How to use the pyvcloud.vcd.vm.VM function in pyvcloud

To help you get started, we’ve selected a few pyvcloud examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vmware / pyvcloud / system_tests / vm_tests.py View on Github external
def test_0310_get_post_gc_status(self):
        vm = VM(TestVM._sys_admin_client,
                href=TestVM._test_vapp_vmtools_vm_href)
        dict = vm.list_check_post_gc_status()
        self.assertTrue(len(dict) > 0)
github vmware / pyvcloud / tests / vcd_vm.py View on Github external
def test_1007_snapshot_revert_to_current(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.snapshot_revert_to_current()
        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
github vmware / pyvcloud / tests / vcd_vm.py View on Github external
def test_0001_modify_cpu(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_cpu(self.config['vcd']['cpu'],
                             self.config['vcd']['cores_per_socket'])
        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()
        cpus = vm.get_cpus()
github vmware / pyvcloud / system_tests / vm_tests.py View on Github external
def test_0290_list_gc_info(self):
        vm = VM(TestVM._sys_admin_client,
                href=TestVM._test_vapp_vmtools_vm_href)
        dict = vm.list_gc_section()
        self.assertTrue(len(dict) > 0)
github vmware / pyvcloud / system_tests / vm_tests.py View on Github external
def test_0100_upgrade_virtual_hardware(self):
        vm = VM(TestVM._client, href=TestVM._test_vapp_first_vm_href)
        task = vm.upgrade_virtual_hardware()
        result = TestVM._client.get_task_monitor().wait_for_success(
            task=task)
        self.assertEqual(result.get('status'), TaskStatus.SUCCESS.value)
github vmware / ansible-module-vcloud-director / modules / vcd_vapp_vm_disk.py View on Github external
def get_vm(self):
        vapp_vm_resource = self.vapp.get_vm(self.params.get('vm_name'))

        return VM(self.client, resource=vapp_vm_resource)
github vmware / vcd-cli / vcd_cli / vapp.py View on Github external
def shutdown(ctx, name, vm_names):
    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)
        if len(vm_names) == 0:
            task = vapp.shutdown()
            stdout(task, ctx)
        else:
            for vm_name in vm_names:
                vm = VM(client, href=vapp.get_vm(vm_name).get('href'))
                vm.reload()
                task = vm.shutdown()
                stdout(task, ctx)
    except Exception as e:
        stderr(e, ctx)
github vmware / container-service-extension / container_service_extension / cluster.py View on Github external
if storage_profile is not None:
                spec['storage_profile'] = storage_profile
            specs.append(spec)

        task = vapp.add_vms(specs, power_on=False)
        client.get_task_monitor().wait_for_status(task)
        vapp.reload()

        if not num_cpu:
            num_cpu = template[LocalTemplateKey.CPU]
        if not memory_in_mb:
            memory_in_mb = template[LocalTemplateKey.MEMORY]
        for spec in specs:
            vm_name = spec['target_vm_name']
            vm_resource = vapp.get_vm(vm_name)
            vm = VM(client, resource=vm_resource)

            task = vm.modify_cpu(num_cpu)
            client.get_task_monitor().wait_for_status(task)

            task = vm.modify_memory(memory_in_mb)
            client.get_task_monitor().wait_for_status(task)

            task = vm.power_on()
            client.get_task_monitor().wait_for_status(task)
            vapp.reload()

            if node_type == NodeType.NFS:
                LOGGER.debug(f"Enabling NFS server on {vm_name}")
                script_filepath = get_local_script_filepath(
                    template[LocalTemplateKey.NAME],
                    template[LocalTemplateKey.REVISION],
github vmware / container-service-extension / container_service_extension / configure_cse.py View on Github external
skip_vm = False
            if admin_password_enabled:
                if new_admin_password:
                    if new_admin_password == admin_password_on_vm:
                        skip_vm = True
                else:
                    if admin_password_on_vm:
                        skip_vm = True
            if not skip_vm:
                href_of_vms_to_verify.append(vm.href)
                vm_hrefs_for_password_update.append(vm.href)

        # At least one vm in the vApp needs a password update
        if len(vm_hrefs_for_password_update) > 0:
            for href in vm_hrefs_for_password_update:
                vm = VM(client=client, href=href)
                try:
                    msg = "Undeploying vm."
                    INSTALL_LOGGER.info(msg)
                    msg_update_callback.info(msg)
                    task = vm.undeploy()
                    client.get_task_monitor().wait_for_success(task)
                    msg = "Successfully undeployed vm"
                    INSTALL_LOGGER.info(msg)
                    msg_update_callback.general(msg)
                except Exception as err:
                    INSTALL_LOGGER.debug(str(err))
                    msg_update_callback.info(str(err))

                msg = f"Processing vm '{vm.get_resource().get('name')}'." \
                      "\nUpdating vm admin password"
                INSTALL_LOGGER.info(msg)
github vmware / container-service-extension / container_service_extension / configure_cse.py View on Github external
INSTALL_LOGGER.info(msg)
        msg_update_callback.info(msg)
        return

    href_of_vms_to_verify = []
    for cluster in cse_clusters:
        msg = f"Processing admin password of cluster '{cluster['name']}'."
        INSTALL_LOGGER.info(msg)
        msg_update_callback.info(msg)

        vm_hrefs_for_password_update = []
        vapp_href = cluster['vapp_href']
        vapp = VApp(client, href=vapp_href)
        vm_resources = vapp.get_all_vms()
        for vm_resource in vm_resources:
            vm = VM(client, href=vm_resource.get('href'))
            msg = f"Determining if vm '{vm.get_resource().get('name')}' " \
                  "needs processing'."
            INSTALL_LOGGER.info(msg)
            msg_update_callback.info(msg)

            gc_section = vm.get_guest_customization_section()
            admin_password_enabled = False
            if hasattr(gc_section, 'AdminPasswordEnabled'):
                admin_password_enabled = utils.str_to_bool(gc_section.AdminPasswordEnabled) # noqa: E501
            admin_password_on_vm = None
            if hasattr(gc_section, 'AdminPassword'):
                admin_password_on_vm = gc_section.AdminPassword.text

            skip_vm = False
            if admin_password_enabled:
                if new_admin_password: