Exemplo n.º 1
0
def main():
    # get vlan auto resource model
    resource_context = helpers.get_resource_context_details()
    resource_model_parser = ResourceModelParser()
    vlan_auto_resource_model = resource_model_parser.convert_to_resource_model(resource_context)
    # get reservation details
    reservation_context = helpers.get_reservation_context_details()
    # Start api session
    api = helpers.get_api_session()

    vlan_service_provider = VlanResolverProvider(vlan_resource_model=vlan_auto_resource_model,
                                                 pool_id=reservation_context.domain,
                                                 reservation_id=reservation_context.id,
                                                 owner_id=resource_context.name,
                                                 api=api)

    if not vlan_service_provider.is_vlan_resolved():
        # resolve vlan id
        vlan_id = vlan_service_provider.resolve_vlan_auto()
        vlan_id = str(vlan_id)
        # set resolved vlan id to virtual network attribute
        api.SetServiceAttributesValues(reservation_context.id,
                                       resource_context.name,
                                       [AttributeNameValue(
                                               vlan_auto_resource_model.virtual_network_attribute,
                                               vlan_id)])
        _logger.info("{0} resolved vlan id {1} successfully".format(resource_context.name, vlan_id))

    else:
        vlan_id = str(vlan_auto_resource_model.virtual_network)
        _logger.info("{0} already has a resolved vlan id: {1}".format(resource_context.name, vlan_id))

    # command result for programmatic use
    set_command_result(vlan_id)
Exemplo n.º 2
0
    def connect_all(self):
        """
        Connects all the VLAN Auto services to all the Deployed Apps in the same Environment
        :return:
        """
        session = helpers.get_api_session()
        reservation_id = helpers.get_reservation_context_details().id

        # GetReservationDetails is performance heavy operation
        reservation_details = session.GetReservationDetails(reservation_id)
        vlan_services = self._get_vlan_auto_services(reservation_details)

        connectors = self._get_connectors(reservation_details)

        if not vlan_services or not connectors:
            return

        for vlan_service in vlan_services:

            _logger.debug('Connecting \'{0}\' '.format(
                vlan_service.ServiceName))

            access_mode = self._get_attribute(vlan_service.Attributes,
                                              ACCESS_MODE_ATTRIBUTE)
            virtual_network = self._get_attribute(vlan_service.Attributes,
                                                  VIRTUAL_NETWORK_ATTRIBUTE)

            # Get Deployed App connected to VLAN Auto service
            connected_resources = self._get_connected_resources(
                connectors, vlan_service)

            if not connected_resources:
                continue

            if not virtual_network or virtual_network == '':

                _logger.debug('Executing Auto Resolve Vlan on \'{0}\''.format(
                    vlan_service.ServiceName))

                command_result = session.ExecuteCommand(
                    reservation_id, vlan_service.ServiceName, 'Service',
                    'Auto Resolve Vlan', [], True)

                virtual_network = get_result_from_command_output(
                    command_result.Output)

                _logger.debug(
                    'Auto Resolve Vlan returned Virtual Network \'{0}\''.
                    format(virtual_network))

                if not virtual_network or virtual_network == '':
                    raise ValueError(
                        'Auto Resolve Vlan command did not return Virtual Network'
                    )

            for connected_resource in connected_resources:
                self._execute_connect_command_on_connected_resource(
                    access_mode, connected_resource, reservation_id, session,
                    virtual_network, vlan_service.ServiceName)
Exemplo n.º 3
0
 def create_resource_for_deployed_vm(self, data_holder, deploy_result):
     reservation_id = helpers.get_reservation_context_details().id
     session = helpers.get_api_session()
     session.CreateResource("Virtual Machine", "Virtual Machine", deploy_result.vm_name, deploy_result.vm_name)
     session.AddResourcesToReservation(reservation_id, [deploy_result.vm_name])
     session.SetAttributesValues(
                 [ResourceAttributesUpdateRequest(deploy_result.vm_name,
                 [AttributeNameValue("vCenter Inventory Path", data_holder.template_model.vCenter_resource_name + "/" + data_holder.template_model.vm_folder),
                     AttributeNameValue("UUID", deploy_result.uuid),
                     AttributeNameValue("vCenter Template", data_holder.resource_context.attributes["vCenter Template"])])])
Exemplo n.º 4
0
    def replace_app_resource_with_vm_resource(self, data_holder, deploy_result):
        app_name = data_holder.resource_context.name
        self.create_resource_for_deployed_vm(data_holder, deploy_result)

        reservation_id = helpers.get_reservation_context_details().id
        session = helpers.get_api_session()

        services_position = session.GetReservationServicesPositions(reservation_id)
        app_poistion = first_or_default(services_position.ResourceDiagramLayouts, lambda x: x.ResourceName == app_name)

        session.RemoveServicesFromReservation(reservation_id, app_name)
        session.SetReservationResourcePosition(reservation_id, deploy_result.vm_name, app_poistion.X, app_poistion.Y)
Exemplo n.º 5
0
def execute_app_orchestration():
    # Retrieve data from environment variables
    reservation_id = helpers.get_reservation_context_details().id
    resource_details = helpers.get_resource_context_details_dict()
    helpers.get_resource_context_details()
    app_name = resource_details["name"]
    deployment_service = resource_details["appData"]["deploymentService"][
        "name"]
    installation_service_data = resource_details["appData"][
        "installationService"]

    # Start api session
    api = helpers.get_api_session()

    # execute deploy app
    deployment_result = deploy_app(api, app_name, deployment_service,
                                   reservation_id)

    # if visual connector endpoints contains service with attribute "Virtual Network" execute connect command
    # TODO

    # TODO this is temporary until we move to drivers
    api.SetAttributesValues([
        ResourceAttributesUpdateRequest(
            deployment_result.LogicalResourceName, [
                AttributeNameValue("VM_UUID", deployment_result.VmUuid),
                AttributeNameValue("Cloud Provider",
                                   deployment_result.CloudProviderResourceName)
            ])
    ])

    # connect all
    connect_all(api, reservation_id)

    # "Power On"
    power_on_deployed_app(api, app_name, deployment_result, reservation_id)

    # if install service exists on app execute it
    execute_installation_if_exist(api, deployment_result,
                                  installation_service_data, reservation_id)

    # refresh ip
    #refresh_ip(api, deployment_result, reservation_id)

    # Set live status - deployment done
    api.SetResourceLiveStatus(deployment_result.LogicalResourceName, "Online",
                              "Active")

    logger.info("Deployed {0} Successfully".format(app_name))
    def execute_command_on_vcenter_resource(
            generic_deployed_app_resource_model, command, inputs):
        session = helpers.get_api_session()
        reservation_id = helpers.get_reservation_context_details().id

        _logger.debug('Executing ' + command + ' command on ' +
                      generic_deployed_app_resource_model.cloud_provider)

        command_result = session.ExecuteCommand(
            reservation_id, generic_deployed_app_resource_model.cloud_provider,
            'Resource', command, inputs, True)

        _logger.info('Command ' + command + ' result: ' +
                     command_result.Output)

        return command_result
    def execute_command_on_vcenter_resource(generic_deployed_app_resource_model, command, inputs):
        session = helpers.get_api_session()
        reservation_id = helpers.get_reservation_context_details().id

        _logger.debug('Executing ' + command + ' command on ' + generic_deployed_app_resource_model.cloud_provider)

        command_result = session.ExecuteCommand(reservation_id,
                                                generic_deployed_app_resource_model.cloud_provider,
                                                'Resource',
                                                command,
                                                inputs,
                                                True)

        _logger.info('Command ' + command + ' result: ' + command_result.Output)

        return command_result
    def integrationtest_get_auto_vlan_specific_id(self):

        dev_helpers.attach_to_cloudshell_as(
            "admin", "admin", "Global", "4255fc8b-f964-444d-aa0c-96ae58659a52")

        requested_vlan_id = "24"
        os.environ["RESOURCECONTEXT"] = \
            '{' \
            ' "name":"VLAN Auto", ' \
            ' "address":"Service",' \
            ' "model":"VLAN Auto", ' \
            ' "family":"Virtual Network", ' \
            ' "description":"", ' \
            ' "fullname":"", ' \
            ' "attributes":{"Access Mode":"trunk",' \
                            '"Allocation Ranges":"2-4098",' \
                            '"Isolation Level":"Shared", ' \
                            '"Virtual Network":"", ' \
                            '"VLAN Id":"' + requested_vlan_id + '"}}'

        resource_context = helpers.get_resource_context_details()

        vlan_auto_resource_model = VLANAutoResourceModel()
        vlan_auto_resource_model.access_mode = resource_context.attributes[
            "Access Mode"]
        vlan_auto_resource_model.allocation_ranges = resource_context.attributes[
            "Allocation Ranges"]
        vlan_auto_resource_model.isolation_level = resource_context.attributes[
            "Isolation Level"]
        vlan_auto_resource_model.vlan_id = resource_context.attributes[
            "VLAN Id"]
        vlan_auto_resource_model.virtual_network = resource_context.attributes[
            "Virtual Network"]
        vlan_auto_resource_model.virtual_network_attribute = "Virtual Network"

        # get reservation details
        reservation_details = helpers.get_reservation_context_details()

        # Start api session
        api = helpers.get_api_session()

        vlan_service_provider = VlanResolverProvider(
            vlan_auto_resource_model, reservation_details.domain,
            reservation_details.id, resource_context.name, api)
        vlan_id = vlan_service_provider.resolve_vlan_auto()

        assert (vlan_id, requested_vlan_id)
