def create_disk(client):
    logging.info('INIT create_disk')

    logged_in_org = client.get_org()
    org = Org(client, resource=logged_in_org)
    v = org.get_vdc('OVD2')
    if v is None:
        raise errors.VDCNotFoundError(vappInfo.vdc)
    vdc = VDC(client, href=v.get('href'))

    #task=vdc.delete_disk('disk01')

    result = vdc.add_disk('disk02', "100")
    logging.info('DONE create_disk %s', result)

    task = client.get_task_monitor().wait_for_status(
        task=result.Tasks.Task[0],
        timeout=60,
        poll_frequency=2,
        fail_on_status=None,
        expected_target_statuses=[
            TaskStatus.SUCCESS, TaskStatus.ABORTED, TaskStatus.ERROR,
            TaskStatus.CANCELED
        ],
        callback=task_callback)
    st = task.get('status')
    if st == TaskStatus.SUCCESS.value:
        logging.info("__LOG__ created DISK")
        #cresult.created = True
    else:
        raise errors.VCDDiskCreationError(
            etree.tostring(task, pretty_print=True))
    def read(self, request):
        logging.info("__INIT__read[VappVm]")
        res = vapp_vm_pb2.ReadVappVmResult()
        res.present = False
        org_resource = self.client.get_org()
        org = Org(self.client, resource=org_resource)
        try:
            vdc_resource = org.get_vdc(request.target_vdc)
            vdc = VDC(
                self.client, name=request.target_vdc, resource=vdc_resource)

            vapp_resource = vdc.get_vapp(request.target_vapp)
            vapp = VApp(
                self.client, name=request.target_vapp, resource=vapp_resource)
            read_vapp_vm_resp = vapp.get_vm(request.target_vm_name)
            vm = VM(client=self.client, href=None, resource=read_vapp_vm_resp)

            res.present = True
        except Exception as e:
            errmsg = '__ERROR_read[VappVm] failed for VappVm {0}. __ErrorMessage__ {1}'
            logging.warn(errmsg.format(request.target_vm_name, str(e)))

            return res

        logging.info("__DONE__read[VappVm]")

        return res
    def capture_vapp(self):
        params = self.params
        vapp_name = params.get('vapp_name')
        vdc_name = params.get('vdc_name')
        catalog_name = params.get('catalog_name')
        item_name = params.get('item_name')
        desc = params.get('description')
        customize_on_instantiate = params.get('customize_on_instantiate')
        overwrite = params.get('overwrite')
        client = self.client
        response = dict()
        response['changed'] = False

        v = self.org.get_vdc(vdc_name)
        vdc = VDC(client, href=v.get('href'))
        vapp = vdc.get_vapp(vapp_name)
        catalog = self.org.get_catalog(catalog_name)
        self.org.capture_vapp(
            catalog_resource=catalog,
            vapp_href=vapp.get('href'),
            catalog_item_name=item_name,
            description=desc,
            customize_on_instantiate=customize_on_instantiate,
            overwrite=overwrite)
        self.ova_check_resolved()
        response['msg'] = "Catalog Item {} has been captured".format(item_name)
        response['changed'] = True

        return response
Пример #4
0
 def test_001_instantiate_vapp(self):
     logged_in_org = self.client.get_org()
     org = Org(self.client, resource=logged_in_org)
     v = org.get_vdc(self.config['vcd']['vdc'])
     vdc = VDC(self.client, href=v.get('href'))
     assert self.config['vcd']['vdc'] == vdc.get_resource().get('name')
     result = vdc.instantiate_vapp(
         self.config['vcd']['vapp'],
         self.config['vcd']['catalog'],
         self.config['vcd']['template'],
         network='net2',
         fence_mode='natRouted',
         deploy=False,
         power_on=False)
     task = self.client.get_task_monitor().wait_for_status(
         task=result.Tasks.Task[0],
         timeout=60,
         poll_frequency=2,
         fail_on_statuses=None,
         expected_target_statuses=[
             TaskStatus.SUCCESS, TaskStatus.ABORTED, TaskStatus.ERROR,
             TaskStatus.CANCELED
         ],
         callback=None)
     assert task.get('status') == TaskStatus.SUCCESS.value
def delete_vm(client):
    print("================= Vdc delete request ===================")
    vdc_name = "pcp_vdc_02"
    target_vm_name = "pcp_vm"
    org_resource = client.get_org()
    org = Org(client, resource=org_resource)
    print("Org name: ", org.get_name())
    print("Vdc name: ", vdc_name)

    vdc_resource = org.get_vdc(vdc_name)
    vdc = VDC(client, name=vdc_name, resource=vdc_resource)

    vapp_resource = vdc.get_vapp(vapp_name)
    vapp = VApp(client, name=vapp_name, resource=vapp_resource)

    delete_vapp_vm_resp = vapp.delete_vms(target_vm_name)
    task = client.get_task_monitor().wait_for_status(
        task=delete_vapp_vm_resp,
        timeout=60,
        poll_frequency=2,
        fail_on_statuses=None,
        expected_target_statuses=[
            TaskStatus.SUCCESS, TaskStatus.ABORTED, TaskStatus.ERROR,
            TaskStatus.CANCELED
        ],
        callback=None)

    st = task.get('status')
    if st == TaskStatus.SUCCESS.value:
        message = 'delete vdc status : {0} '.format(st)
        logging.info(message)
    else:
        raise errors.VCDVdcDeleteError(etree.tostring(task, pretty_print=True))
Пример #6
0
 def test_0002_modify_memory(self):
     logged_in_org = self.client.get_org()
     org = Org(self.client, resource=logged_in_org)
     vdc_resource = org.get_vdc(self.config['vcd']['vdc'])
     vdc = VDC(self.client, resource=vdc_resource)
     assert self.config['vcd']['vdc'] == vdc.get_resource().get('name')
     vapp_resource = vdc.get_vapp(self.config['vcd']['vapp'])
     vapp = VApp(self.client, resource=vapp_resource)
     vm_resource = vapp.get_vm(self.config['vcd']['vm'])
     vm = VM(self.client, resource=vm_resource)
     task = vm.modify_memory(self.config['vcd']['memory'])
     task = self.client.get_task_monitor().wait_for_status(
                         task=task,
                         timeout=60,
                         poll_frequency=2,
                         fail_on_statuses=None,
                         expected_target_statuses=[
                             TaskStatus.SUCCESS,
                             TaskStatus.ABORTED,
                             TaskStatus.ERROR,
                             TaskStatus.CANCELED],
                         callback=None)
     assert task.get('status') == TaskStatus.SUCCESS.value
     vm.reload()
     assert vm.get_memory() == self.config['vcd']['memory']
