当前位置: 首页>>代码示例>>Python>>正文


Python vim_client.VimClient类代码示例

本文整理汇总了Python中host.hypervisor.esx.vim_client.VimClient的典型用法代码示例。如果您正苦于以下问题:Python VimClient类的具体用法?Python VimClient怎么用?Python VimClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了VimClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_update_fail_without_looping

 def test_update_fail_without_looping(self, connect_mock, update_mock):
     client = VimClient("esx.local", "root", "password", auto_sync=True,
                        min_interval=1)
     update_mock.side_effect = vim.fault.HostConnectFault
     time.sleep(0.5)
     client.disconnect(wait=True)
     assert_that(update_mock.call_count, less_than(4))  # no crazy loop
开发者ID:tomzhang,项目名称:photon-controller,代码行数:7,代码来源:test_vim_client.py

示例2: test_update_host_cache_in_thread

    def test_update_host_cache_in_thread(self, disconnect_mock, connect_mock, spec_mock,
                                         update_mock, prop_collector_mock):
        vm = vim.VirtualMachine("moid", None)
        vm.kind = "enter"
        vm.changeSet = {}
        update = MagicMock()
        update.filterSet = [MagicMock()]
        update.filterSet[0].objectSet = [MagicMock()]
        update.filterSet[0].objectSet[0] = vm

        # Mock the Vim APIs.
        prop_collector_mock.WaitForUpdatesEx = MagicMock()
        prop_collector_mock.WaitForUpdatesEx.return_value = update

        # Create VimClient.
        vim_client = VimClient(min_interval=0.1, auto_sync=True)
        vim_client.connect_userpwd("esx.local", "root", "password")

        # Verify that the update mock is called a few times.
        retry = 0
        while update_mock.call_count < 5 and retry < 10:
            time.sleep(0.2)
            retry += 1
        assert_that(retry, is_not(10), "VimClient.update_mock is not called repeatedly")

        # Disconnect the client and stop the thread.
        vim_client.disconnect()
        assert_that(disconnect_mock.called, is_(True))

        assert_that(update_mock.call_count, is_not(0), "VimClient.update_mock is not called")
开发者ID:cartlhd,项目名称:photon-controller,代码行数:30,代码来源:test_vim_client.py

示例3: test_check_prefix_len_to_netmask_conversion

 def test_check_prefix_len_to_netmask_conversion(self):
     """Check the conversion from prefix length to netmask"""
     self.assertEqual(VimClient._prefix_len_to_mask(32), "255.255.255.255")
     self.assertEqual(VimClient._prefix_len_to_mask(0), "0.0.0.0")
     self.assertRaises(ValueError,
                       VimClient._prefix_len_to_mask, 33)
     self.assertEqual(VimClient._prefix_len_to_mask(23), "255.255.254.0")
     self.assertEqual(VimClient._prefix_len_to_mask(6), "252.0.0.0")
     self.assertEqual(VimClient._prefix_len_to_mask(32), "255.255.255.255")
开发者ID:cartlhd,项目名称:photon-controller,代码行数:9,代码来源:test_vm_manager.py

示例4: test_update_host_cache_in_thread

    def test_update_host_cache_in_thread(self, disconnect_mock, connect_mock,
                                         spec_mock, update_mock,
                                         update_host_mock, query_spec_mock,
                                         perf_manager_mock,
                                         prop_collector_mock):

        # Test Values.
        counter = MagicMock()
        counter.groupInfo.key = "mem"
        counter.nameInfo.key = "consumed"
        counter.key = 65613

        n = 5
        statValues = ','.join([str(x) for x in range(1, n+1)])
        statAverage = sum(range(1, n+1)) / len(range(1, n+1))
        stat = MagicMock()
        stat.value = [MagicMock()]
        stat.value[0].id.counterId = 65613
        stat.value[0].value = statValues

        # Mock the Vim APIs.
        pc_return_mock = MagicMock({'WaitForUpdatesEx.return_value': {}})
        summarize_stats = {'QueryPerf.return_value': [stat]}
        pm_return_mock = MagicMock(perfCounter=[counter], **summarize_stats)

        # Tie the mocked APIs with VimClient.
        prop_collector_mock.return_value = pc_return_mock
        perf_manager_mock.return_value = pm_return_mock

        # Create VimClient.
        vim_client = VimClient("esx.local", "root", "password",
                               min_interval=0.1, auto_sync=True,
                               stats_interval=0.2)

        # Verify that the update mock is called a few times.
        retry = 0
        while update_mock.call_count < 5 and retry < 10:
            time.sleep(0.2)
            retry += 1
        assert_that(retry, is_not(10), "VimClient.update_mock is not "
                                       "called repeatedly")

        # Disconnect the client and stop the thread.
        vim_client.disconnect(wait=True)
        assert_that(disconnect_mock.called, is_(True))

        # Verify that update_host_mock is called atleast once and is called
        # less number of times than update_mock.
        assert_that(update_host_mock.call_count, is_not(0),
                    "VimClient.update_host_mock is not called repeatedly")
        assert_that(update_host_mock.call_count,
                    less_than(update_mock.call_count))

        host_stats = update_host_mock.call_args_list
        for host in host_stats:
            assert_that(host[0][0]['mem.consumed'], equal_to(statAverage))