Exemplo n.º 9
0
    def connect_all(self):
        """
        Connects all the VLAN Auto services to all the Deployed Apps in the same Environment
        :return:
        """
        session = helpers.get_api_session()
        reservation_id = helpers.get_reservation_context_details().id

        # GetReservationDetails is performance heavy operation
        reservation_details = session.GetReservationDetails(reservation_id)
        vlan_services = self._get_vlan_auto_services(reservation_details)

        connectors = self._get_connectors(reservation_details)

        if not vlan_services or not connectors:
            return

        for vlan_service in vlan_services:

            _logger.debug('Connecting \'{0}\' '.format(vlan_service.ServiceName))

            access_mode = self._get_attribute(vlan_service.Attributes, ACCESS_MODE_ATTRIBUTE)
            virtual_network = self._get_attribute(vlan_service.Attributes, VIRTUAL_NETWORK_ATTRIBUTE)

            # Get Deployed App connected to VLAN Auto service
            connected_resources = self._get_connected_resources(connectors, vlan_service)

            if not connected_resources:
                continue

            if not virtual_network or virtual_network == '':

                _logger.debug('Executing Auto Resolve Vlan on \'{0}\''.format(vlan_service.ServiceName))

                command_result = session.ExecuteCommand(reservation_id, vlan_service.ServiceName, 'Service',
                                                        'Auto Resolve Vlan', [], True)

                virtual_network = get_result_from_command_output(command_result.Output)

                _logger.debug('Auto Resolve Vlan returned Virtual Network \'{0}\''.format(virtual_network))

                if not virtual_network or virtual_network == '':
                    raise ValueError('Auto Resolve Vlan command did not return Virtual Network')

            for connected_resource in connected_resources:
                self._execute_connect_command_on_connected_resource(access_mode, connected_resource, reservation_id,
                                                                    session, virtual_network, vlan_service.ServiceName)