Пример #7
0
 def test_0002_add_vm(self):
     logged_in_org = self.client.get_org()
     org = Org(self.client, resource=logged_in_org)
     vdc_resource = org.get_vdc(self.config['vcd']['vdc'])
     vdc = VDC(self.client, href=vdc_resource.get('href'))
     assert self.config['vcd']['vdc'] == vdc.get_resource().get('name')
     vapp_resource = vdc.get_vapp(self.config['vcd']['vapp'])
     assert vapp_resource.get('name') == self.config['vcd']['vapp']
     vapp = VApp(self.client, resource=vapp_resource)
     catalog_item = org.get_catalog_item(self.config['vcd']['catalog'],
                                         self.config['vcd']['template'])
     source_vapp_resource = self.client.get_resource(
         catalog_item.Entity.get('href'))
     spec = {'source_vm_name': self.config['vcd']['vm'],
             'vapp': source_vapp_resource}
     spec['target_vm_name'] = self.config['vcd']['hostname']
     spec['hostname'] = self.config['vcd']['hostname']
     spec['network'] = self.config['vcd']['network']
     spec['ip_allocation_mode'] = self.config['vcd']['ip_allocation_mode']
     spec['storage_profile'] = vdc.get_storage_profile(
         self.config['vcd']['storage_profile'])
     vms = [spec]
     result = vapp.add_vms(vms)
     task = self.client.get_task_monitor().wait_for_status(
                         task=result,
                         timeout=60,
                         poll_frequency=2,
                         fail_on_statuses=None,
                         expected_target_statuses=[
                             TaskStatus.SUCCESS,
                             TaskStatus.ABORTED,
                             TaskStatus.ERROR,
                             TaskStatus.CANCELED],
                         callback=None)
     assert task.get('status') == TaskStatus.SUCCESS.value
Пример #8
0
def create_isolated_network(ctx, name, gateway_ip, netmask, description,
                            primary_dns_ip, secondary_dns_ip, dns_suffix,
                            ip_range_start, ip_range_end, is_dhcp_enabled,
                            default_lease_time, max_lease_time,
                            dhcp_ip_range_start, dhcp_ip_range_end, is_shared):
    try:
        restore_session(ctx, vdc_required=True)
        client = ctx.obj['client']
        in_use_vdc_href = ctx.obj['profiles'].get('vdc_href')
        vdc = VDC(client, href=in_use_vdc_href)
        prefix_len = netmask_to_cidr_prefix_len(gateway_ip, netmask)
        network_cidr = gateway_ip + '/' + str(prefix_len)

        result = vdc.create_isolated_vdc_network(
            network_name=name,
            network_cidr=network_cidr,
            description=description,
            primary_dns_ip=primary_dns_ip,
            secondary_dns_ip=secondary_dns_ip,
            dns_suffix=dns_suffix,
            ip_range_start=ip_range_start,
            ip_range_end=ip_range_end,
            is_dhcp_enabled=is_dhcp_enabled,
            default_lease_time=default_lease_time,
            max_lease_time=max_lease_time,
            dhcp_ip_range_start=dhcp_ip_range_start,
            dhcp_ip_range_end=dhcp_ip_range_end,
            is_shared=is_shared)

        stdout(result.Tasks.Task[0], ctx)
    except Exception as e:
        stderr(e, ctx)
Пример #9
0
 def test_03_get_vdc_access(self):
     logged_in_org = self.client.get_org()
     org = Org(self.client, resource=logged_in_org)
     vdc_resource = org.get_vdc(self.config['vcd']['vdc'])
     vdc = VDC(self.client, resource=vdc_resource)
     control_access = vdc.get_access_settings()
     assert len(control_access.AccessSettings.AccessSetting) == 2
Пример #10
0
    def create_routed_ovdc_network(cls):
        """Creates a routed org vdc network.

        The name of the created org vdc network is specified in the
        ovdc_network_constant file, skips creating one, if such a network already
        exists.

        :raises: Exception: if the class variable _ovdc_href is not populated.
        """
        cls._basic_check()
        if cls._ovdc_href is None:
            raise Exception('OrgVDC ' +
                            cls._config['vcd']['default_ovdc_name'] +
                            ' doesn\'t exist.')

        vdc = VDC(cls._sys_admin_client, href=cls._ovdc_href)

        expected_net_name = OvdcNetConstants.routed_net_name
        records_list = vdc.list_orgvdc_network_records()

        for network_record in records_list:
            if network_record['name'].lower() == expected_net_name.lower():
                cls._logger.debug('Reusing existing direct org-vdc network ' +
                                  expected_net_name)
                return

        result = vdc.create_routed_vdc_network(
            network_name=OvdcNetConstants.routed_net_name,
            gateway_name=GatewayConstants.name,
            network_cidr=OvdcNetConstants.routed_orgvdc_network_gateway_ip,
            description='org vdc network description')

        cls._sys_admin_client.get_task_monitor() \
            .wait_for_success(task=result.Tasks.Task[0])
Пример #11
0
    def test_060_attach_disk_to_vm_in_vapp(self):
        logged_in_org = self.client.get_org()
        org = Org(self.client, resource=logged_in_org)
        vdc_resource = org.get_vdc(self.config['vcd']['vdc'])
        vdc = VDC(self.client, resource=vdc_resource)
        assert self.config['vcd']['vdc'] == vdc.get_resource().get('name')

        vapp_resource = vdc.get_vapp(self.config['vcd']['vapp'])
        assert self.config['vcd']['vapp'] == vapp_resource.get('name')
        vapp = VApp(self.client, resource=vapp_resource)

        disk = vdc.get_disk(self.config['vcd']['idisk_name'])

        result = vapp.attach_disk_to_vm(disk_href=disk.get('href'),
                                        vm_name=self.config['vcd']['vm'])
        task = self.client.get_task_monitor().wait_for_status(
                            task=result,
                            timeout=60,
                            poll_frequency=2,
                            fail_on_statuses=None,
                            expected_target_statuses=[
                                TaskStatus.SUCCESS,
                                TaskStatus.ABORTED,
                                TaskStatus.ERROR,
                                TaskStatus.CANCELED],
                            callback=None)
        assert task.get('status') == TaskStatus.SUCCESS.value