开发者ID:tomzhang,项目名称:photon-controller,代码行数:56,代码来源:test_vim_client.py

示例5: test_poll_update_in_thread

    def test_poll_update_in_thread(self, disconnect_mock, connect_mock, spec_mock, update_mock):
        vim_client = VimClient(min_interval=0, auto_sync=True)
        vim_client.connect_userpwd("esx.local", "root", "password")
        vim_client._property_collector.WaitForUpdatesEx.return_value = {}

        assert_that(update_mock.called, is_(True))
        retry = 0
        while update_mock.call_count < 5 and retry < 10:
            time.sleep(0.2)
            retry += 1
        assert_that(retry, is_not(10), "VimClient._poll_updates is not called repeatedly")
        vim_client.disconnect()
        assert_that(disconnect_mock.called, is_(True))
开发者ID:cartlhd,项目名称:photon-controller,代码行数:13,代码来源:test_vim_client.py

示例6: __init__

    def __init__(self, agent_config):
        self.logger = logging.getLogger(__name__)

        # If VimClient's housekeeping thread failed to update its own cache,
        # call errback to commit suicide. Watchdog will bring up the agent
        # again.
        errback = lambda: suicide()
        self.vim_client = VimClient(wait_timeout=agent_config.wait_timeout,
                                    errback=errback)
        atexit.register(lambda client: client.disconnect(), self.vim_client)

        self._uuid = self.vim_client.host_uuid
        self.set_memory_overcommit(agent_config.memory_overcommit)

        image_datastores = [ds["name"] for ds in agent_config.image_datastores]
        self.datastore_manager = EsxDatastoreManager(
            self, agent_config.datastores, agent_config.image_datastores)
        # datastore manager needs to update the cache when there is a change.
        self.vim_client.add_update_listener(self.datastore_manager)
        self.vm_manager = EsxVmManager(self.vim_client, self.datastore_manager)
        self.disk_manager = EsxDiskManager(self.vim_client,
                                           self.datastore_manager)
        self.image_manager = EsxImageManager(self.vim_client,
                                             self.datastore_manager)
        self.network_manager = EsxNetworkManager(self.vim_client,
                                                 agent_config.networks)
        self.system = EsxSystem(self.vim_client)
        self.image_manager.monitor_for_cleanup()
        self.image_transferer = HttpNfcTransferer(self.vim_client,
                                                  image_datastores)
        atexit.register(self.image_manager.cleanup)
开发者ID:fakber,项目名称:photon-controller,代码行数:31,代码来源:hypervisor.py

示例7: setUp

 def setUp(self, connect, update, creds):
     creds.return_value = ["username", "password"]
     self.vim_client = VimClient(auto_sync=False)
     self.vim_client.wait_for_task = MagicMock()
     self.patcher = patch("host.hypervisor.esx.vm_config.GetEnv")
     self.patcher.start()
     self.vm_manager = EsxVmManager(self.vim_client, MagicMock())
开发者ID:aju0987,项目名称:photon-controller,代码行数:7,代码来源:test_esx_vm_manager.py

