Skip to content

Commit c6e7723

Browse files
authored
Merge pull request #894 from QualiSystems/develop
Merging dev to master for 1.10.0 release
2 parents ec00c39 + 6c3fd9a commit c6e7723

File tree

27 files changed

+212
-303
lines changed

27 files changed

+212
-303
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,4 @@ develop.cmd
8181
*.zip
8282
debug.xml
8383
debug_info.txt
84+

cloudshell_shell_core_install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
if [ "${CLOUD_SHELL_SHELL_CORE}" -eq 1 ]
33
then
4-
pip install "cloudshell-shell-core>=3.0.0,<3.1.0" --extra-index-url https://testpypi.python.org/simple
4+
pip install "cloudshell-shell-core>=3.1.0,<3.2.0" --extra-index-url https://testpypi.python.org/simple
55
else
66
pip install "cloudshell-shell-core>=2.3.0,<2.4.0" --extra-index-url https://testpypi.python.org/simple
77
fi

kill_python.bat

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@echo off
2+
::taskkill /im python.exe /f
3+
wmic Path win32_process Where "CommandLine Like '%%\\ExecutionServer\\%%python.exe%%'" Call Terminate
4+
wmic Path win32_process Where "CommandLine Like '%%\\ProgramData\\QualiSystems\\%%python.exe%%'" Call Terminate

package/cloudshell/cp/vcenter/commands/command_orchestrator.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import jsonpickle
44

55
from cloudshell.cp.vcenter.models.DeployFromImageDetails import DeployFromImageDetails
6+
from cloudshell.shell.core.context import ResourceRemoteCommandContext
67
from cloudshell.cp.vcenter.models.OrchestrationSaveResult import OrchestrationSaveResult
78
from cloudshell.cp.vcenter.models.OrchestrationSavedArtifactsInfo import OrchestrationSavedArtifactsInfo
89
from cloudshell.cp.vcenter.models.OrchestrationSavedArtifact import OrchestrationSavedArtifact
@@ -19,12 +20,10 @@
1920
from cloudshell.cp.vcenter.commands.restore_snapshot import SnapshotRestoreCommand
2021
from cloudshell.cp.vcenter.commands.save_snapshot import SaveSnapshotCommand
2122
from cloudshell.cp.vcenter.commands.retrieve_snapshots import RetrieveSnapshotsCommand
22-
from cloudshell.cp.vcenter.common.cloud_shell.driver_helper import CloudshellDriverHelper
2323
from cloudshell.cp.vcenter.common.cloud_shell.resource_remover import CloudshellResourceRemover
2424
from cloudshell.cp.vcenter.common.model_factory import ResourceModelParser
2525
from cloudshell.cp.vcenter.common.utilites.command_result import set_command_result, get_result_from_command_output
2626
from cloudshell.cp.vcenter.common.utilites.common_name import generate_unique_name
27-
from cloudshell.cp.vcenter.common.utilites.common_utils import back_slash_to_front_converter
2827
from cloudshell.cp.vcenter.common.utilites.context_based_logger_factory import ContextBasedLoggerFactory
2928
from cloudshell.cp.vcenter.common.vcenter.ovf_service import OvfImageDeployerService
3029
from cloudshell.cp.vcenter.common.vcenter.task_waiter import SynchronousTaskWaiter
@@ -50,16 +49,13 @@
5049
from cloudshell.cp.vcenter.vm.vnic_to_network_mapper import VnicToNetworkMapper
5150
from cloudshell.cp.vcenter.models.DeployFromTemplateDetails import DeployFromTemplateDetails
5251

53-
5452
class CommandOrchestrator(object):
5553
def __init__(self):
5654
"""
5755
Initialize the driver session, this function is called everytime a new instance of the driver is created
5856
in here the driver is going to be bootstrapped
5957
60-
:param context: models.QualiDriverModels.InitCommandContext
6158
"""
62-
self.cs_helper = CloudshellDriverHelper()
6359
synchronous_task_waiter = SynchronousTaskWaiter()
6460
pv_service = pyVmomiService(connect=SmartConnect, disconnect=Disconnect, task_waiter=synchronous_task_waiter)
6561
self.resource_model_parser = ResourceModelParser()
@@ -74,7 +70,6 @@ def __init__(self):
7470
vm_deployer = VirtualMachineDeployer(pv_service=pv_service,
7571
name_generator=generate_unique_name,
7672
ovf_service=ovf_service,
77-
cs_helper=self.cs_helper,
7873
resource_model_parser=ResourceModelParser())
7974