Пример #12
0
def list_disks(ctx):
    try:
        restore_session(ctx, vdc_required=True)
        client = ctx.obj['client']
        vdc_href = ctx.obj['profiles'].get('vdc_href')
        vdc = VDC(client, href=vdc_href)
        disks = vdc.get_disks()
        result = []
        for disk in disks:
            attached_vms = ''
            if hasattr(disk, 'attached_vms') and \
               hasattr(disk.attached_vms, 'VmReference'):
                attached_vms = disk.attached_vms.VmReference.get('name')
            result.append({
                'name':
                disk.get('name'),
                'id':
                extract_id(disk.get('id')),
                'owner':
                disk.Owner.User.get('name'),
                'size':
                humanfriendly.format_size(int(disk.get('size'))),
                'size_bytes':
                disk.get('size'),
                'status':
                VCLOUD_STATUS_MAP.get(int(disk.get('status'))),
                'vms_attached':
                attached_vms
            })
        stdout(result, ctx, show_id=True)
    except Exception as e:
        stderr(e, ctx)
Пример #13
0
 def test_06_unshare_vdc_access(self):
     logged_in_org = self.client.get_org()
     org = Org(self.client, resource=logged_in_org)
     vdc_resource = org.get_vdc(self.config['vcd']['vdc'])
     vdc = VDC(self.client, resource=vdc_resource)
     control_access = vdc.unshare_from_org_members()
     assert control_access.IsSharedToEveryone.text == 'false'
Пример #14
0
 def test_1006_snapshot_create(self):
     logged_in_org = self.client.get_org()
     org = Org(self.client, resource=logged_in_org)
     vdc_resource = org.get_vdc(self.config['vcd']['vdc'])
     vdc = VDC(self.client, resource=vdc_resource)
     assert self.config['vcd']['vdc'] == vdc.get_resource().get('name')
     vapp_resource = vdc.get_vapp(self.config['vcd']['vapp'])
     assert vapp_resource.get('name') == self.config['vcd']['vapp']
     vapp = VApp(self.client, resource=vapp_resource)
     vm_resource = vapp.get_vm(self.config['vcd']['vm'])
     assert vm_resource.get('name') == self.config['vcd']['vm']
     vm = VM(self.client, resource=vm_resource)
     task = vm.snapshot_create(memory=False, quiesce=False)
     task = self.client.get_task_monitor().wait_for_status(
                         task=task,
                         timeout=120,
                         poll_frequency=2,
                         fail_on_statuses=None,
                         expected_target_statuses=[
                             TaskStatus.SUCCESS,
                             TaskStatus.ABORTED,
                             TaskStatus.ERROR,
                             TaskStatus.CANCELED],
                         callback=None)
     assert task.get('status') == TaskStatus.SUCCESS.value
Пример #15
0
def capture(ctx, name, catalog, template, customizable, description):
    try:
        restore_session(ctx, vdc_required=True)
        client = ctx.obj['client']
        in_use_org_href = ctx.obj['profiles'].get('org_href')
        org = Org(client, in_use_org_href)
        catalog_resource = org.get_catalog(catalog)
        vdc_href = ctx.obj['profiles'].get('vdc_href')
        vdc = VDC(client, href=vdc_href)
        vapp_resource = vdc.get_vapp(name)
        overwrite = False
        if template is None:
            template = vapp_resource.get('name')
        else:
            overwrite = True
        task = org.capture_vapp(
            catalog_resource,
            vapp_href=vapp_resource.get('href'),
            catalog_item_name=template,
            description=description,
            customize_on_instantiate=customizable == 'customizable',
            overwrite=overwrite)
        stdout(task, ctx)
    except Exception as e:
        stderr(e, ctx)
Пример #16
0
 def test_001_list_edge_gateways(self):
     logged_in_org = self.client.get_org()
     org = Org(self.client, resource=logged_in_org)
     v = org.get_vdc(self.config['vcd']['vdc'])
     vdc = VDC(self.client, resource=v)
     edge_gateways = vdc.list_edge_gateways()
     assert len(edge_gateways) > 0
Пример #17
0
def create(ctx, name, description, catalog, template, network, memory, cpu,
           disk_size, ip_allocation_mode, vm_name, hostname, storage_profile,
           accept_all_eulas):
    try:
        restore_session(ctx, vdc_required=True)
        client = ctx.obj['client']
        vdc_href = ctx.obj['profiles'].get('vdc_href')
        vdc = VDC(client, href=vdc_href)
        if catalog is None and template is None:
            vapp_resource = vdc.create_vapp(
                name,
                description=description,
                network=network,
                accept_all_eulas=accept_all_eulas)
        else:
            vapp_resource = vdc.instantiate_vapp(
                name,
                catalog,
                template,
                description=description,
                network=network,
                memory=memory,
                cpu=cpu,
                disk_size=disk_size,
                deploy=True,
                power_on=True,
                accept_all_eulas=accept_all_eulas,
                cust_script=None,
                ip_allocation_mode=ip_allocation_mode,
                vm_name=vm_name,
                hostname=hostname,
                storage_profile=storage_profile)
        stdout(vapp_resource.Tasks.Task[0], ctx)
    except Exception as e:
        stderr(e, ctx)
Пример #18
0
    def test_080_update_disk(self):
        logged_in_org = self.client.get_org()
        org = Org(self.client, resource=logged_in_org)
        vdc_resource = org.get_vdc(self.config['vcd']['vdc'])
        vdc = VDC(self.client, resource=vdc_resource)

        result = vdc.update_disk(
            name=self.config['vcd']['idisk_name'],
            new_name=self.config['vcd']['idisk_new_name'],
            new_size=self.config['vcd']['idisk_new_size'],
            new_description=self.config['vcd']['idisk_new_description'],
            new_storage_profile_name=self.config['vcd']['idisk_new_sp_name'],
            new_iops=self.config['vcd']['idisk_new_iops'])

        task = self.client.get_task_monitor().wait_for_status(
            task=result,
            timeout=30,
            poll_frequency=2,
            fail_on_statuses=None,
            expected_target_statuses=[
                TaskStatus.SUCCESS, TaskStatus.ABORTED, TaskStatus.ERROR,
                TaskStatus.CANCELED
            ],
            callback=None)

        assert task.get('status') == TaskStatus.SUCCESS.value
