本文整理汇总了Python中host.hypervisor.esx.vim_client.VimClient.get_all_datastores方法的典型用法代码示例。如果您正苦于以下问题:Python VimClient.get_all_datastores方法的具体用法?Python VimClient.get_all_datastores怎么用?Python VimClient.get_all_datastores使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类host.hypervisor.esx.vim_client.VimClient
的用法示例。
在下文中一共展示了VimClient.get_all_datastores方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestVmManager
# 需要导入模块: from host.hypervisor.esx.vim_client import VimClient [as 别名]
# 或者: from host.hypervisor.esx.vim_client.VimClient import get_all_datastores [as 别名]
class TestVmManager(unittest.TestCase):
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"]
if self.host is None or self.pwd is None:
raise SkipTest()
self._logger = logging.getLogger(__name__)
self.vim_client = VimClient()
self.vim_client.connect_userpwd(self.host, "root", self.pwd)
self.vm_manager = VmManager(self.vim_client, None)
for vm in self.vim_client._get_vms():
vm.Destroy()
def tearDown(self):
self.vim_client.disconnect()
@patch('os.path.exists', return_value=True)
def test_mks_ticket(self, _exists):
vm_id = self._vm_id()
flavor = Flavor("vm", [QuotaLineItem("vm.cpu", 1, Unit.COUNT),
QuotaLineItem("vm.memory", 8, Unit.MB)])
datastore = self.vim_client.get_all_datastores()[0].name
spec = self.vm_manager.create_vm_spec(vm_id, datastore, flavor)
try:
self.vm_manager.create_vm(vm_id, spec)
self.vm_manager.power_on_vm(vm_id)
ticket = self.vm_manager.get_mks_ticket(vm_id)
assert_that(ticket.cfg_file, not_none())
assert_that(ticket.ticket, not_none())
finally:
self.vm_manager.power_off_vm(vm_id)
self.vm_manager.delete_vm(vm_id)
def _vm_id(self):
vm_id = strftime("%Y-%m-%d-%H%M%S-", localtime())
vm_id += str(random.randint(1, 10000))
return vm_id
def _test_port(self):
return 5907
示例2: TestRemoteAgent
# 需要导入模块: from host.hypervisor.esx.vim_client import VimClient [as 别名]
# 或者: from host.hypervisor.esx.vim_client.VimClient import get_all_datastores [as 别名]
class TestRemoteAgent(unittest.TestCase, AgentCommonTests):
def shortDescription(self):
return None
def get_service_instance(self):
# create a connection to hostd.
request = ServiceTicketRequest(ServiceType.VIM)
response = self.host_client.get_service_ticket(request)
self.assertEqual(response.result, ServiceTicketResultCode.OK)
hostd_port = 443
vim_namespace = "vim25/5.0"
stub = SoapStubAdapter(self.server, hostd_port, vim_namespace)
si = vim.ServiceInstance("ServiceInstance", stub)
si.RetrieveContent().sessionManager.CloneSession(response.vim_ticket)
connect.SetSi(si)
return si
def connect_client(self, service, cls, server):
""" Utility method to connect to a remote agent """
max_sleep_time = 32
sleep_time = 0.1
while sleep_time < max_sleep_time:
try:
client = DirectClient(service, cls, server, 8835)
client.connect()
return client
except TTransport.TTransportException:
time.sleep(sleep_time)
sleep_time *= 2
self.fail("Cannot connect to agent %s" % server)
def create_client(self):
return self.connect_client("Host", Host.Client, self.server)
def client_connections(self):
self.host_client = self.create_client()
self.control_client = self.connect_client("AgentControl", AgentControl.Client, self.server)
def provision_hosts(self, mem_overcommit=2.0,
datastores=None, used_for_vms=True,
image_ds=None, host_id=None,
deployment_id="test-deployment"):
""" Provisions the agents on the remote hosts """
if datastores is None:
datastores = self.get_all_datastores()
image_datastore = self.get_image_datastore()
elif image_ds:
image_datastore = image_ds
else:
image_datastore = datastores[0]
req = ProvisionRequest()
req.datastores = datastores
req.address = ServerAddress(host=self.server, port=8835)
req.memory_overcommit = mem_overcommit
req.image_datastore_info = ImageDatastore(
name=image_datastore,
used_for_vms=used_for_vms)
req.image_datastores = set([req.image_datastore_info])
req.management_only = True
if host_id:
req.host_id = host_id
else:
req.host_id = self.host_id
if deployment_id:
req.deployment_id = deployment_id
else:
req.deployment_id = self.deployment_id
res = self.control_client.provision(req)
# This will trigger a restart if the agent config changes, which
# will happen the first time provision_hosts is called.
self.assertEqual(res.result, ProvisionResultCode.OK)
# Wait for up to 60 seconds for the agent to reboot.
count = 0
while count < 60:
try:
res = self.control_client.get_agent_status()
if res.status == AgentStatusCode.OK:
# Agent is up
return
except:
logger.exception("Can't connect to agent")
count += 1
time.sleep(1)
# Reconnect the clients
self._close_agent_connections()
self.client_connections()
self.fail("Cannot connect to agent %s after provisioning" % self.server)
return host_id
def setUp(self):
from testconfig import config
if "agent_remote_test" not in config:
raise SkipTest()
#.........这里部分代码省略.........
示例3: TestVimClient
# 需要导入模块: from host.hypervisor.esx.vim_client import VimClient [as 别名]
# 或者: from host.hypervisor.esx.vim_client.VimClient import get_all_datastores [as 别名]
class TestVimClient(unittest.TestCase):
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"]
if self.host is None or self.pwd is None:
raise SkipTest()
self.vim_client = VimClient(auto_sync=True)
self.vim_client.connect_userpwd(self.host, "root", self.pwd)
self._logger = logging.getLogger(__name__)
def tearDown(self):
self.vim_client.disconnect()
def test_memory_usage(self):
used_memory = self.vim_client.memory_usage_mb
assert_that(used_memory > 0, is_(True))
def test_total_memory(self):
total_memory = self.vim_client.total_vmusable_memory_mb
assert_that(total_memory > 0, is_(True))
def test_total_cpus(self):
num_cpus = self.vim_client.num_physical_cpus
assert_that(num_cpus > 0, is_(True))
def _create_test_vm(self, suffix="host-integ"):
# Create VM
vm_id = "vm_%s-%s-%s" % (
time.strftime("%Y-%m-%d-%H%M%S", time.localtime()),
str(random.randint(100000, 1000000)),
suffix)
datastore = self.vim_client.get_all_datastores()[0].name
disk_path = "[%s] %s/disk.vmdk" % (datastore, vm_id)
create_spec = self.get_create_spec(datastore, vm_id, disk_path)
self.vim_client.create_vm(vm_id, create_spec)
vm = self.vim_client.get_vm(vm_id)
return (vm_id, vm, datastore, disk_path)
def test_get_cached_vm(self):
vm_id, vm, datastore, disk_path = self._create_test_vm("vm-cache-test")
# Verify VM is in cache
vms = self.vim_client.get_vms_in_cache()
found_vms = [v for v in vms if v.name == vm_id]
assert_that(len(found_vms), is_(1))
assert_that(found_vms[0].name, is_(vm_id))
assert_that(found_vms[0].power_state, is_(VmPowerState.STOPPED))
assert_that(found_vms[0].memory_mb, is_(64))
assert_that(found_vms[0].path, starts_with("[%s]" % datastore))
assert_that(len(found_vms[0].disks), is_(1))
assert_that(found_vms[0].disks[0], is_(disk_path))
# Make sure get_vm_in_cache works
vm_from_cache = self.vim_client.get_vm_in_cache(vm_id)
assert_that(vm_from_cache.name, is_(vm_id))
self.assertRaises(VmNotFoundException,
self.vim_client.get_vm_in_cache, "missing")
# Add disk
disk2_path = "[%s] %s/disk2.vmdk" % (datastore, vm_id)
update_spec = self.get_update_spec(vm, disk2_path)
task = vm.ReconfigVM_Task(update_spec.get_spec())
self.vim_client.wait_for_task(task)
# For the ReconfigVM task to remove disk, the hostd could update
# task status to success before updating VM status. Thus when
# wait_for_task returns, the vm_cache is possible to be still in old
# state, though eventually it converges to consistent state. It only
# happens in this task AFAIK. It should be fine for this task, because
# rarely there is other operation that depends on this task.
self._wait_vm_has_disk(vm_id, 2)
# Verify disk added
vms = self.vim_client.get_vms_in_cache()
found_vms = [v for v in vms if v.name == vm_id]
assert_that(len(found_vms[0].disks), is_(2))
assert_that(found_vms[0].disks,
contains_inanyorder(disk_path, disk2_path))
# Remove disk
vm = self.vim_client.get_vm(vm_id)
remove_spec = self.get_remove_spec(vm, disk2_path)
task = vm.ReconfigVM_Task(remove_spec.get_spec())
self.vim_client.wait_for_task(task)
# Same as before when disk is added
self._wait_vm_has_disk(vm_id, 1)
# Verify disk removed
vms = self.vim_client.get_vms_in_cache()
found_vms = [v for v in vms if v.name == vm_id]
assert_that(len(found_vms), is_(1))
assert_that(len(found_vms[0].disks), is_(1), "disk2 in " +
str(found_vms[0].disks))
#.........这里部分代码省略.........