8075
dv_port_group_creator = DvPortGroupCreator(pyvmomi_service=pv_service,
@@ -89,7 +84,6 @@ def __init__(self):
8984
virtual_machine_port_group_configurer)
9085
# Command Wrapper
9186
self.command_wrapper = CommandWrapper(pv_service=pv_service,
92-
cloud_shell_helper=self.cs_helper,
9387
resource_model_parser=self.resource_model_parser,
9488
context_based_logger_factory=ContextBasedLoggerFactory())
9589
# Deploy Command
@@ -261,6 +255,7 @@ def disconnect_all(self, context, ports):
261255
:param models.QualiDriverModels.ResourceRemoteCommandContext context: the context the command runs on
262256
:param list[string] ports: the ports of the connection between the remote resource and the local resource, NOT IN USE!!!
263257
"""
258+
264259
resource_details = self._parse_remote_model(context)
265260
# execute command
266261
res = self.command_wrapper.execute_command_with_connection(
@@ -309,16 +304,15 @@ def destroy_vm_only(self, context, ports):
309304
def refresh_ip(self, context, cancellation_context, ports):
310305
"""
311306
Refresh IP Command, will refresh the ip of the vm and will update it on the resource
312-
:param models.QualiDriverModels.ResourceRemoteCommandContext context: the context the command runs on
307+
:param ResourceRemoteCommandContext context: the context the command runs on
313308
:param cancellation_context:
314309
:param list[string] ports: the ports of the connection between the remote resource and the local resource, NOT IN USE!!!
315310
"""
316311
resource_details = self._parse_remote_model(context)
317312
# execute command
318313
res = self.command_wrapper.execute_command_with_connection(context,
319314
self.refresh_ip_command.refresh_ip,
320-
resource_details.vm_uuid,
321-
resource_details.fullname,
315+
resource_details,
322316
cancellation_context,
323317
context.remote_endpoints[0].app_context.app_request_json)
324318
return set_command_result(result=res, unpicklable=False)
@@ -379,6 +373,8 @@ def _parse_remote_model(self, context):
379373
app_resource_detail.vm_uuid = holder.vmdetails.uid
380374
app_resource_detail.cloud_provider = context.resource.fullname
381375
app_resource_detail.fullname = resource.fullname
376+
if hasattr(holder.vmdetails, 'vmCustomParams'):
377+
app_resource_detail.vm_custom_params = holder.vmdetails.vmCustomParams
382378
return app_resource_detail
383379

384380
def power_on_not_roemote(self, context, vm_uuid, resource_fullname):

package/cloudshell/cp/vcenter/commands/refresh_ip.py

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import re
22
import time
33

4+
from retrying import retry
5+
46
from cloudshell.cp.vcenter.commands.ip_result import IpResult, IpReason
57

68
from cloudshell.cp.vcenter.common.vcenter.vm_location import VMLocation
9+
from cloudshell.cp.vcenter.models.GenericDeployedAppResourceModel import GenericDeployedAppResourceModel
710

811

912
class RefreshIpCommand(object):
@@ -19,15 +22,15 @@ def _do_not_run_on_static_vm(self, app_request_json):
1922
if app_request_json == '' or app_request_json is None:
2023
raise ValueError('This command cannot be executed on a Static VM.')
2124

22-
def refresh_ip(self, si, logger, session, vcenter_data_model, vm_uuid, resource_name, cancellation_context,app_request_json):
25+
def refresh_ip(self, si, logger, session, vcenter_data_model, resource_model, cancellation_context,
26+
app_request_json):
2327
"""
2428
Refreshes IP address of virtual machine and updates Address property on the resource
2529
2630
:param vim.ServiceInstance si: py_vmomi service instance
2731
:param logger:
2832
:param vCenterShell.driver.SecureCloudShellApiSession session: cloudshell session
29-
:param str vm_uuid: UUID of Virtual Machine
30-
:param str resource_name: Logical resource name to update address property on
33+
:param GenericDeployedAppResourceModel resource_model: UUID of Virtual Machine
3134
:param VMwarevCenterResourceModel vcenter_data_model: the vcenter data model attributes
3235
:param cancellation_context:
3336
"""
@@ -36,29 +39,34 @@ def refresh_ip(self, si, logger, session, vcenter_data_model, vm_uuid, resource_
3639
default_network = VMLocation.combine(
3740
[vcenter_data_model.default_datacenter, vcenter_data_model.holding_network])
3841

39-
resource = session.GetResourceDetails(resource_name)
40-
41-
match_function = self.ip_manager.get_ip_match_function(self._get_ip_refresh_ip_regex(resource))
42+
match_function = self.ip_manager.get_ip_match_function(
43+
self._get_ip_refresh_ip_regex(resource_model.vm_custom_params))
4244

43-
timeout = self._get_ip_refresh_timeout(resource)
45+
timeout = self._get_ip_refresh_timeout(resource_model.vm_custom_params)
4446

45-
vm = self.pyvmomi_service.find_by_uuid(si, vm_uuid)
47+
vm = self.pyvmomi_service.find_by_uuid(si, resource_model.vm_uuid)
4648

4749
ip_res = self.ip_manager.get_ip(vm, default_network, match_function, cancellation_context, timeout, logger)
4850

4951
if ip_res.reason == IpReason.Timeout:
5052
raise ValueError('IP address of VM \'{0}\' could not be obtained during {1} seconds'
51-
.format(resource_name, timeout))
53+
.format(resource_model.fullname, timeout))
5254

5355
if ip_res.reason == IpReason.Success:
54-
session.UpdateResourceAddress(resource_name, ip_res.ip_address)
56+
self._update_resource_address_with_retry(session=session,
57+
resource_name=resource_model.fullname,
58+
ip_address=ip_res.ip_address)
5559

5660
return ip_res.ip_address
5761

62+
@retry(stop_max_attempt_number=5, wait_fixed=1000)
63+
def _update_resource_address_with_retry(self, session, resource_name, ip_address):
64+
session.UpdateResourceAddress(resource_name, ip_address)
65+
5866
@staticmethod
59-
def _get_ip_refresh_timeout(resource):
67+
def _get_ip_refresh_timeout(custom_params):
6068
timeout = RefreshIpCommand._get_custom_param(
61-
resource=resource,
69+
custom_params=custom_params,
6270
custom_param_name='refresh_ip_timeout')
6371

6472
if not timeout:
@@ -67,21 +75,18 @@ def _get_ip_refresh_timeout(resource):
6775
return float(timeout)
6876

6977
@staticmethod
70-
def _get_ip_refresh_ip_regex(resource):
78+
def _get_ip_refresh_ip_regex(custom_params):
7179
return RefreshIpCommand._get_custom_param(
72-
resource=resource,
80+
custom_params=custom_params,
7381
custom_param_name='ip_regex')
7482

7583
@staticmethod
76-
def _get_custom_param(resource, custom_param_name):
77-
custom_param_values = []
78-
vm_details = resource.VmDetails
79-
if vm_details and hasattr(vm_details, 'VmCustomParams') and vm_details.VmCustomParams:
80-
custom_params = vm_details.VmCustomParams
81-
params = custom_params if isinstance(custom_params, list) else [custom_params]
82-
custom_param_values = [custom_param.Value for custom_param
83-
in params
84-
if custom_param.Name == custom_param_name]
84+
def _get_custom_param(custom_params, custom_param_name):
85+
if not custom_params:
86+
return None
87+
88+
custom_param_values = [custom_param.value for custom_param in custom_params
89+
if custom_param.name == custom_param_name]
8590

8691
if custom_param_values:
8792
return custom_param_values[0]

package/cloudshell/cp/vcenter/common/cloud_shell/conn_details_retriever.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,24 @@
22

33

44
class ResourceConnectionDetailsRetriever:
5-
def __init__(self, qualipy_helpers):
6-
"""
7-
:param qualipy.scripts.cloudshell_scripts_helpers qualipy_helpers:
8-
:param cs_retriever_service:
9-
:return:
10-
"""
11-
self.qualipy_helpers = qualipy_helpers
125

13-
def connection_details(self):
14-
""" Retrieves connection details to vCenter from specified resource
6+
@staticmethod
7+
def get_connection_details(session, vcenter_resource_model, resource_context):
8+
"""
9+
Methods retrieves the connection details from the vcenter resource model attributes.
1510
16-
:param resource_name: Resource name to get connection details from
17-
:rtype VCenterConnectionDetails:
11+
:param CloudShellAPISession session:
12+
:param VMwarevCenterResourceModel vcenter_resource_model: Instance of VMwarevCenterResourceModel
13+
:param ResourceContextDetails resource_context: the context of the command
1814
"""
19-
# gets the vcenter resource context to connect. We assume this will only run on a cloud prodvider resource
20-
session = self.qualipy_helpers.get_api_session()
21-
resource_context = self.qualipy_helpers.get_resource_context_details()
15+
16+
session = session
17+
resource_context = resource_context
2218