Пример #19
0
 def test_1002_deploy_vm(self):
     logged_in_org = self.client.get_org()
     org = Org(self.client, resource=logged_in_org)
     v = org.get_vdc(self.config['vcd']['vdc'])
     vdc = VDC(self.client, href=v.get('href'))
     assert self.config['vcd']['vdc'] == vdc.get_resource().get('name')
     vapp_resource = vdc.get_vapp(self.config['vcd']['vapp'])
     assert vapp_resource.get('name') == self.config['vcd']['vapp']
     vapp = VApp(self.client, resource=vapp_resource)
     vm_resource = vapp.get_vm(self.config['vcd']['vm'])
     vm = VM(self.client, resource=vm_resource)
     result = vm.deploy()
     # result = vm.shutdown()
     task = self.client.get_task_monitor().wait_for_status(
         task=result,
         timeout=60,
         poll_frequency=2,
         fail_on_statuses=None,
         expected_target_statuses=[
             TaskStatus.SUCCESS,
             TaskStatus.ABORTED,
             TaskStatus.ERROR,
             TaskStatus.CANCELED],
         callback=None)
     assert task.get('status') == TaskStatus.SUCCESS.value
    def update(self):
        logging.info("__INIT__update[Vdc]")
        res = vdc_pb2.UpdateVdcResult()
        res.updated = False
        context = self.context
        logged_in_org = self.client.get_org()
        org = Org(self.client, resource=logged_in_org)

        #Vdc details
        name = self.name
        is_enabled = self.is_enabled

        try:
            vdc_resource = org.get_vdc(name)
            vdc = VDC(self.client, name=name, resource=vdc_resource)
            result = vdc.enable_vdc(is_enabled)
            res.updated = True
        except Exception as e:
            error_message = '__ERROR_update[Vdc] failed for Vdc {0}. __ErrorMessage__ {1}'.format(
                self.name, str(e))
            logging.warn(error_message)
            context.set_code(grpc.StatusCode.INVALID_ARGUMENT)
            context.set_details(error_message)
            return res

        logging.info("__DONE__update[Vdc]")
        return res
Пример #21
0
    def __create_advanced_gateway(self):
        """Creates a gateway."""

        ext_config = TestIpSecVpn._config['external_network']
        vdc_reource = TestIpSecVpn._vdc_resource
        api_version = TestIpSecVpn._config['vcd']['api_version']
        vdc = VDC(TestIpSecVpn._client, resource=vdc_reource)
        gateway = vdc.get_gateway(TestIpSecVpn._gateway_name)
        if self.__does_exist_gateway(TestIpSecVpn._gateway_name):
            return

        if float(api_version) <= float(
                ApiVersion.VERSION_30.value):
            gateway = vdc.create_gateway_api_version_30(
                TestIpSecVpn._gateway_name, [ext_config['name']])
        elif float(api_version) == float(ApiVersion.VERSION_31.value):
            gateway = vdc.create_gateway_api_version_31(
                TestIpSecVpn._gateway_name,
                [ext_config['name']],
                should_create_as_advanced=True)
        elif float(api_version) >= float(ApiVersion.VERSION_32.value):
            gateway = vdc.create_gateway_api_version_32(
                TestIpSecVpn._gateway_name, [ext_config['name']],
                should_create_as_advanced=True)

        TestIpSecVpn._client.get_task_monitor(). \
            wait_for_success(task=gateway.Tasks.Task[0])
        TestIpSecVpn._gateway_href = gateway.get('href')
        TestIpSecVpn._gateway_obj = Gateway(TestIpSecVpn._client,
                                            href=TestIpSecVpn._gateway_href)
        TestIpSecVpn._gateway_resource = TestIpSecVpn. \
            _gateway_obj.get_resource()
Пример #22
0
 def test_05_share_vdc_access(self):
     logged_in_org = self.client.get_org()
     org = Org(self.client, resource=logged_in_org)
     vdc_resource = org.get_vdc(self.config['vcd']['vdc'])
     vdc = VDC(self.client, resource=vdc_resource)
     control_access = vdc.share_with_org_members()
     assert control_access.IsSharedToEveryone.text == 'true'
     assert control_access.EveryoneAccessLevel.text == 'ReadOnly'
Пример #23
0
 def test_get_vdc(self):
     org_to_use = self.client.get_org_by_name(
         self.config['vcd']['org_to_use'])
     org = Org(self.client, href=org_to_use.get('href'))
     resource = org.get_vdc(self.config['vcd']['new_vdc'])
     assert resource is not None
     vdc = VDC(self.client, resource=resource)
     assert self.config['vcd']['new_vdc'] == vdc.get_resource().get('name')
Пример #24
0
 def test_01_remove_all_vdc_access(self):
     logged_in_org = self.client.get_org()
     org = Org(self.client, resource=logged_in_org)
     vdc_resource = org.get_vdc(self.config['vcd']['vdc'])
     vdc = VDC(self.client, resource=vdc_resource)
     vdc.share_with_org_members()
     control_access = vdc.remove_access_settings(remove_all=True)
     self.assertFalse(hasattr(control_access, 'AccessSettings'))
    def get_vapp_resource(self, vdc_name, vapp_name):
        org_resource = Org(self.client, resource=self.client.get_org())
        vdc_resource = VDC(
            self.client, resource=org_resource.get_vdc(vdc_name))
        vapp_resource_href = vdc_resource.get_resource_href(
            name=vapp_name, entity_type=EntityType.VAPP)

        return self.client.get_resource(vapp_resource_href)
Пример #26
0
    def test_010_get_storage_profiles(self):
        logged_in_org = self.client.get_org()
        org = Org(self.client, resource=logged_in_org)
        vdc_resource = org.get_vdc(self.config['vcd']['vdc'])
        vdc = VDC(self.client, resource=vdc_resource)

        profiles = vdc.get_storage_profiles()

        assert len(profiles) > 0
Пример #27
0
 def test_disable_vdc(self):
     org_to_use = self.client.get_org_by_name(
         self.config['vcd']['org_to_use'])
     org = Org(self.client, href=org_to_use.get('href'))
     resource = org.get_vdc(self.config['vcd']['new_vdc'])
     vdc = VDC(self.client, resource=resource)
     vdc.enable_vdc(False)
     vdc.reload()
     assert vdc.resource.IsEnabled.text == 'false'
Пример #28
0
    def test_050_list_isolated_orgvdc_networks(self):
        org_record = self.client.get_org_by_name(
            self.config['vcd']['org_name'])
        org = Org(self.client, href=org_record.get('href'))
        vdc_resource = org.get_vdc(self.config['vcd']['vdc_name'])
        vdc = VDC(self.client, href=vdc_resource.get('href'))

        result = vdc.list_orgvdc_isolated_networks()
        assert len(result) > 0