Exemplo n.º 10
0
    def execute(self):
        data_holder = self._get_data_holder()
        json_data_holder = jsonpickle.encode(data_holder, unpicklable=False)

        reservation_id = helpers.get_reservation_context_details().id
        api = helpers.get_api_session()
        result = api.ExecuteCommand(reservation_id,
                                    data_holder.template_model.vCenter_resource_name,
                                    "Resource",
                                    self.COMMAND_DEPLOY_FROM_TEMPLATE,
                                    self._get_command_inputs_list(json_data_holder),
                                    False)

        if hasattr(result, 'Output'):
            print result.Output
        else:
            print jsonpickle.encode(result, unpicklable=False)
    def integration_test_update_vnics(self):


        dev_helpers.attach_to_cloudshell_as("admin", "admin", "Global", "1205e711-edf7-4b12-8a5e-e0ff53768ce7")
        details = helpers.get_reservation_context_details()
        py_vmomi_service = pyVmomiService(SmartConnect, Disconnect)
        cred = TestCredentials()
        si = py_vmomi_service.connect(cred.host, cred.username, cred.password, cred.port)
        vm = py_vmomi_service.find_vm_by_name(si, 'QualiSB/Alex', 'Ubuntu_a287f573')

        nics = [x for x in vm.config.hardware.device
                if isinstance(x, vim.vm.device.VirtualEthernetCard)]

        for nic in nics:
            network_name = nic.backing.network.name
            mac_address = nic.macAddress

            print network_name + mac_address
    def integrationtest_get_auto_vlan_specific_id(self):

        dev_helpers.attach_to_cloudshell_as("admin", "admin", "Global", "4255fc8b-f964-444d-aa0c-96ae58659a52")

        requested_vlan_id = "24"
        os.environ["RESOURCECONTEXT"] = \
            '{' \
            ' "name":"VLAN Auto", ' \
            ' "address":"Service",' \
            ' "model":"VLAN Auto", ' \
            ' "family":"Virtual Network", ' \
            ' "description":"", ' \
            ' "fullname":"", ' \
            ' "attributes":{"Access Mode":"trunk",' \
                            '"Allocation Ranges":"2-4098",' \
                            '"Isolation Level":"Shared", ' \
                            '"Virtual Network":"", ' \
                            '"VLAN Id":"' + requested_vlan_id + '"}}'

        resource_context = helpers.get_resource_context_details()

        vlan_auto_resource_model = VLANAutoResourceModel()
        vlan_auto_resource_model.access_mode = resource_context.attributes["Access Mode"]
        vlan_auto_resource_model.allocation_ranges = resource_context.attributes["Allocation Ranges"]
        vlan_auto_resource_model.isolation_level = resource_context.attributes["Isolation Level"]
        vlan_auto_resource_model.vlan_id = resource_context.attributes["VLAN Id"]
        vlan_auto_resource_model.virtual_network = resource_context.attributes["Virtual Network"]
        vlan_auto_resource_model.virtual_network_attribute = "Virtual Network"

        # get reservation details
        reservation_details = helpers.get_reservation_context_details()

        # Start api session
        api = helpers.get_api_session()

        vlan_service_provider = VlanResolverProvider(vlan_auto_resource_model,
                                                     reservation_details.domain,
                                                     reservation_details.id,
                                                     resource_context.name,
                                                     api)
        vlan_id = vlan_service_provider.resolve_vlan_auto()

        assert(vlan_id, requested_vlan_id)
Exemplo n.º 13
0
def execute_app_orchestration():
    # Retrieve data from environment variables
    reservation_id = helpers.get_reservation_context_details().id
    resource_details = helpers.get_resource_context_details_dict()
    helpers.get_resource_context_details()
    app_name = resource_details["name"]
    deployment_service = resource_details["appData"]["deploymentService"]["name"]
    installation_service_data = resource_details["appData"]["installationService"]

    # Start api session
    api = helpers.get_api_session()

    # execute deploy app
    deployment_result = deploy_app(api, app_name, deployment_service, reservation_id)

    # if visual connector endpoints contains service with attribute "Virtual Network" execute connect command
    # TODO

    # TODO this is temporary until we move to drivers
    api.SetAttributesValues(
            [ResourceAttributesUpdateRequest(
                    deployment_result.LogicalResourceName,
                    [AttributeNameValue("VM_UUID", deployment_result.VmUuid),
                     AttributeNameValue("Cloud Provider", deployment_result.CloudProviderResourceName)])])

    # connect all
    connect_all(api, reservation_id)

    # "Power On"
    power_on_deployed_app(api, app_name, deployment_result, reservation_id)

    # if install service exists on app execute it
    execute_installation_if_exist(api, deployment_result, installation_service_data, reservation_id)

    # refresh ip
    #refresh_ip(api, deployment_result, reservation_id)

    # Set live status - deployment done
    api.SetResourceLiveStatus(deployment_result.LogicalResourceName, "Online", "Active")

    logger.info("Deployed {0} Successfully".format(app_name))
    def integration_test_update_vnics(self):

        dev_helpers.attach_to_cloudshell_as(
            "admin", "admin", "Global", "1205e711-edf7-4b12-8a5e-e0ff53768ce7")
        details = helpers.get_reservation_context_details()
        py_vmomi_service = pyVmomiService(SmartConnect, Disconnect)
        cred = TestCredentials()
        si = py_vmomi_service.connect(cred.host, cred.username, cred.password,
                                      cred.port)
        vm = py_vmomi_service.find_vm_by_name(si, 'QualiSB/Alex',
                                              'Ubuntu_a287f573')

        nics = [
            x for x in vm.config.hardware.device
            if isinstance(x, vim.vm.device.VirtualEthernetCard)
        ]

        for nic in nics:
            network_name = nic.backing.network.name
            mac_address = nic.macAddress

            print network_name + mac_address
