|
16 | 16 | from SoftLayer.managers import ordering |
17 | 17 | from SoftLayer import utils |
18 | 18 |
|
19 | | - |
20 | 19 | LOGGER = logging.getLogger(__name__) |
| 20 | + |
| 21 | + |
21 | 22 | # pylint: disable=no-self-use |
22 | 23 |
|
23 | 24 |
|
@@ -366,27 +367,10 @@ def _generate_create_dict( |
366 | 367 | if datacenter: |
367 | 368 | data["datacenter"] = {"name": datacenter} |
368 | 369 |
|
369 | | - if public_vlan: |
370 | | - if public_subnet: |
371 | | - data.update({ |
372 | | - 'primaryNetworkComponent': { |
373 | | - "networkVlan": {"id": int(public_vlan), |
374 | | - "primarySubnet": {"id": int(public_subnet)}}}}) |
375 | | - else: |
376 | | - data.update({ |
377 | | - 'primaryNetworkComponent': { |
378 | | - "networkVlan": {"id": int(public_vlan)}}}) |
379 | | - |
380 | | - if private_vlan: |
381 | | - if private_subnet: |
382 | | - data.update({ |
383 | | - 'primaryBackendNetworkComponent': { |
384 | | - "networkVlan": {"id": int(private_vlan), |
385 | | - "primarySubnet": {"id": int(private_subnet)}}}}) |
386 | | - else: |
387 | | - data.update({ |
388 | | - "primaryBackendNetworkComponent": { |
389 | | - "networkVlan": {"id": int(private_vlan)}}}) |
| 370 | + if private_vlan and public_vlan: |
| 371 | + network_components = self._create_network_components(public_vlan, private_vlan, |
| 372 | + private_subnet, public_subnet) |
| 373 | + data.update(network_components) |
390 | 374 |
|
391 | 375 | if public_security_groups: |
392 | 376 | secgroups = [{'securityGroup': {'id': int(sg)}} |
@@ -429,6 +413,46 @@ def _generate_create_dict( |
429 | 413 |
|
430 | 414 | return data |
431 | 415 |
|
| 416 | + def _create_network_components( |
| 417 | + self, public_vlan=None, private_vlan=None, |
| 418 | + private_subnet=None, public_subnet=None, **kwargs): |
| 419 | + |
| 420 | + if private_vlan and public_vlan: |
| 421 | + if private_subnet and public_subnet: |
| 422 | + parameters = { |
| 423 | + 'primaryNetworkComponent': { |
| 424 | + "networkVlan": {"primarySubnet": {"id": int(public_subnet)}}}, |
| 425 | + 'primaryBackendNetworkComponent': { |
| 426 | + "networkVlan": {"primarySubnet": {"id": int(private_subnet)}}}} |
| 427 | + else: |
| 428 | + if private_subnet: |
| 429 | + parameters = { |
| 430 | + 'primaryNetworkComponent': { |
| 431 | + "networkVlan": {"id": int(public_vlan)}}, |
| 432 | + 'primaryBackendNetworkComponent': { |
| 433 | + "networkVlan": {"primarySubnet": {"id": int(private_subnet)}}} |
| 434 | + } |
| 435 | + else: |
| 436 | + parameters = { |
| 437 | + 'primaryNetworkComponent': { |
| 438 | + "networkVlan": {"primarySubnet": {"id": int(public_subnet)}}}, |
| 439 | + 'primaryBackendNetworkComponent': { |
| 440 | + "networkVlan": {"id": int(private_vlan)}} |
| 441 | + } |
| 442 | + else: |
| 443 | + if private_vlan: |
| 444 | + parameters = { |
| 445 | + 'primaryBackendNetworkComponent': { |
| 446 | + "networkVlan": {"id": int(private_vlan)}} |
| 447 | + } |
| 448 | + else: |
| 449 | + parameters = { |
| 450 | + 'primaryNetworkComponent': { |
| 451 | + "networkVlan": {"id": int(public_vlan)}} |
| 452 | + } |
| 453 | + |
| 454 | + return parameters |
| 455 | + |
432 | 456 | @retry(logger=LOGGER) |
433 | 457 | def wait_for_transaction(self, instance_id, limit, delay=10): |
434 | 458 | """Waits on a VS transaction for the specified amount of time. |
|
0 commit comments