Пример #29
0
 def test_1001_remove_all_vapp_access(self):
     logged_in_org = self.client.get_org()
     org = Org(self.client, resource=logged_in_org)
     vdc_resource = org.get_vdc(self.config['vcd']['vdc'])
     vdc = VDC(self.client, resource=vdc_resource)
     vapp_resource = vdc.get_vapp(self.config['vcd']['vapp'])
     vapp = VApp(self.client, resource=vapp_resource)
     control_access = vapp.remove_access_settings(remove_all=True)
     self.assertFalse(hasattr(control_access, 'AccessSettings'))
    def get_resource(self):
        vapp = self.params.get('vapp')
        vdc = self.params.get('vdc')
        org_resource = Org(self.client, resource=self.client.get_org())
        vdc_resource = VDC(self.client, resource=org_resource.get_vdc(vdc))
        vapp_resource_href = vdc_resource.get_resource_href(name=vapp, entity_type=EntityType.VAPP)
        vapp_resource = self.client.get_resource(vapp_resource_href)

        return vapp_resource
Пример #31
0
    def test_020_create_isolated_orgvdc_network(self):
        org_record = self.client.get_org_by_name(
            self.config['vcd']['org_name'])
        org = Org(self.client, href=org_record.get('href'))
        vdc_resource = org.get_vdc(self.config['vcd']['vdc_name'])
        vdc = VDC(self.client, href=vdc_resource.get('href'))

        result = vdc.create_isolated_vdc_network(
            network_name=self.config['vcd']['vdc_isolated_network_name'],
            gateway_ip=self.config['vcd']['isolated_network_gateway_ip'],
            netmask=self.config['vcd']['isolated_network_gateway_netmask'],
            description='Dummy description')
        task = self.client.get_task_monitor().wait_for_success(
            task=result.Tasks.Task[0])
        assert task.get('status') == TaskStatus.SUCCESS.value
def list_disks(client):
    logging.info('INIT create_disk')

    logged_in_org = client.get_org()
    org = Org(client, resource=logged_in_org)
    v = org.get_vdc('OVD2')
    if v is None:
        raise errors.VDCNotFoundError(vappInfo.vdc)
    vdc = VDC(client, href=v.get('href'))
    #disks = vdc.get_disk('disk02')

    #print(etree.tostring(disks, pretty_print=True))
    logging.info(disks.get('href'))

    vdc.delete_disk('disk02')
Пример #33
0
def change_owner(ctx, vapp_name, user_name):
    try:
        restore_session(ctx, vdc_required=True)
        client = ctx.obj['client']
        vdc_href = ctx.obj['profiles'].get('vdc_href')
        vdc = VDC(client, href=vdc_href)
        in_use_org_href = ctx.obj['profiles'].get('org_href')
        org = Org(client, in_use_org_href)
        user_resource = org.get_user(user_name)
        vapp_resource = vdc.get_vapp(vapp_name)
        vapp = VApp(client, resource=vapp_resource)
        vapp.change_owner(user_resource.get('href'))
        stdout('vapp owner changed', ctx)
    except Exception as e:
        stderr(e, ctx)
Пример #34
0
def list_isolated_networks(ctx):
    try:
        restore_session(ctx, vdc_required=True)
        client = ctx.obj['client']
        in_use_vdc_href = ctx.obj['profiles'].get('vdc_href')
        vdc = VDC(client, href=in_use_vdc_href)

        isolated_nets = vdc.list_orgvdc_isolated_networks()

        result = []
        for isolated_net in isolated_nets:
            result.append({'name': isolated_net.get('name')})
        stdout(result, ctx)
    except Exception as e:
        stderr(e, ctx)
Пример #35
0
def list_acl(ctx, vapp_name):
    try:
        restore_session(ctx, vdc_required=True)
        client = ctx.obj['client']
        vdc_href = ctx.obj['profiles'].get('vdc_href')
        vdc = VDC(client, href=vdc_href)
        vapp = VApp(client, resource=vdc.get_vapp(vapp_name))

        acl = vapp.get_access_settings()
        stdout(access_settings_to_list(acl,
                                       ctx.obj['profiles'].get('org_in_use')),
               ctx,
               sort_headers=False)
    except Exception as e:
        stderr(e, ctx)
Пример #36
0
def info(ctx, name):
    try:
        restore_session(ctx, vdc_required=True)
        client = ctx.obj['client']
        vdc_href = ctx.obj['profiles'].get('vdc_href')
        vdc = VDC(client, href=vdc_href)
        vapp_resource = vdc.get_vapp(name)
        vapp = VApp(client, resource=vapp_resource)
        md = vapp.get_metadata()
        access_control_settings = vapp.get_access_settings()
        result = vapp_to_dict(vapp_resource, md,
                              access_settings_to_dict(access_control_settings))
        stdout(result, ctx)
    except Exception as e:
        stderr(e, ctx)
Пример #37
0
def detach(ctx, vapp_name, vm_name, disk_name, disk_id):
    try:
        client = ctx.obj['client']
        vdc_href = ctx.obj['profiles'].get('vdc_href')
        vdc = VDC(client, href=vdc_href)
        disk = vdc.get_disk(disk_name, disk_id)
        vapp_resource = vdc.get_vapp(vapp_name)
        vapp = VApp(client, resource=vapp_resource)
        task = vapp.detach_disk_from_vm(disk_href=disk.get('href'),
                                        disk_type=disk.get('type'),
                                        disk_name=disk_name,
                                        vm_name=vm_name)
        stdout(task, ctx)
    except Exception as e:
        stderr(e, ctx)
Пример #38
0
def delete(ctx, name, vm_names, force):
    try:
        restore_session(ctx, vdc_required=True)
        client = ctx.obj['client']
        vdc_href = ctx.obj['profiles'].get('vdc_href')
        vdc = VDC(client, href=vdc_href)
        if len(vm_names) == 0:
            task = vdc.delete_vapp(name, force)
        else:
            vapp_resource = vdc.get_vapp(name)
            vapp = VApp(client, resource=vapp_resource)
            task = vapp.delete_vms(vm_names)
        stdout(task, ctx)
    except Exception as e:
        stderr(e, ctx)