Exemplo n.º 15
0
def main():
    # get vlan auto resource model
    resource_context = helpers.get_resource_context_details()
    resource_model_parser = ResourceModelParser()
    vlan_auto_resource_model = resource_model_parser.convert_to_resource_model(
        resource_context)
    # get reservation details
    reservation_context = helpers.get_reservation_context_details()
    # Start api session
    api = helpers.get_api_session()

    vlan_service_provider = VlanResolverProvider(
        vlan_resource_model=vlan_auto_resource_model,
        pool_id=reservation_context.domain,
        reservation_id=reservation_context.id,
        owner_id=resource_context.name,
        api=api)

    if not vlan_service_provider.is_vlan_resolved():
        # resolve vlan id
        vlan_id = vlan_service_provider.resolve_vlan_auto()
        vlan_id = str(vlan_id)
        # set resolved vlan id to virtual network attribute
        api.SetServiceAttributesValues(
            reservation_context.id, resource_context.name, [
                AttributeNameValue(
                    vlan_auto_resource_model.virtual_network_attribute,
                    vlan_id)
            ])
        _logger.info("{0} resolved vlan id {1} successfully".format(
            resource_context.name, vlan_id))

    else:
        vlan_id = str(vlan_auto_resource_model.virtual_network)
        _logger.info("{0} already has a resolved vlan id: {1}".format(
            resource_context.name, vlan_id))

    # command result for programmatic use
    set_command_result(vlan_id)
    def execute(self):
        """ execute the command """

        resource_att = helpers.get_resource_context_details()

        # get vCenter resource name
        inventory_path_data = self.csRetrieverService.getVCenterInventoryPathAttributeData(resource_att)
        vCenter_resource_name = inventory_path_data.vCenter_resource_name
        vm_folder = inventory_path_data.vm_folder

        print "Folder: {0}, vCenter: {1}".format(vm_folder, vCenter_resource_name)

        reservation_id = helpers.get_reservation_context_details().id
        session = helpers.get_api_session()
        vCenter_details = session.GetResourceDetails(vCenter_resource_name)

        # get vCenter connection details from vCenter resource
        vCenterConn = self.csRetrieverService.getVCenterConnectionDetails(session, vCenter_details)

        print "Connecting to: {0}, As: {1}, Pwd: {2}".format(vCenterConn["vCenter_url"], vCenterConn["user"],
                                                             vCenterConn["password"])

        # connect
        si = self.pvService.connect(vCenterConn["vCenter_url"], vCenterConn["user"], vCenterConn["password"])
        content = si.RetrieveContent()

        # destroy the vm
        vm_name = resource_att.name
        self.pvService.destroy_vm_by_name(content, si, vm_name)

        # disconnect
        self.pvService.disconnect(si)

        # delete resource 
        helpers.get_api_session() \
            .DeleteResource(resource_att.fullname)
