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)
Beispiel #2
0
def create_cs_session(debug):
    if debug == 'yes':
        try:
            dev_helpers_71.attach_to_cloudshell_as("admin", "admin", "Global",
                                                   reservation_id='59b547e3-6e9e-49d3-906f-2e28582ac98b',
                                                   server_address='q1.cisco.com')
        except:
            dev_helpers_64.attach_to_cloudshell_as("admin", "admin", "Global",
                                                   reservation_id='6376f07e-6d30-4b2b-811c-2eee0c77832b',
                                                   server_address='q1.cisco.com')

    try:
        session = helpers_71.get_api_session()
        helpers = helpers_71
    except:
        session = helpers_64.get_api_session()
        helpers = helpers_64
    return session, helpers
    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)
Beispiel #4
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)
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)
Beispiel #6
0
def attachAndGetResourceContext(cloudshellConnectData):
    dev_helpers.attach_to_cloudshell_as(cloudshellConnectData["user"],
                                        cloudshellConnectData["password"],
                                        cloudshellConnectData["domain"],
                                        cloudshellConnectData["reservationId"])
Beispiel #7
0
def attachAndGetResourceContext(cloudshellConnectData):
    dev_helpers.attach_to_cloudshell_as(cloudshellConnectData["user"],
                                        cloudshellConnectData["password"],
                                        cloudshellConnectData["domain"],
                                        cloudshellConnectData["reservationId"])
Beispiel #8
0
import qualipy.scripts.cloudshell_dev_helpers as dhelpers
import qualipy.scripts.cloudshell_scripts_helpers as helpers

reservationId = 'b0ce36a1-48be-4ff7-9d9b-80bdc430ab68'
dhelpers.attach_to_cloudshell_as('admin',
                                 'admin',
                                 'Global',
                                 reservationId,
                                 server_address='q1.cisco.com')
api_session = helpers.get_api_session()

playable_Switches = []
switches = api_session.GetReservationDetails(reservationId)
for switch in switches.ReservationDescription.Resources:
    if switch.ResourceFamilyName == 'Power Port':
        playable_Switches.append(switch.Name.split("/")[0])
for aswitch in playable_Switches:
    api_session.ExecuteResourceConnectedCommand(reservationId,
                                                aswitch,
                                                'PowerOff',
                                                'power',
                                                parameterValues=[],
                                                printOutput=True)
pass