Пример #39
0
    def add_network(self):
        network_name = self.params.get('network')
        fence_mode = self.params.get('fence_mode')
        parent_network = self.params.get('parent_network')
        ip_scope = self.params.get('ip_scope')

        response = dict()
        response['changed'] = False

        try:
            self.get_network()
        except EntityNotFoundException:
            network_config_section = self.vapp.resource.NetworkConfigSection
            config = E.Configuration()
            if parent_network:
                vdc = self.params.get('vdc')
                org_resource = Org(self.client, resource=self.client.get_org())
                vdc_resource = VDC(self.client, resource=org_resource.get_vdc(vdc))
                orgvdc_networks = vdc_resource.list_orgvdc_network_resources(parent_network)
                parent = next((network for network in orgvdc_networks if network.get('name') == parent_network), None)
                if parent:
                    config.append(E.ParentNetwork(href=parent.get('href')))
                else:
                    raise EntityNotFoundException('Parent network \'%s\' does not exist'.format(parent_network))
            elif ip_scope:
                scope = E.IpScope(
                    E.IsInherited('false'),
                    E.Gateway(str(ip_network(ip_scope, strict=False).network_address+1)),
                    E.Netmask(str(ip_network(ip_scope, strict=False).netmask)))
                config.append(E.IpScopes(scope))
            else:
                raise VappNetworkCreateError('Either parent_network or ip_scope must be set')
            config.append(E.FenceMode(fence_mode))

            network_config = E.NetworkConfig(config, networkName=network_name)
            network_config_section.append(network_config)

            add_network_task = self.client.put_linked_resource(
                self.vapp.resource.NetworkConfigSection, RelationType.EDIT,
                EntityType.NETWORK_CONFIG_SECTION.value,
                network_config_section)
            self.execute_task(add_network_task)
            response['msg'] = 'Vapp Network {} has been added'.format(network_name)
            response['changed'] = True
        else:
            response['warnings'] = 'Vapp Network {} is already present.'.format(network_name)

        return response
Пример #40
0
    def power_on(self, request):
        logging.info("__INIT__power_on[VappVm]")
        res = vapp_vm_pb2.PowerOnVappVmResult()
        res.powered_on = False

        org_resource = self.client.get_org()
        org = Org(self.client, resource=org_resource)
        try:
            vdc_resource = org.get_vdc(request.target_vdc)
            vdc = VDC(self.client, name=request.target_vdc,
                      resource=vdc_resource)

            vapp_resource = vdc.get_vapp(request.target_vapp)
            vapp = VApp(self.client, name=request.target_vapp,
                        resource=vapp_resource)
            vapp_vm_resource = vapp.get_vm(request.target_vm_name)
            vm = VM(self.client, resource=vapp_vm_resource)
            power_on_response = vm.power_on()

            task = self.client.get_task_monitor().wait_for_status(
                task=power_on_response,
                timeout=60,
                poll_frequency=2,
                fail_on_statuses=None,
                expected_target_statuses=[
                    TaskStatus.SUCCESS, TaskStatus.ABORTED, TaskStatus.ERROR,
                    TaskStatus.CANCELED
                ],
                callback=None)

            st = task.get('status')
            if st != TaskStatus.SUCCESS.value:
                raise errors.VappVmPowerOnError(
                    etree.tostring(task, pretty_print=True))

            message = 'status : {0} '.format(st)
            logging.info(message)
            res.powered_on = True

        except Exception as e:
            errmsg = '__ERROR_power_off[VappVm] failed for VappVm {0}. __ErrorMessage__ {1}'
            logging.warn(errmsg.format(request.target_vm_name, str(e)))
            self.context.set_code(grpc.StatusCode.INVALID_ARGUMENT)
            self.context.set_details(errmsg)

        logging.info("__DONE__power_on[VappVm]")

        return res
    def delete(self):
        logging.info("__INIT__delete[Vdc]")
        res = vdc_pb2.DeleteVdcResult()
        res.deleted = False

        context = self.context
        logged_in_org = self.client.get_org()
        org = Org(self.client, resource=logged_in_org)

        #Vdc details
        name = self.name

        try:
            vdc_resource = org.get_vdc(name)
            vdc = VDC(self.client, name=name, resource=vdc_resource)
            delete_vdc_resp = vdc.delete_vdc()

            task = self.client.get_task_monitor().wait_for_status(
                task=delete_vdc_resp,
                timeout=60,
                poll_frequency=2,
                fail_on_statuses=None,
                expected_target_statuses=[
                    TaskStatus.SUCCESS, TaskStatus.ABORTED, TaskStatus.ERROR,
                    TaskStatus.CANCELED
                ],
                callback=None)

            st = task.get('status')
            if st == TaskStatus.SUCCESS.value:
                message = 'delete vdc status : {0} '.format(st)
                logging.info(message)
            else:
                raise errors.VCDVdcDeleteError(
                    etree.tostring(task, pretty_print=True))

            res.deleted = True
        except Exception as e:
            res.deleted = False
            error_message = '__ERROR_delete[Vdc] failed for Vdc {0}. __ErrorMessage__ {1}'.format(
                self.name, str(e))
            logging.warn(error_message)
            context.set_code(grpc.StatusCode.INVALID_ARGUMENT)
            context.set_details(error_message)
            return res

        logging.info("__DONE__delete[Vdc]")
        return res
Пример #42
0
    def test_008_get_disks(self):

        logged_in_org = self.client.get_org()
       
        org = Org(self.client, resource=logged_in_org)
        v = org.get_vdc(self.config['vcd']['vdc'])
        vdc = VDC(self.client, href=v.get('href'))
        
        disks = vdc.get_disks()
        
        for disk in disks:
            print (" Disk: " + str(etree.tostring(disk, pretty_print=True), "utf-8"))

        assert len(disks) > 0 

        assert disks[0].get('name') == self.config['vcd']['disk']
Пример #43
0
def list_acl(ctx, vdc_name):
    try:
        restore_session(ctx)
        client = ctx.obj['client']
        in_use_org_href = ctx.obj['profiles'].get('org_href')
        org = Org(client, in_use_org_href)
        vdc_resource = org.get_vdc(vdc_name)
        vdc = VDC(client, resource=vdc_resource)

        acl = vdc.get_access_settings()
        stdout(
            access_settings_to_list(acl,
                                    ctx.obj['profiles'].get('org_in_use')),
            ctx)
    except Exception as e:
        stderr(e, ctx)
 def create_nodes_thread(self):
     LOGGER.debug('about to add nodes to cluster with name: %s',
                  self.cluster_name)
     try:
         org_resource = self.client_tenant.get_org()
         org = Org(self.client_tenant, resource=org_resource)
         vdc = VDC(self.client_tenant, href=self.cluster['vdc_href'])
         vapp = VApp(self.client_tenant, href=self.cluster['vapp_href'])
         template = self.get_template()
         self.update_task(
             TaskStatus.RUNNING,
             message='Creating %s node(s) for %s(%s)' %
             (self.body['node_count'], self.cluster_name, self.cluster_id))
         new_nodes = add_nodes(self.body['node_count'], template, TYPE_NODE,
                               self.config, self.client_tenant, org, vdc,
                               vapp, self.body)
         self.update_task(
             TaskStatus.RUNNING,
             message='Adding %s node(s) to %s(%s)' %
             (self.body['node_count'], self.cluster_name, self.cluster_id))
         target_nodes = []
         for spec in new_nodes['specs']:
             target_nodes.append(spec['target_vm_name'])
         vapp.reload()
         join_cluster(self.config, vapp, template, target_nodes)
         self.update_task(
             TaskStatus.SUCCESS,
             message='Added %s node(s) to cluster %s(%s)' %
             (self.body['node_count'], self.cluster_name, self.cluster_id))
     except Exception as e:
         LOGGER.error(traceback.format_exc())
         self.update_task(TaskStatus.ERROR, error_message=str(e))