示例8: setUp

 def setUp(self, connect, update, creds):
     creds.return_value = ["username", "password"]
     self.vim_client = VimClient(auto_sync=False)
     self.vim_client.wait_for_task = MagicMock()
     self.disk_manager = EsxDiskManager(self.vim_client, [])
     self.disk_manager._vmdk_mkdir = MagicMock()
     self.disk_manager._vmdk_rmdir = MagicMock()
开发者ID:aasthabh,项目名称:photon-controller,代码行数:7,代码来源:test_esx_disk_manager.py

示例9: setUp

    def setUp(self):
        if "host_remote_test" not in config:
            raise SkipTest()

        self.host = config["host_remote_test"]["server"]
        self.pwd = config["host_remote_test"]["esx_pwd"]
        self.agent_port = config["host_remote_test"].get("agent_port", 8835)
        if self.host is None or self.pwd is None:
            raise SkipTest()

        self.image_datastore = config["host_remote_test"].get(
            "image_datastore", "datastore1")

        self._logger = logging.getLogger(__name__)
        self.vim_client = VimClient(self.host, "root", self.pwd)
        self.http_transferer = HttpNfcTransferer(self.vim_client,
                                                 [self.image_datastore],
                                                 self.host)

        with tempfile.NamedTemporaryFile(delete=False) as source_file:
            with open(source_file.name, 'wb') as f:
                f.write(os.urandom(1024 * 100))
        self.random_file = source_file.name

        self.remote_files_to_delete = []
开发者ID:thulasi39,项目名称:photon-controller,代码行数:25,代码来源:test_http_transfer.py

示例10: __init__

    def __init__(self, agent_config):
        self.logger = logging.getLogger(__name__)

        # If VimClient's housekeeping thread failed to update its own cache,
        # call errback to commit suicide. Watchdog will bring up the agent
        # again.
        errback = lambda: suicide()
        self.vim_client = VimClient(wait_timeout=agent_config.wait_timeout,
                                    errback=errback)
        atexit.register(lambda client: client.disconnect(), self.vim_client)

        self._uuid = self.vim_client.host_uuid

        # Enable/Disable large page support. If this host is removed
        # from the deployment, large page support will need to be
        # explicitly updated by the user.
        disable_large_pages = agent_config.memory_overcommit > 1.0
        self.vim_client.set_large_page_support(disable=disable_large_pages)

        image_datastores = [ds["name"] for ds in agent_config.image_datastores]
        self.datastore_manager = EsxDatastoreManager(
            self, agent_config.datastores, image_datastores)
        # datastore manager needs to update the cache when there is a change.
        self.vim_client.add_update_listener(self.datastore_manager)
        self.vm_manager = EsxVmManager(self.vim_client, self.datastore_manager)
        self.disk_manager = EsxDiskManager(self.vim_client,
                                           self.datastore_manager)
        self.image_manager = EsxImageManager(self.vim_client,
                                             self.datastore_manager)
        self.network_manager = EsxNetworkManager(self.vim_client,
                                                 agent_config.networks)
        self.system = EsxSystem(self.vim_client)
        self.image_manager.monitor_for_cleanup()
        atexit.register(self.image_manager.cleanup)
开发者ID:pankaj-lakhina,项目名称:photon-controller,代码行数:34,代码来源:hypervisor.py

示例11: TestEsxDiskManager

class TestEsxDiskManager(unittest.TestCase):

    @patch.object(VimClient, "acquire_credentials")
    @patch.object(VimClient, "update_cache")
    @patch("pysdk.connect.Connect")
    def setUp(self, connect, update, creds):
        creds.return_value = ["username", "password"]
        self.vim_client = VimClient(auto_sync=False)
        self.vim_client.wait_for_task = MagicMock()
        self.disk_manager = EsxDiskManager(self.vim_client, [])
        self.disk_manager._vmdk_mkdir = MagicMock()
        self.disk_manager._vmdk_rmdir = MagicMock()

    def tearDown(self):
        self.vim_client.disconnect(wait=True)

    def test_create_spec(self):
        """Test that we create a valid disk spec."""

        capacity = 2
        spec = self.disk_manager._create_spec(capacity)
        assert_that(spec.capacityKb, equal_to(capacity * (1024 ** 2)))
        assert_that(spec.adapterType, equal_to(DEFAULT_DISK_ADAPTER_TYPE))

    def test_invalid_datastore_path(self):
        """Test that we propagate InvalidDatastorePath."""

        self.vim_client.wait_for_task.side_effect = \
            vim.fault.InvalidDatastorePath
        self.assertRaises(DiskPathException,
                          self.disk_manager.create_disk, "ds1", "foo", 101)

    def test_disk_not_found(self):
        """Test that we propagate FileNotFound."""

        self.vim_client.wait_for_task.side_effect = vim.fault.FileNotFound
        self.assertRaises(DiskFileException,
                          self.disk_manager.delete_disk, "ds1", "bar")

    def test_general_fault(self):
        """Test general Exception propagation."""

        self.vim_client.wait_for_task.side_effect = vim.fault.TaskInProgress

        self.assertRaises(vim.fault.TaskInProgress,
                          self.disk_manager.move_disk,
                          "ds1", "biz", "ds1", "baz")
