|
9 | 9 | from .api import InstanceV1API
|
10 | 10 | from .custom_marshalling import marshal_GetServerUserDataRequest
|
11 | 11 | from .custom_types import GetServerUserDataRequest, GetAllServerUserDataResponse
|
| 12 | +from .types import ( |
| 13 | + VolumeServerTemplate, |
| 14 | + BootType, |
| 15 | + CreateServerResponse, |
| 16 | +) |
12 | 17 |
|
13 | 18 | max_retry = 10
|
14 | 19 | interval = 0.01
|
@@ -148,85 +153,81 @@ def wait_instance_server(self, server_id: str, zone: ScwZone) -> GetServerRespon
|
148 | 153 | )
|
149 | 154 |
|
150 | 155 | def create_instance_server(
|
151 |
| - self, |
152 |
| - *, |
153 |
| - zone: Optional[ScwZone] = None, |
154 |
| - commercial_type: str, |
155 |
| - name: Optional[str] = None, |
156 |
| - dynamic_ip_required: Optional[bool] = None, |
157 |
| - routed_ip_enabled: Optional[bool] = None, |
158 |
| - image: Optional[str] = None, |
159 |
| - volumes: Optional[dict[str, VolumeServerTemplate]] = None, |
160 |
| - enable_ipv6: Optional[bool] = None, |
161 |
| - protected: bool = False, |
162 |
| - public_ip: Optional[str] = None, |
163 |
| - public_ips: Optional[list[str]] = None, |
164 |
| - boot_type: Optional[BootType] = None, |
165 |
| - organization: Optional[str] = None, |
166 |
| - project: Optional[str] = None, |
167 |
| - tags: Optional[list[str]] = None, |
168 |
| - security_group: Optional[str] = None, |
169 |
| - placement_group: Optional[str] = None, |
170 |
| - admin_password_encryption_ssh_key_id: Optional[str] = None, |
| 156 | + self, |
| 157 | + *, |
| 158 | + zone: Optional[ScwZone] = None, |
| 159 | + commercial_type: str, |
| 160 | + name: Optional[str] = None, |
| 161 | + dynamic_ip_required: Optional[bool] = None, |
| 162 | + routed_ip_enabled: Optional[bool] = None, |
| 163 | + image: Optional[str] = None, |
| 164 | + volumes: Optional[dict[str, VolumeServerTemplate]] = None, |
| 165 | + enable_ipv6: Optional[bool] = None, |
| 166 | + protected: bool = False, |
| 167 | + public_ip: Optional[str] = None, |
| 168 | + public_ips: Optional[list[str]] = None, |
| 169 | + boot_type: Optional[BootType] = None, |
| 170 | + organization: Optional[str] = None, |
| 171 | + project: Optional[str] = None, |
| 172 | + tags: Optional[list[str]] = None, |
| 173 | + security_group: Optional[str] = None, |
| 174 | + placement_group: Optional[str] = None, |
| 175 | + admin_password_encryption_ssh_key_id: Optional[str] = None, |
171 | 176 | ) -> CreateServerResponse:
|
172 | 177 | """
|
173 |
| - Create an Instance. |
174 |
| - Create a new Instance of the specified commercial type in the specified zone. Pay attention to the volumes parameter, which takes an object which can be used in different ways to achieve different behaviors. |
175 |
| - Get more information in the [Technical Information](#technical-information) section of the introduction. |
176 |
| - :param zone: Zone to target. If none is passed will use default zone from the config. |
177 |
| - :param commercial_type: Define the Instance commercial type (i.e. GP1-S). |
178 |
| - :param name: Instance name. |
179 |
| - :param dynamic_ip_required: By default, `dynamic_ip_required` is true, a dynamic ip is attached to the instance (if no flexible ip is already attached). |
180 |
| - :param routed_ip_enabled: If true, configure the Instance so it uses the new routed IP mode. |
181 |
| - :param image: Instance image ID or label. |
182 |
| - :param volumes: Volumes attached to the server. |
183 |
| - :param enable_ipv6: True if IPv6 is enabled on the server (deprecated and always `False` when `routed_ip_enabled` is `True`). |
184 |
| - :param protected: True to activate server protection option. |
185 |
| - :param public_ip: ID of the reserved IP to attach to the Instance. |
186 |
| - :param public_ips: A list of reserved IP IDs to attach to the Instance. |
187 |
| - :param boot_type: Boot type to use. |
188 |
| - :param organization: Instance Organization ID. |
189 |
| - One-Of ('project_identifier'): at most one of 'project', 'organization' could be set. |
190 |
| - :param project: Instance Project ID. |
191 |
| - One-Of ('project_identifier'): at most one of 'project', 'organization' could be set. |
192 |
| - :param tags: Instance tags. |
193 |
| - :param security_group: Security group ID. |
194 |
| - :param placement_group: Placement group ID if Instance must be part of a placement group. |
195 |
| - :param admin_password_encryption_ssh_key_id: The public_key value of this key is used to encrypt the admin password. |
196 |
| - :return: :class:`CreateServerResponse <CreateServerResponse>` |
197 |
| -
|
198 |
| - Usage: |
199 |
| - :: |
200 |
| -
|
201 |
| - result = api.create_instance_server( |
202 |
| - commercial_type="example", |
203 |
| - protected=False, |
204 |
| - ) |
205 |
| - """ |
206 |
| - |
207 |
| - payload = { |
208 |
| - "zone": zone, |
209 |
| - "commercial_type": commercial_type, |
210 |
| - "name": name, |
211 |
| - "dynamic_ip_required": dynamic_ip_required, |
212 |
| - "routed_ip_enabled": routed_ip_enabled, |
213 |
| - "image": image, |
214 |
| - "volumes": volumes, |
215 |
| - "enable_ipv6": enable_ipv6, |
216 |
| - "protected": protected, |
217 |
| - "public_ip": public_ip, |
218 |
| - "public_ips": public_ips, |
219 |
| - "boot_type": boot_type, |
220 |
| - "organization": organization, |
221 |
| - "project": project, |
222 |
| - "tags": tags, |
223 |
| - "security_group": security_group, |
224 |
| - "placement_group": placement_group, |
225 |
| - "admin_password_encryption_ssh_key_id": admin_password_encryption_ssh_key_id, |
226 |
| - } |
| 178 | + Create an Instance. |
| 179 | + Create a new Instance of the specified commercial type in the specified zone. Pay attention to the volumes parameter, which takes an object which can be used in different ways to achieve different behaviors. |
| 180 | + Get more information in the [Technical Information](#technical-information) section of the introduction. |
| 181 | + :param zone: Zone to target. If none is passed will use default zone from the config. |
| 182 | + :param commercial_type: Define the Instance commercial type (i.e. GP1-S). |
| 183 | + :param name: Instance name. |
| 184 | + :param dynamic_ip_required: By default, `dynamic_ip_required` is true, a dynamic ip is attached to the instance (if no flexible ip is already attached). |
| 185 | + :param routed_ip_enabled: If true, configure the Instance so it uses the new routed IP mode. |
| 186 | + :param image: Instance image ID or label. |
| 187 | + :param volumes: Volumes attached to the server. |
| 188 | + :param enable_ipv6: True if IPv6 is enabled on the server (deprecated and always `False` when `routed_ip_enabled` is `True`). |
| 189 | + :param protected: True to activate server protection option. |
| 190 | + :param public_ip: ID of the reserved IP to attach to the Instance. |
| 191 | + :param public_ips: A list of reserved IP IDs to attach to the Instance. |
| 192 | + :param boot_type: Boot type to use. |
| 193 | + :param organization: Instance Organization ID. |
| 194 | + One-Of ('project_identifier'): at most one of 'project', 'organization' could be set. |
| 195 | + :param project: Instance Project ID. |
| 196 | + One-Of ('project_identifier'): at most one of 'project', 'organization' could be set. |
| 197 | + :param tags: Instance tags. |
| 198 | + :param security_group: Security group ID. |
| 199 | + :param placement_group: Placement group ID if Instance must be part of a placement group. |
| 200 | + :param admin_password_encryption_ssh_key_id: The public_key value of this key is used to encrypt the admin password. |
| 201 | + :return: :class:`CreateServerResponse <CreateServerResponse>` |
| 202 | +
|
| 203 | + Usage: |
| 204 | + :: |
227 | 205 |
|
228 |
| - clean_payload = {k: v for k, v in payload.items() if v is not None} |
| 206 | + result = api.create_instance_server( |
| 207 | + commercial_type="example", |
| 208 | + protected=False, |
| 209 | + ) |
| 210 | + """ |
229 | 211 |
|
230 |
| - response = self._create_server(**clean_payload) |
| 212 | + request = CreateServerRequest( |
| 213 | + zone=zone, |
| 214 | + commercial_type=commercial_type, |
| 215 | + name=name, |
| 216 | + dynamic_ip_required=dynamic_ip_required, |
| 217 | + routed_ip_enabled=routed_ip_enabled, |
| 218 | + image=image, |
| 219 | + volumes=volumes, |
| 220 | + enable_ipv6=enable_ipv6, |
| 221 | + protected=protected, |
| 222 | + public_ip=public_ip, |
| 223 | + public_ips=public_ips, |
| 224 | + boot_type=boot_type, |
| 225 | + organization=organization, |
| 226 | + project=project, |
| 227 | + tags=tags, |
| 228 | + security_group=security_group, |
| 229 | + placement_group=placement_group, |
| 230 | + admin_password_encryption_ssh_key_id=admin_password_encryption_ssh_key_id, |
| 231 | + ) |
231 | 232 |
|
232 |
| - return response |
| 233 | + return self._create_server(request) |
0 commit comments