Пример #45
0
def create_direct_network(ctx, name, parent_network_name, description,
                          is_shared):
    try:
        client = ctx.obj['client']
        in_use_vdc_href = ctx.obj['profiles'].get('vdc_href')
        vdc = VDC(client, href=in_use_vdc_href)

        result = vdc.create_directly_connected_vdc_network(
            network_name=name,
            parent_network_name=parent_network_name,
            description=description,
            is_shared=is_shared)

        stdout(result.Tasks.Task[0], ctx)
    except Exception as e:
        stderr(e, ctx)
Пример #46
0
    def get_target_resource(self):
        target_vdc = self.params.get('target_vdc')
        org_resource = Org(self.client, resource=self.client.get_org())

        vdc = VDC(self.client, resource=org_resource.get_vdc(target_vdc))

        return vdc
Пример #47
0
def bootstrap_li(ctx, vapp_name):
    """Given a VAPP containing a LI VM, identify the public IP and boostrap a standalone (1-node) cluster."""
    try:
        client = ctx.obj['client']
        vdc_href = ctx.obj['profiles'].get('vdc_href')
        vdc = VDC(client, vdc_href=vdc_href)

        internal_ip = get_ip(vdc, client, vapp_name)

        external_ip = mapping(internal_ip)

        import requests

        logging.info("Boostrapping")
        response = requests.post('https://%s/api/v1/deployment/new' % external_ip, verify=False, json={
            "user": {
                "userName": "******",
                "password": "******",
                "email": "admin-integration-test@localhost"
            }
        })

        logging.info("Waiting for bootstrap to finish and service to start")
        requests.post('https://%s/api/v1/deployment/waitUntilStarted' % external_ip, verify=False, json={})

        result = {
            'status': response.status_code,
            'text': response.text
        }

        stdout(result, ctx)
    except Exception as e:
        stderr(e, ctx)
def get_vdc(client,
            vdc_name,
            org=None,
            org_name=None,
            is_admin_operation=False):
    """Get the specified VDC object.

    :param pyvcloud.vcd.client.Client client:
    :param str vdc_name:
    :param pyvcloud.vcd.org.Org org: specific org to use.
    :param str org_name: specific org to use if @org is not given.
        If None, uses currently logged-in org from @client.
    :param bool is_admin_operation: if set True, will return the admin
            view of the org vdc resource.

    :return: pyvcloud VDC object

    :rtype: pyvcloud.vcd.vdc.VDC

    :raises EntityNotFoundException: if the vdc could not be found.
    """
    if org is None:
        org = get_org(client, org_name=org_name)
    resource = org.get_vdc(vdc_name, is_admin_operation=is_admin_operation)
    # TODO() org.get_vdc() should throw exception if vdc not found in the org.
    # This should be handled in pyvcloud. For now, it is handled here.
    if resource is None:
        raise EntityNotFoundException(f"VDC '{vdc_name}' not found")
    vdc = VDC(client, resource=resource)
    return vdc
Пример #49
0
def create_vapp_network(ctx, vapp_name, name, subnet, description,
                        primary_dns_ip, secondary_dns_ip, dns_suffix,
                        ip_ranges, is_guest_vlan_allowed):
    try:
        restore_session(ctx, vdc_required=True)
        client = ctx.obj['client']
        vdc_href = ctx.obj['profiles'].get('vdc_href')
        vdc = VDC(client, href=vdc_href)
        vapp_resource = vdc.get_vapp(vapp_name)
        vapp = VApp(client, resource=vapp_resource)
        task = vapp.create_vapp_network(
            name, subnet, description, primary_dns_ip, secondary_dns_ip,
            dns_suffix, ip_ranges, is_guest_vlan_allowed)
        stdout(task, ctx)
    except Exception as e:
        stderr(e, ctx)
Пример #50
0
def update(ctx, name, size, description, new_name, storage_profile, iops,
           disk_id):
    try:
        client = ctx.obj['client']
        vdc_href = ctx.obj['profiles'].get('vdc_href')
        vdc = VDC(client, href=vdc_href)
        task = vdc.update_disk(name,
                               size=humanfriendly.parse_size(size),
                               new_name=new_name,
                               description=description,
                               storage_profile_name=storage_profile,
                               iops=iops,
                               disk_id=disk_id)
        stdout(task, ctx)
    except Exception as e:
        stderr(e, ctx)
Пример #51
0
def capture(ctx, name, catalog, template, customizable):
    try:
        client = ctx.obj['client']
        org_name = ctx.obj['profiles'].get('org')
        in_use_org_href = ctx.obj['profiles'].get('org_href')
        org = Org(client, in_use_org_href, org_name == 'System')
        vdc_href = ctx.obj['profiles'].get('vdc_href')
        vdc = VDC(client, href=vdc_href)
        print(org.href)
        print(vdc.href)
        # vapp_resource = vdc.instantiate_vapp(
        #     name,
        #     catalog,
        #     template,
        #     network=network,
        #     memory=memory,
        #     cpu=cpu,
        #     deploy=False,
        #     power_on=False)
        # stdout(vapp_resource.Tasks.Task[0], ctx)
        # vapp = VApp(client, vapp_href=vapp_resource.get('href'))
        # t = vapp.connect_vm(mode=connection_mode)
        # stdout(t, ctx)
        # t = vapp.power_on()
        # stdout(t, ctx)
    except Exception as e:
        stderr(e, ctx)