开发者ID:aasthabh,项目名称:photon-controller,代码行数:47,代码来源:test_esx_disk_manager.py

示例12: vim_delete_vm

 def vim_delete_vm(self, vm_id):
     """ Delete a VM using the vim client """
     try:
         vim_client = VimClient()
         vim_client.connect_ticket(self.server, self._get_vim_ticket())
         vim_vm = vim_client.get_vm(vm_id)
         if vim_vm.runtime.powerState != 'poweredOff':
             try:
                 vim_task = vim_vm.PowerOff()
                 vim_client.wait_for_task(vim_task)
             except:
                 logger.info("Cannot power off vm", exc_info=True)
         vim_task = vim_vm.Destroy()
         vim_client.wait_for_task(vim_task)
     finally:
         if vim_client:
             vim_client.disconnect()
开发者ID:hartsock,项目名称:photon-controller,代码行数:17,代码来源:test_remote_agent.py

示例13: test_vim_client_errback

    def test_vim_client_errback(self, connect_mock, host_mock):
        callback = MagicMock()
        vim_client = VimClient(auto_sync=False, errback=callback)
        vim_client.connect_userpwd("esx.local", "root", "password")
        host_mock.side_effect = vim.fault.NotAuthenticated
        vim_client.host_system
        callback.assert_called_once()

        host_mock.side_effect = vim.fault.HostConnectFault
        vim_client.host_system
        assert_that(callback.call_count, is_(2))

        host_mock.side_effect = vim.fault.InvalidLogin
        vim_client.host_system
        assert_that(callback.call_count, is_(3))

        host_mock.side_effect = AcquireCredentialsException
        vim_client.host_system
        assert_that(callback.call_count, is_(4))
开发者ID:cartlhd,项目名称:photon-controller,代码行数:19,代码来源:test_vim_client.py

示例14: setUp

 def setUp(self, connect, creds):
     self.shadow_vm_id = SHADOW_VM_NAME_PREFIX + str(uuid.uuid1())
     self.image_datastores = ["image_ds", "alt_image_ds"]
     creds.return_value = ["username", "password"]
     self.vim_client = VimClient(auto_sync=False)
     self.patcher = patch("host.hypervisor.esx.vm_config.GetEnv")
     self.patcher.start()
     services.register(ServiceName.AGENT_CONFIG, MagicMock())
     self.http_transferer = HttpNfcTransferer(self.vim_client,
                                              self.image_datastores)
开发者ID:thulasi39,项目名称:photon-controller,代码行数:10,代码来源:test_http_transfer.py

示例15: setUp

 def setUp(self, connect, creds):
     self.host_uuid = str(uuid.uuid4())
     VimClient.host_uuid = self.host_uuid
     self.image_ds = "image_ds"
     creds.return_value = ["username", "password"]
     self.vim_client = VimClient(auto_sync=False)
     self.patcher = patch("host.hypervisor.esx.vm_config.GetEnv")
     self.patcher.start()
     services.register(ServiceName.AGENT_CONFIG, MagicMock())
     self.http_transferer = HttpNfcTransferer(self.vim_client,
                                              self.image_ds)
开发者ID:pankaj-lakhina,项目名称:photon-controller,代码行数:11,代码来源:test_http_transfer.py


注:本文中的host.hypervisor.esx.vim_client.VimClient类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。