Skip to content

Commit

Permalink
fix #44544 Connect VMs created by different Cloud Providers
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony Poddubny authored and Anthony Poddubny committed Apr 27, 2021
1 parent e6c80f8 commit 50c1d36
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 24 deletions.
58 changes: 35 additions & 23 deletions cloudshell/cp/vcenter/network/dvswitch/creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from pyVmomi import vim

from cloudshell.cp.vcenter.exceptions.task_waiter import TaskFaultException


class DvPortGroupCreator(object):
CREATE_PORT_GROUP_TIMEOUT = 60 * 5
Expand Down Expand Up @@ -52,6 +54,7 @@ def get_or_create_network(
network = None
error = None
self._lock.acquire()

try:
# check if the network is attached to the vm and gets it, the function doesn't goes to the vcenter
network = self.pyvmomi_service.get_network_by_name_from_vm(vm, dv_port_name)
Expand Down Expand Up @@ -92,28 +95,35 @@ def get_or_create_network(
logger.info(
f"Creating DvSwitch '{dv_switch_name}' Port Group {dv_port_name} ...'"
)
self._create_dv_port_group(
dv_port_name,
dv_switch_name,
dv_switch_path,
si,
vlan_spec,
vlan_id,
logger,
promiscuous_mode,
)
try:
self._create_dv_port_group(
dv_port_name,
dv_switch_name,
dv_switch_path,
si,
vlan_spec,
vlan_id,
logger,
promiscuous_mode,
)
except TaskFaultException as e:
if "already exists" not in str(e):
raise
else:
logger.info(
f"Creating vSwitch '{dv_switch_name}' Port Group {dv_port_name} ...'"
)
self._create_port_group(
dv_port_name,
dv_switch_name,
vlan_id,
logger,
promiscuous_mode,
vm.runtime.host,
)
try:
self._create_port_group(
dv_port_name,
dv_switch_name,
vlan_id,
logger,
promiscuous_mode,
vm.runtime.host,
)
except vim.fault.AlreadyExists:
pass

network = self._wait_for_network(
si=si,
Expand All @@ -122,18 +132,20 @@ def get_or_create_network(
logger=logger,
)
logger.info(f"Found Port Group Network '{network}' ...'")

if not network:
raise ValueError(
"Could not get or create vlan named: {0}".format(dv_port_name)
)
except ValueError as e:
logger.debug("Failed to find network", exc_info=True)
error = e
finally:
self._lock.release()

if error:
raise error

if not network:
raise ValueError(
"Could not get or create vlan named: {0}".format(dv_port_name)
)

return network

def _wait_for_network(
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.0
3.0.1

0 comments on commit 50c1d36

Please sign in to comment.