2319
# get vCenter connection details from vCenter resource
24-
user = resource_context.attributes["User"]
25-
encrypted_pass = resource_context.attributes["Password"]
20+
user = vcenter_resource_model.user
2621
vcenter_url = resource_context.address
27-
password = session.DecryptPassword(encrypted_pass).Value
22+
password = session.DecryptPassword(vcenter_resource_model.password).Value
2823

2924
return VCenterConnectionDetails(vcenter_url, user, password)
25+

package/cloudshell/cp/vcenter/common/cloud_shell/driver_helper.py

Lines changed: 0 additions & 52 deletions
This file was deleted.

package/cloudshell/cp/vcenter/common/vcenter/model_auto_discovery.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
from cloudshell.cp.vcenter.models.QualiDriverModels import AutoLoadDetails, AutoLoadAttribute
88
from cloudshell.cp.vcenter.models.VCenterConnectionDetails import VCenterConnectionDetails
99

10-
from cloudshell.cp.vcenter.common.cloud_shell.driver_helper import CloudshellDriverHelper
10+
1111
from cloudshell.cp.vcenter.common.model_factory import ResourceModelParser
1212
from cloudshell.cp.vcenter.common.vcenter.vmomi_service import pyVmomiService
1313

1414
from cloudshell.cp.vcenter.common.vcenter.task_waiter import SynchronousTaskWaiter
15+
from cloudshell.shell.core.session.cloudshell_session import CloudShellSessionContext
1516