Пример #52
0
def get_vdc(client,
            vdc_name,
            org=None,
            org_name=None,
            is_admin_operation=False):
    """Get the specified VDC object.

    :param pyvcloud.vcd.client.Client client:
    :param str vdc_name:
    :param pyvcloud.vcd.org.Org org: specific org to use.
    :param str org_name: specific org to use if @org is not given.
        If None, uses currently logged-in org from @client.
    :param bool is_admin_operation: if set True, will return the admin
            view of the org vdc resource.

    :return: pyvcloud VDC object

    :rtype: pyvcloud.vcd.vdc.VDC

    :raises EntityNotFoundException: if the vdc could not be found.
    """
    if org is None:
        org = get_org(client, org_name=org_name)
    vdc = VDC(client,
              resource=org.get_vdc(vdc_name,
                                   is_admin_operation=is_admin_operation))
    return vdc
Пример #53
0
    def test_050_change_idisk_owner(self):
        logged_in_org = self.client.get_org()
        org = Org(self.client, resource=logged_in_org)
        vdc_resource = org.get_vdc(self.config['vcd']['vdc'])
        vdc = VDC(self.client, resource=vdc_resource)

        user_resource = org.get_user(
            self.config['vcd']['idisk_new_owner_name'])

        vdc.change_disk_owner(name=self.config['vcd']['idisk_name'],
                              user_href=user_resource.get('href'))

        disk_resource = vdc.get_disk(self.config['vcd']['idisk_name'])
        new_user = disk_resource.Owner.User.get('name')

        assert self.config['vcd']['idisk_new_owner_name'] == new_user
Пример #54
0
    def get_test_vdc(cls, client):
        """Gets the vdc for testing

        :return: A :class: pyvcloud.vcd.vdc.VDC object representing the
            vdc that is backing the org in which all tests will run.
        """
        return VDC(client, href=cls._ovdc_href)
    def get_vdc_object(self, vdc_name):
        client = self.module.client
        logged_in_org = client.get_org()
        org = Org(client, resource=logged_in_org)
        vdc_resource = org.get_vdc(vdc_name)

        return VDC(client, href=vdc_resource.get('href'))
Пример #56
0
def get_vdc(client, vdc_id=None, vdc_name=None, org=None, org_name=None,
            is_admin_operation=False):
    """Get the specified VDC object.

    Atleast one of vdc_id or vdc_name must be specified. If org or org_name
    both are not specified, the currently logged in user's org will be used to
    look for the vdc.

    :param pyvcloud.vcd.client.Client client:
    :param str vdc_id: id of the vdc
    :param str vdc_name: name of the vdc
    :param pyvcloud.vcd.org.Org org: specific org to use.
    :param str org_name: specific org to use if @org is not given.
        If None, uses currently logged-in org from @client.
    :param bool is_admin_operation: if set True, will return the admin
            view of the org vdc resource.

    :return: pyvcloud VDC object

    :rtype: pyvcloud.vcd.vdc.VDC

    :raises EntityNotFoundException: if the vdc could not be found.
    """
    if vdc_id:
        base_url = client.get_api_uri()
        # add a trailing slash if missing
        if base_url[-1] != '/':
            base_url += '/'
        if is_admin_operation:
            base_url = get_admin_href(base_url)
        vdc_href = f'{base_url}vdc/{vdc_id}'
        vdc = VDC(client, href=vdc_href)
        vdc.reload()
        return vdc

    resource = None
    if vdc_name:
        if not org:
            org = get_org(client, org_name=org_name)
        resource = org.get_vdc(vdc_name, is_admin_operation=is_admin_operation)

    # TODO() org.get_vdc() should throw exception if vdc not found in the org.
    # This should be handled in pyvcloud. For now, it is handled here.
    if resource is None:
        raise EntityNotFoundException(f"VDC '{vdc_name}' not found in ORG "
                                      f"'{org.get_name()}'")
    return VDC(client, resource=resource)
Пример #57
0
 def test_1002_add_vapp_access(self):
     logged_in_org = self.client.get_org()
     org = Org(self.client, resource=logged_in_org)
     vdc_resource = org.get_vdc(self.config['vcd']['vdc'])
     vdc = VDC(self.client, resource=vdc_resource)
     vapp_resource = vdc.get_vapp(self.config['vcd']['vapp'])
     vapp = VApp(self.client, resource=vapp_resource)
     control_access = vapp.add_access_settings(
         access_settings_list=[{
             'name': self.config['vcd']['access_user'],
             'type': 'user'
         }, {
             'name': self.config['vcd']['access_user1'],
             'type': 'user',
             'access_level': 'Change'
         }])
     assert len(control_access.AccessSettings.AccessSetting) == 2
Пример #58
0
def attach(ctx, vapp_name, vm_name, disk_name):
    try:
        client = ctx.obj['client']
        vdc_href = ctx.obj['profiles'].get('vdc_href')
        vdc = VDC(client, href=vdc_href)

        disk_name, disk_id = extract_name_and_id(disk_name)
        disk = vdc.get_disk(name=disk_name, disk_id=disk_id)

        vapp_resource = vdc.get_vapp(vapp_name)
        vapp = VApp(client, resource=vapp_resource)

        task = vapp.attach_disk_to_vm(
            disk_href=disk.get('href'), vm_name=vm_name)
        stdout(task, ctx)
    except Exception as e:
        stderr(e, ctx)
Пример #59
0
    def __init__(self, **kwargs):
        super(EdgeInCatalogWhole, self).__init__(**kwargs)
        self.host = self.params.get('host')
        self.host = self.params.get('host')

        self.user = self.params.get('user')
        self.password = self.params.get('password')
        self.api_version = self.params.get('api_version')
        self.vdc_name = self.params.get('vdc_name')
        self.org_name = self.params.get('org_name')
        self.edge_name = self.params.get('edge_name')
        logged_in_org = self.client.get_org_by_name(self.org_name)
        self.org = Org(self.client, resource=logged_in_org)
        #org_resource = self.client.get_org_by_name(self.org_name)
        #self.org = Org(self.client, resource=org_resource)
        vdc_resource = self.org.get_vdc(self.vdc_name)
        self.vdc = VDC(self.client, name=self.vdc_name, resource=vdc_resource)
Пример #60
0
def reset(ctx, name, vm_names):
    try:
        client = ctx.obj['client']
        vdc_href = ctx.obj['profiles'].get('vdc_href')
        vdc = VDC(client, href=vdc_href)
        vapp_resource = vdc.get_vapp(name)
        vapp = VApp(client, resource=vapp_resource)
        if len(vm_names) == 0:
            task = vapp.power_reset()
            stdout(task, ctx)
        else:
            for vm_name in vm_names:
                vm = VM(client, resource=vapp.get_vm(vm_name))
                task = vm.power_reset()
                stdout(task, ctx)
    except Exception as e:
        stderr(e, ctx)