def run(pvService, cloudshellConnectData):
    """
    Create a VM, sleep, and destroy the VM

    pvService:              pyVmomiService Instance
    cloudshellConnectData:  dictionary with cloudshell connection data
    """

    csRetrieverService = CloudshellDataRetrieverService()

    dev_helpers.attach_to_cloudshell_as(cloudshellConnectData["user"], 
                                        cloudshellConnectData["password"], 
                                        cloudshellConnectData["domain"], 
                                        cloudshellConnectData["reservationId"])
    resource_att = helpers.get_resource_context_details()
        

    # get vCenter resource name, template name, template folder
    vCenterTemplateAttData = csRetrieverService.getVCenterTemplateAttributeData(resource_att)
    template_name = vCenterTemplateAttData["template_name"]
    vCenter_resource_name = vCenterTemplateAttData["vCenter_resource_name"]
    vm_folder = vCenterTemplateAttData["vm_folder"]
    print "Template: {0}, Folder: {1}, vCenter: {2}".format(template_name,vm_folder,vCenter_resource_name)
    

    # get power state of the cloned VM
    power_on = csRetrieverService.getPowerStateAttributeData(resource_att)
    print "Power On: {0}".format(power_on)


    # get cluster and resource pool
    vmClusterAttData = csRetrieverService.getVMClusterAttributeData(resource_att)
    cluster_name = vmClusterAttData["cluster_name"]
    resource_pool = vmClusterAttData["resource_pool"]
    print "Cluster: {0}, Resource Pool: {1}".format(cluster_name, resource_pool)


    # get datastore
    datastore_name = csRetrieverService.getVMStorageAttributeData(resource_att)
    print "Datastore: {0}".format(datastore_name)


    reservation_id = helpers.get_reservation_context_details().id
    session = helpers.get_api_session()
    vCenter_details = session.GetResourceDetails(vCenter_resource_name)
    
    # get vCenter connection details from vCenter resource
    vCenterConn = csRetrieverService.getVCenterConnectionDetails(session, vCenter_details)
    print "Connecting to: {0}, As: {1}, Pwd: {2}".format(vCenterConn["vCenter_url"] , vCenterConn["user"], vCenterConn["password"])
 
    # connect
    si = pvService.connect(vCenterConn["vCenter_url"] , vCenterConn["user"], vCenterConn["password"])
    content = si.RetrieveContent()
    template = pvService.get_obj(content, [vim.VirtualMachine], template_name)
    
    if template:
        # generate unique name
        vm_name = generate_unique_name(template_name)

        vm = pvService.clone_vm(
            content = content, 
            si = si,
            template = template, 
            vm_name = vm_name,
            datacenter_name = None, 
            vm_folder = vm_folder, 
            datastore_name = datastore_name, 
            cluster_name = cluster_name,
            resource_pool = resource_pool,
            power_on = power_on)

        helpers.get_api_session() \
            .CreateResource("Virtual Machine",
                            "Virtual Machine", vm_name,
                            vm.summary.config.instanceUuid)
        helpers.get_api_session() \
            .AddResourcesToReservation(reservation_id, [vm_name])
        helpers.get_api_session() \
            .SetAttributeValue(vm_name,
                               "vCenter Inventory Path",
                               attributeValue = vCenter_resource_name + "/" + vm_folder)


        sleep_sec = 5
        print "Sleep for {0} sec".format(sleep_sec)
        time.sleep( sleep_sec )

        
        # delete the VM and delete resource
        pvService.destroy_vm(content, si, vm)
        helpers.get_api_session().DeleteResource(vm_name)

    else:
        print "template not found"

    pvService.disconnect(si)
Exemplo n.º 18
0
def run(pvService, cloudshellConnectData):
    """
    Create a VM, sleep, and destroy the VM

    pvService:              pyVmomiService Instance
    cloudshellConnectData:  dictionary with cloudshell connection data
    """

    csRetrieverService = CloudshellDataRetrieverService()

    dev_helpers.attach_to_cloudshell_as(cloudshellConnectData["user"],
                                        cloudshellConnectData["password"],
                                        cloudshellConnectData["domain"],
                                        cloudshellConnectData["reservationId"])
    resource_att = helpers.get_resource_context_details()

    # get vCenter resource name, template name, template folder
    vCenterTemplateAttData = csRetrieverService.getVCenterTemplateAttributeData(
        resource_att)
    template_name = vCenterTemplateAttData["template_name"]
    vCenter_resource_name = vCenterTemplateAttData["vCenter_resource_name"]
    vm_folder = vCenterTemplateAttData["vm_folder"]
    print "Template: {0}, Folder: {1}, vCenter: {2}".format(
        template_name, vm_folder, vCenter_resource_name)

    # get power state of the cloned VM
    power_on = csRetrieverService.getPowerStateAttributeData(resource_att)
    print "Power On: {0}".format(power_on)

    # get cluster and resource pool
    vmClusterAttData = csRetrieverService.getVMClusterAttributeData(
        resource_att)
    cluster_name = vmClusterAttData["cluster_name"]
    resource_pool = vmClusterAttData["resource_pool"]
    print "Cluster: {0}, Resource Pool: {1}".format(cluster_name,
                                                    resource_pool)

    # get datastore
    datastore_name = csRetrieverService.getVMStorageAttributeData(resource_att)
    print "Datastore: {0}".format(datastore_name)

    reservation_id = helpers.get_reservation_context_details().id
    session = helpers.get_api_session()
    vCenter_details = session.GetResourceDetails(vCenter_resource_name)

    # get vCenter connection details from vCenter resource
    vCenterConn = csRetrieverService.getVCenterConnectionDetails(
        session, vCenter_details)
    print "Connecting to: {0}, As: {1}, Pwd: {2}".format(
        vCenterConn["vCenter_url"], vCenterConn["user"],
        vCenterConn["password"])

    # connect
    si = pvService.connect(vCenterConn["vCenter_url"], vCenterConn["user"],
                           vCenterConn["password"])
    content = si.RetrieveContent()
    template = pvService.get_obj(content, [vim.VirtualMachine], template_name)

    if template:
        # generate unique name
        vm_name = generate_unique_name(template_name)

        vm = pvService.clone_vm(content=content,
                                si=si,
                                template=template,
                                vm_name=vm_name,
                                datacenter_name=None,
                                vm_folder=vm_folder,
                                datastore_name=datastore_name,
                                cluster_name=cluster_name,
                                resource_pool=resource_pool,
                                power_on=power_on)

        helpers.get_api_session() \
            .CreateResource("Virtual Machine",
                            "Virtual Machine", vm_name,
                            vm.summary.config.instanceUuid)
        helpers.get_api_session() \
            .AddResourcesToReservation(reservation_id, [vm_name])
        helpers.get_api_session() \
            .SetAttributeValue(vm_name,
                               "vCenter Inventory Path",
                               attributeValue = vCenter_resource_name + "/" + vm_folder)

        sleep_sec = 5
        print "Sleep for {0} sec".format(sleep_sec)
        time.sleep(sleep_sec)

        # delete the VM and delete resource
        pvService.destroy_vm(content, si, vm)
        helpers.get_api_session().DeleteResource(vm_name)

    else:
        print "template not found"

    pvService.disconnect(si)
import telnetlib
import re
import traceback
import time
import qualipy.api.cloudshell_api as CA
import json
import os
import errno
import qualipy.scripts.cloudshell_scripts_helpers as CS

serverAddress = CS.get_connectivity_context_details().server_address
adminUser = CS.get_connectivity_context_details().admin_user
adminPass = CS.get_connectivity_context_details().admin_pass
domain = CS.get_reservation_context_details().domain

#get the reservation id
resID = CS.get_reservation_context_details().id
#Set the ip of the host from the resource
host = CS.get_resource_context_details().address
#Set the user name of the user from the resource
atts = CS.get_resource_context_details().attributes
# Get the username out of the resource attributes
username = atts['User']

# Get the password out of the resource attributes
passwEn = atts['Password']

#Decrypt the password
session = CA.CloudShellAPISession(serverAddress,adminUser,adminPass,domain)
password = session.DecryptPassword(passwEn).Value
Exemplo n.º 20
0
import telnetlib
import re
import traceback
import time
import qualipy.api.cloudshell_api as CA
import json
import os
import errno
import qualipy.scripts.cloudshell_scripts_helpers as CS

serverAddress = CS.get_connectivity_context_details().server_address
adminUser = CS.get_connectivity_context_details().admin_user
adminPass = CS.get_connectivity_context_details().admin_pass
domain = CS.get_reservation_context_details().domain

#get the reservation id
resID = CS.get_reservation_context_details().id
#Set the ip of the host from the resource
host = CS.get_resource_context_details().address
#Set the user name of the user from the resource
atts = CS.get_resource_context_details().attributes
# Get the username out of the resource attributes
username = atts['User']

# Get the password out of the resource attributes
passwEn = atts['Password']

#Decrypt the password
session = CA.CloudShellAPISession(serverAddress, adminUser, adminPass, domain)
password = session.DecryptPassword(passwEn).Value