Skip to content

Commit

Permalink
correcting the doc strings to the standard
Browse files Browse the repository at this point in the history
  • Loading branch information
razaba committed Mar 31, 2016
1 parent 08d6477 commit 7b613f9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
32 changes: 26 additions & 6 deletions package/cloudshell/cp/vcenter/commands/connect_orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def __init__(self, connector, disconnector, resource_model_parser):
self.dv_switch_name = ''
self.port_group_path = ''
self.default_network = ''
self.logger = None

def connect_bulk(self, si, logger, vcenter_data_model, request):
"""
Expand All @@ -44,6 +45,11 @@ def connect_bulk(self, si, logger, vcenter_data_model, request):
:param request:
:return:
"""
self.logger = logger

self.logger.info('Apply connectivity changes has started')
self.logger.debug('Apply connectivity changes has started with the requet: {0}'.format(request))

self.vcenter_data_model = vcenter_data_model
if vcenter_data_model.reserved_networks:
self.reserved_networks = [name.strip() for name in vcenter_data_model.reserved_networks.split(',')]
Expand All @@ -58,20 +64,20 @@ def connect_bulk(self, si, logger, vcenter_data_model, request):
holder = DeployDataHolder(jsonpickle.decode(request))

mappings = self._map_requsets(holder.driverRequest.actions)
self.logger.debug('Connectivity actions mappings: {0}'.format(jsonpickle.encode(mappings, unpicklable=False)))

pool = ThreadPool()
async_results = self._run_async_connection_actions(si, mappings, pool, logger)

results = self._get_async_results(async_results, pool)

self.logger.info('Apply connectivity changes done')
self.logger.debug('Apply connectivity has finished with the results: {0}'.format(jsonpickle.encode(results,
unpicklable=False)))
return results

def _map_requsets(self, actions):
vm_mapping = dict()

grouped_by_vm_by_requset_by_mode = self._group_action(actions)
self._create_mapping_from_groupings(grouped_by_vm_by_requset_by_mode, vm_mapping)

vm_mapping = self._create_mapping_from_groupings(grouped_by_vm_by_requset_by_mode)
return vm_mapping

def _group_action(self, actions):
Expand Down Expand Up @@ -107,7 +113,8 @@ def _group_action_by_vm(self, actions):
self._add_safely_to_dict(dictionary=grouped_by_vm, key=vm_uuid, value=action)
return grouped_by_vm

def _create_mapping_from_groupings(self, grouped_by_vm_by_requset_by_mode, vm_mapping):
def _create_mapping_from_groupings(self, grouped_by_vm_by_requset_by_mode):
vm_mapping = dict()
for vm, req_to_modes in grouped_by_vm_by_requset_by_mode.items():
actions_mapping = self.ActionsMapping()

Expand All @@ -120,6 +127,8 @@ def _create_mapping_from_groupings(self, grouped_by_vm_by_requset_by_mode, vm_ma
actions_mapping.action_tree = req_to_modes
vm_mapping[vm] = actions_mapping

return vm_mapping

def _get_remove_mappings(self, req_to_modes, vm):
remove_mappings = []
if ACTION_TYPE_REMOVE_VLAN in req_to_modes:
Expand Down Expand Up @@ -180,6 +189,10 @@ def _set_vlan(self, action_mappings, si, vm_uuid, logger):
results = []
set_vlan_actions = action_mappings.action_tree[ACTION_TYPE_SET_VLAN]
try:
self.logger.info('connecting vm({0})'.format(vm_uuid))
self.logger.debug('connecting vm({0}) with the mappings'.format(vm_uuid,
jsonpickle.encode(action_mappings,
unpicklable=False)))
connection_results = self.connector.connect_to_networks(si,
logger,
vm_uuid,
Expand All @@ -193,6 +206,7 @@ def _set_vlan(self, action_mappings, si, vm_uuid, logger):
results += self._get_set_vlan_result_suc(act_by_mode_by_vlan_by_nic, connection_res_map)

except Exception as e:
self.logger.error('Exception raised while connecting vm({0}) with exception: {1}'.format(vm_uuid, e))
for mode, actions in set_vlan_actions.items():
for action in actions:
error_result = self._create_error_action_res(action, e)
Expand Down Expand Up @@ -259,9 +273,14 @@ def _group_action_by_vlan_id(self, set_vlan_actions):
return set_actions_grouped_by_vlan_id

def _remove_vlan(self, action_mappings, si, vm_uuid, logger):

results = []
mode_to_actions = action_mappings.action_tree[ACTION_TYPE_REMOVE_VLAN]
try:
self.logger.info('disconnecting vm({0})'.format(vm_uuid))
self.logger.debug('disconnecting vm({0}) with the mappings'.format(vm_uuid,
jsonpickle.encode(action_mappings,
unpicklable=False)))
connection_results = self.disconnector.disconnect_from_networks(si,
logger,
self.vcenter_data_model,
Expand All @@ -285,6 +304,7 @@ def _remove_vlan(self, action_mappings, si, vm_uuid, logger):
action_result.updatedInterface = res.vnic_mac
results.append(action_result)
except Exception as e:
self.logger.error('Exception raised while disconnecting vm({0}) with exception: {1}'.format(vm_uuid, e))
for mode, actions in mode_to_actions.items():
for action in actions:
error_result = self._create_error_action_res(action, e)
Expand Down
9 changes: 3 additions & 6 deletions package/cloudshell/cp/vcenter/vm/portgroup_configurer.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ def erase_network_by_mapping(self, networks, reserved_networks, logger):
for net in networks:
try:
nets[net.name] = net
except vim.fault.ManagedObjectNotFound as e:
continue

try:
for network in nets.values():
if self.network_name_gen.is_generated_name(network.name) \
and (not reserved_networks or network.name not in reserved_networks) \
Expand All @@ -75,8 +71,9 @@ def erase_network_by_mapping(self, networks, reserved_networks, logger):
self.synchronous_task_waiter.wait_for_task(task=task,
logger=logger,
action_name='Erase dv Port Group')
except vim.fault.ManagedObjectNotFound as e:
continue
except Exception as e:
a = e.msg
continue
finally:
self._lock.release()

Expand Down
4 changes: 2 additions & 2 deletions vCenterShellPackage/DataModel/datamodel.xml
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@
<ns0:Categories>
</ns0:Categories>
</ns0:ResourceFamily>
<ns0:ResourceFamily Description="" IsService="true" Name="Virtual Network" ImagePath="service_vnetwork.png" ServiceType="Regular">
<ns0:ResourceFamily Description="" ImagePath="service_vnetwork.png" IsService="true" Name="Virtual Network" ServiceType="Regular">
<ns0:AttachedAttributes>
<ns0:AttachedAttribute IsLocal="true" IsOverridable="true" Name="QnQ" UserInput="false">
<ns0:AllowedValues />
Expand Down Expand Up @@ -667,4 +667,4 @@
<ns0:ScriptInputs />
</ns0:ScriptDescriptor>
</ns0:ScriptDescriptors>
</ns0:DataModelInfo>
</ns0:DataModelInfo>

0 comments on commit 7b613f9

Please sign in to comment.