55from common .utilites .command_result import get_result_from_command_output
66
77from common .logger .service import getLogger
8- _logger = getLogger ('EnvironmentConnector' )
8+ _logger = getLogger ('EnvironmentConnector' )
9+
10+ VIRTUAL_NETWORK_ATTRIBUTE = 'Virtual Network'
11+ ACCESS_MODE_ATTRIBUTE = 'Access Mode'
12+
913
1014class EnvironmentConnector (object ):
1115 def connect_all (self ):
@@ -27,19 +31,30 @@ def connect_all(self):
2731
2832 for vlan_service in vlan_services :
2933
30- if not len (vlan_service .Attributes ):
31- raise ValueError ('No attributes on service {0}' .format (vlan_service .ServiceName ))
34+ _logger .debug ('Connecting \' {0}\' ' .format (vlan_service .ServiceName ))
3235
33- access_mode = self ._get_attribute (vlan_service .Attributes , 'Access Mode' )
34- virtual_network = self ._get_attribute (vlan_service .Attributes , 'Virtual Network' )
36+ access_mode = self ._get_attribute (vlan_service .Attributes , ACCESS_MODE_ATTRIBUTE )
37+ virtual_network = self ._get_attribute (vlan_service .Attributes , VIRTUAL_NETWORK_ATTRIBUTE )
3538
3639 # Get Deployed App connected to VLAN Auto service
3740 connected_resources = self ._get_connected_resources (connectors , vlan_service )
3841
3942 if not connected_resources :
4043 continue
4144
42- session .ExecuteCommand (reservation_id , vlan_service .ServiceName , 'Service' , 'Auto Resolve Vlan' , [], True )
45+ if not virtual_network or virtual_network == '' :
46+
47+ _logger .debug ('Executing Auto Resolve Vlan on \' {0}\' ' .format (vlan_service .ServiceName ))
48+
49+ command_result = session .ExecuteCommand (reservation_id , vlan_service .ServiceName , 'Service' ,
50+ 'Auto Resolve Vlan' , [], True )
51+
52+ virtual_network = get_result_from_command_output (command_result .Output )
53+
54+ _logger .debug ('Auto Resolve Vlan returned Virtual Network \' {0}\' ' .format (virtual_network ))
55+
56+ if not virtual_network or virtual_network == '' :
57+ raise ValueError ('Auto Resolve Vlan command did not return Virtual Network' )
4358
4459 for connected_resource in connected_resources :
4560 self ._execute_connect_command_on_connected_resource (access_mode , connected_resource , reservation_id ,
@@ -48,7 +63,7 @@ def connect_all(self):
4863 @staticmethod
4964 def _get_attribute (attributes , attribute_name ):
5065 attribute = next (item for item in attributes if item .Name == attribute_name )
51- if not attribute or not attribute . Value :
66+ if not attribute :
5267 raise ValueError ('Attribute {0} is missing' .format (attribute_name ))
5368 return attribute .Value
5469
@@ -60,7 +75,7 @@ def _get_connectors(reservation_details):
6075 @staticmethod
6176 def _get_vlan_auto_services (reservation_details ):
6277 vlan_services = [service for service in reservation_details .ReservationDescription .Services
63- if service . ServiceName == 'VLAN Auto' ]
78+ if VIRTUAL_NETWORK_ATTRIBUTE in [ attr . Name for attr in service . Attributes ] ]
6479 return vlan_services
6580
6681 @staticmethod
0 commit comments