1617
DOMAIN = 'Global'
1718
ADDRESS = 'address'
@@ -34,7 +35,6 @@ class VCenterAutoModelDiscovery(object):
3435
def __init__(self):
3536
self.parser = ResourceModelParser()
3637
self.pv_service = pyVmomiService(SmartConnect, Disconnect, SynchronousTaskWaiter())
37-
self.cs_helper = CloudshellDriverHelper()
3838
self.context_based_logger_factory = ContextBasedLoggerFactory()
3939

4040
def _get_logger(self, context):
@@ -51,15 +51,15 @@ def validate_and_discover(self, context):
5151
"""
5252
logger = self._get_logger(context)
5353
logger.info('Autodiscovery started')
54+
si = None
55+
resource = None
5456

55-
session = self.cs_helper.get_session(context.connectivity.server_address,
56-
context.connectivity.admin_auth_token,
57-
DOMAIN)
58-
self._check_if_attribute_not_empty(context.resource, ADDRESS)
59-
resource = context.resource
60-
auto_attr = []
61-
si = self._check_if_vcenter_user_pass_valid(context, session, resource.attributes)
57+
with CloudShellSessionContext(context) as cloudshell_session:
58+
self._check_if_attribute_not_empty(context.resource, ADDRESS)
59+
resource = context.resource
60+
si = self._check_if_vcenter_user_pass_valid(context, cloudshell_session, resource.attributes)
6261

62+
auto_attr = []
6363
if not si:
6464
error_message = 'Could not connect to the vCenter: {0}, with given credentials'\
6565
.format(context.resource.address)
@@ -69,6 +69,7 @@ def validate_and_discover(self, context):
6969
try:
7070
all_dc = self.pv_service.get_all_items_in_vcenter(si, vim.Datacenter)
7171
dc = self._validate_datacenter(si, all_dc, auto_attr, resource.attributes)
72+
7273
all_items_in_dc = self.pv_service.get_all_items_in_vcenter(si, None, dc)
7374
dc_name = dc.name
7475

@@ -111,6 +112,21 @@ def _validate_datacenter(self, si, all_item_in_vc, auto_att, attributes):
111112
auto_att.append(AutoLoadAttribute('', DEFAULT_DATACENTER, dc.name))
112113
return dc
113114

115+
def _validate_default_dvswitch(self, si, all_items_in_vc, auto_att, dc_name, attributes, key):
116+
117+
dvs_path = attributes[key]
118+
119+
# optional pararm
120+
if(not attributes[key]):
121+
return
122+
123+
path = "{}/{}".format(dc_name, dvs_path)
124+
dv = self.pv_service.find_dvs_by_path(si, path)
125+
126+
auto_att.append(AutoLoadAttribute('', DEFAULT_DVSWITCH, dvs_path))
127+
128+
return dv
129+
114130
def _validate_attribute(self, si, attributes, vim_type, name, prefix=''):
115131
if name in attributes and attributes[name]:
116132
att_value = attributes[name]

0 commit comments

Comments
 (0)