Skip to content

Commit 3dbc2b2

Browse files
committed
If 'Virtual Network' already has value than no need to resolve it.
vlan auto service returns the VLAN ID get_vlan_services was changed to check by existence of Virtual Network attribute
1 parent d5539a3 commit 3dbc2b2

5 files changed

Lines changed: 29 additions & 18 deletions

File tree

deployed_app_service/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def main():
1515

1616
vlan_id = helpers.get_user_param('VLAN_ID')
1717
if not vlan_id:
18-
raise ValueError('VLAN_ID is missoing')
18+
raise ValueError('VLAN_ID is missing')
1919

2020
deployed_app_service.connect(vlan_spec_type, vlan_id)
2121

environment_scripts/connect_all.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
from common.utilites.command_result import get_result_from_command_output
66

77
from 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

1014
class 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

vCenterShell/commands/connect_dvswitch.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,5 @@ def _prepare_mappings(self, vm_network_mappings):
6262
vm_network_mapping.vlan_spec = \
6363
self.vlan_spec_factory.get_vlan_spec(vm_network_mapping.vlan_spec)
6464

65-
self.logger.debug('Vlan Id: {0}, VLAN Spec: {1}, Port Name {2}',
66-
vm_network_mapping.vlan_id,
67-
vm_network_mapping.vlan_spec,
68-
vm_network_mapping.dv_port_name)
69-
7065
mappings.append(vm_network_mapping)
7166
return mappings

vCenterShellPackage/App Templates/VM Deployment.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<Attribute Name="VM Cluster" Value="QualiSB Cluster/LiverPool" />
1717
<Attribute Name="VM Power State" Value="False" />
1818
<Attribute Name="VM Storage" Value="eric ds cluster" />
19-
<Attribute Name="vCenter Template" Value="vCenter/QualiSB/Alex/test" />
19+
<Attribute Name="vCenter Template" Value="vCenter/QualiSB/YOUR_FOLDER/YOUR_TEMPLATE" />
2020
</Attributes>
2121
</DeploymentService>
2222
</DeploymentPath>

vlan_service/auto/__main__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import os
22
import models
33
from time import sleep
4-
54
import qualipy.scripts.cloudshell_scripts_helpers as helpers
65
from qualipy.api.cloudshell_api import AttributeNameValue
7-
86
from common.model_factory import ResourceModelParser
97
from vlan_service.resolver.provider import VlanResolverProvider
8+
from common.utilites.command_result import set_command_result
109

1110

1211
def main():
@@ -40,10 +39,12 @@ def main():
4039
str(vlan_id)))
4140
else:
4241
# write already resolved message to reservation output
42+
vlan_id = str(vlan_auto_resource_model.virtual_network)
4343
api.WriteMessageToReservationOutput(reservation_context.id,
4444
"{0} already has a resolved vlan id: {1}"
4545
.format(resource_context.name,
46-
str(vlan_auto_resource_model.virtual_network)))
46+
vlan_id))
47+
set_command_result(vlan_id)
4748

4849

4950
if __name__ == "__main__":

0 commit comments

Comments
 (0)