mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
CLOUDSTACK-5626: Simplifying VM Migrate code
Signed-off-by: SrikanteswaraRao Talluri <talluri@apache.org>
This commit is contained in:
parent
09c375379d
commit
3b3ae02459
@ -30,10 +30,11 @@ from marvin.integration.lib.base import (
|
|||||||
from marvin.integration.lib.common import (get_domain,
|
from marvin.integration.lib.common import (get_domain,
|
||||||
get_zone,
|
get_zone,
|
||||||
get_template,
|
get_template,
|
||||||
find_suitable_host,
|
findSuitableHostForMigration,
|
||||||
get_resource_type
|
get_resource_type
|
||||||
)
|
)
|
||||||
from marvin.integration.lib.utils import cleanup_resources
|
from marvin.integration.lib.utils import cleanup_resources
|
||||||
|
from marvin.codes import ERROR_NO_HOST_FOR_MIGRATION
|
||||||
|
|
||||||
class Services:
|
class Services:
|
||||||
"""Test resource limit services
|
"""Test resource limit services
|
||||||
@ -329,7 +330,9 @@ class TestDomainCPULimitsUpdateResources(cloudstackTestCase):
|
|||||||
self.assertEqual(resource_count, expected_resource_count,
|
self.assertEqual(resource_count, expected_resource_count,
|
||||||
"Initial resource count should match with the expected resource count")
|
"Initial resource count should match with the expected resource count")
|
||||||
|
|
||||||
host = find_suitable_host(self.apiclient, vm)
|
host = findSuitableHostForMigration(self.apiclient, vm.id)
|
||||||
|
if host is None:
|
||||||
|
self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
|
||||||
self.debug("Migrating instance: %s to host: %s" %
|
self.debug("Migrating instance: %s to host: %s" %
|
||||||
(vm.name, host.name))
|
(vm.name, host.name))
|
||||||
try:
|
try:
|
||||||
@ -477,7 +480,9 @@ class TestDomainCPULimitsUpdateResources(cloudstackTestCase):
|
|||||||
self.assertEqual(resource_count_after_delete, expected_resource_count,
|
self.assertEqual(resource_count_after_delete, expected_resource_count,
|
||||||
"Resource count should match with the expected count")
|
"Resource count should match with the expected count")
|
||||||
|
|
||||||
host = find_suitable_host(self.apiclient, vm_2)
|
host = findSuitableHostForMigration(self.apiclient, vm_2.id)
|
||||||
|
if host is None:
|
||||||
|
self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
|
||||||
self.debug("Migrating instance: %s to host: %s" % (vm_2.name,
|
self.debug("Migrating instance: %s to host: %s" % (vm_2.name,
|
||||||
host.name))
|
host.name))
|
||||||
try:
|
try:
|
||||||
|
|||||||
@ -30,10 +30,11 @@ from marvin.integration.lib.base import (
|
|||||||
from marvin.integration.lib.common import (get_domain,
|
from marvin.integration.lib.common import (get_domain,
|
||||||
get_zone,
|
get_zone,
|
||||||
get_template,
|
get_template,
|
||||||
find_suitable_host,
|
findSuitableHostForMigration,
|
||||||
get_resource_type
|
get_resource_type
|
||||||
)
|
)
|
||||||
from marvin.integration.lib.utils import cleanup_resources
|
from marvin.integration.lib.utils import cleanup_resources
|
||||||
|
from marvin.codes import ERROR_NO_HOST_FOR_MIGRATION
|
||||||
|
|
||||||
|
|
||||||
class Services:
|
class Services:
|
||||||
@ -251,7 +252,9 @@ class TestCPULimits(cloudstackTestCase):
|
|||||||
self.assertEqual(resource_count, expected_resource_count,
|
self.assertEqual(resource_count, expected_resource_count,
|
||||||
"Resource count should match with the expected resource count")
|
"Resource count should match with the expected resource count")
|
||||||
|
|
||||||
host = find_suitable_host(self.apiclient, self.vm)
|
host = findSuitableHostForMigration(self.apiclient, self.vm.id)
|
||||||
|
if host is None:
|
||||||
|
self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
|
||||||
self.debug("Migrating instance: %s to host: %s" % (self.vm.name, host.name))
|
self.debug("Migrating instance: %s to host: %s" % (self.vm.name, host.name))
|
||||||
try:
|
try:
|
||||||
self.vm.migrate(self.apiclient, host.id)
|
self.vm.migrate(self.apiclient, host.id)
|
||||||
@ -570,7 +573,9 @@ class TestDomainCPULimitsConfiguration(cloudstackTestCase):
|
|||||||
self.assertEqual(resource_count, expected_resource_count,
|
self.assertEqual(resource_count, expected_resource_count,
|
||||||
"Initial resource count should with the expected resource count")
|
"Initial resource count should with the expected resource count")
|
||||||
|
|
||||||
host = find_suitable_host(self.apiclient, vm)
|
host = findSuitableHostForMigration(self.apiclient, vm.id)
|
||||||
|
if host is None:
|
||||||
|
self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
|
||||||
self.debug("Migrating instance: %s to host: %s" %
|
self.debug("Migrating instance: %s to host: %s" %
|
||||||
(vm.name, host.name))
|
(vm.name, host.name))
|
||||||
try:
|
try:
|
||||||
@ -725,7 +730,9 @@ class TestDomainCPULimitsConfiguration(cloudstackTestCase):
|
|||||||
self.assertEqual(resource_count_after_delete, expected_resource_count,
|
self.assertEqual(resource_count_after_delete, expected_resource_count,
|
||||||
"Resource count should be less than before after deleting the instance")
|
"Resource count should be less than before after deleting the instance")
|
||||||
|
|
||||||
host = find_suitable_host(self.apiclient, vm_2)
|
host = findSuitableHostForMigration(self.apiclient, vm_2.id)
|
||||||
|
if host is None:
|
||||||
|
self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
|
||||||
self.debug("Migrating instance: %s to host: %s" % (vm_2.name,
|
self.debug("Migrating instance: %s to host: %s" % (vm_2.name,
|
||||||
host.name))
|
host.name))
|
||||||
try:
|
try:
|
||||||
|
|||||||
@ -30,10 +30,11 @@ from marvin.integration.lib.base import (
|
|||||||
from marvin.integration.lib.common import (get_domain,
|
from marvin.integration.lib.common import (get_domain,
|
||||||
get_zone,
|
get_zone,
|
||||||
get_template,
|
get_template,
|
||||||
find_suitable_host,
|
findSuitableHostForMigration,
|
||||||
get_resource_type
|
get_resource_type
|
||||||
)
|
)
|
||||||
from marvin.integration.lib.utils import cleanup_resources
|
from marvin.integration.lib.utils import cleanup_resources
|
||||||
|
from marvin.codes import ERROR_NO_HOST_FOR_MIGRATION
|
||||||
|
|
||||||
class Services:
|
class Services:
|
||||||
"""Test resource limit services
|
"""Test resource limit services
|
||||||
@ -291,7 +292,9 @@ class TestProjectsCPULimits(cloudstackTestCase):
|
|||||||
self.assertEqual(resource_count, expected_resource_count,
|
self.assertEqual(resource_count, expected_resource_count,
|
||||||
"Resource count should match with the expected resource count")
|
"Resource count should match with the expected resource count")
|
||||||
|
|
||||||
host = find_suitable_host(self.apiclient, self.vm)
|
host = findSuitableHostForMigration(self.apiclient, self.vm.id)
|
||||||
|
if host is None:
|
||||||
|
self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
|
||||||
self.debug("Migrating instance: %s to host: %s" %
|
self.debug("Migrating instance: %s to host: %s" %
|
||||||
(self.vm.name, host.name))
|
(self.vm.name, host.name))
|
||||||
try:
|
try:
|
||||||
|
|||||||
@ -30,10 +30,11 @@ from marvin.integration.lib.common import (get_domain,
|
|||||||
get_zone,
|
get_zone,
|
||||||
get_template,
|
get_template,
|
||||||
wait_for_cleanup,
|
wait_for_cleanup,
|
||||||
find_suitable_host,
|
findSuitableHostForMigration,
|
||||||
get_resource_type
|
get_resource_type
|
||||||
)
|
)
|
||||||
from marvin.integration.lib.utils import cleanup_resources
|
from marvin.integration.lib.utils import cleanup_resources
|
||||||
|
from marvin.codes import ERROR_NO_HOST_FOR_MIGRATION
|
||||||
|
|
||||||
class Services:
|
class Services:
|
||||||
"""Test memory resource limit services
|
"""Test memory resource limit services
|
||||||
@ -248,7 +249,9 @@ class TestMemoryLimits(cloudstackTestCase):
|
|||||||
self.assertEqual(resource_count, expected_resource_count,
|
self.assertEqual(resource_count, expected_resource_count,
|
||||||
"Resource count should match with the expected resource count")
|
"Resource count should match with the expected resource count")
|
||||||
|
|
||||||
host = find_suitable_host(self.apiclient, self.vm)
|
host = findSuitableHostForMigration(self.apiclient, self.vm.id)
|
||||||
|
if host is None:
|
||||||
|
self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
|
||||||
self.debug("Migrating instance: %s to host: %s" % (self.vm.name, host.name))
|
self.debug("Migrating instance: %s to host: %s" % (self.vm.name, host.name))
|
||||||
try:
|
try:
|
||||||
self.vm.migrate(self.apiclient, host.id)
|
self.vm.migrate(self.apiclient, host.id)
|
||||||
@ -587,7 +590,9 @@ class TestDomainMemoryLimitsConfiguration(cloudstackTestCase):
|
|||||||
self.assertEqual(resource_count, expected_resource_count,
|
self.assertEqual(resource_count, expected_resource_count,
|
||||||
"Initial resource count should with the expected resource count")
|
"Initial resource count should with the expected resource count")
|
||||||
|
|
||||||
host = find_suitable_host(self.apiclient, vm)
|
host = findSuitableHostForMigration(self.apiclient, vm.id)
|
||||||
|
if host is None:
|
||||||
|
self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
|
||||||
self.debug("Migrating instance: %s to host: %s" %
|
self.debug("Migrating instance: %s to host: %s" %
|
||||||
(vm.name, host.name))
|
(vm.name, host.name))
|
||||||
try:
|
try:
|
||||||
@ -743,7 +748,9 @@ class TestDomainMemoryLimitsConfiguration(cloudstackTestCase):
|
|||||||
self.assertEqual(resource_count_after_delete, expected_resource_count,
|
self.assertEqual(resource_count_after_delete, expected_resource_count,
|
||||||
"Resource count should match with the expected resource count")
|
"Resource count should match with the expected resource count")
|
||||||
|
|
||||||
host = find_suitable_host(self.apiclient, vm_2)
|
host = findSuitableHostForMigration(self.apiclient, vm_2.id)
|
||||||
|
if host is None:
|
||||||
|
self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
|
||||||
self.debug("Migrating instance: %s to host: %s" % (vm_2.name,
|
self.debug("Migrating instance: %s to host: %s" % (vm_2.name,
|
||||||
host.name))
|
host.name))
|
||||||
try:
|
try:
|
||||||
|
|||||||
@ -30,11 +30,12 @@ from marvin.integration.lib.common import (get_domain,
|
|||||||
get_zone,
|
get_zone,
|
||||||
get_template,
|
get_template,
|
||||||
wait_for_cleanup,
|
wait_for_cleanup,
|
||||||
find_suitable_host,
|
findSuitableHostForMigration,
|
||||||
get_resource_type,
|
get_resource_type,
|
||||||
update_resource_count
|
update_resource_count
|
||||||
)
|
)
|
||||||
from marvin.integration.lib.utils import cleanup_resources
|
from marvin.integration.lib.utils import cleanup_resources
|
||||||
|
from marvin.codes import ERROR_NO_HOST_FOR_MIGRATION
|
||||||
|
|
||||||
class Services:
|
class Services:
|
||||||
"""Test memory resource limit services
|
"""Test memory resource limit services
|
||||||
@ -388,7 +389,9 @@ class TestDomainMemoryLimits(cloudstackTestCase):
|
|||||||
self.assertEqual(resource_count, expected_resource_count,
|
self.assertEqual(resource_count, expected_resource_count,
|
||||||
"Resource count should match with the expected resource count")
|
"Resource count should match with the expected resource count")
|
||||||
|
|
||||||
host = find_suitable_host(self.apiclient, vm)
|
host = findSuitableHostForMigration(self.apiclient, vm.id)
|
||||||
|
if host is None:
|
||||||
|
self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
|
||||||
self.debug("Migrating instance: %s to host: %s" %
|
self.debug("Migrating instance: %s to host: %s" %
|
||||||
(vm.name, host.name))
|
(vm.name, host.name))
|
||||||
try:
|
try:
|
||||||
|
|||||||
@ -30,10 +30,11 @@ from marvin.integration.lib.common import (get_domain,
|
|||||||
get_zone,
|
get_zone,
|
||||||
get_template,
|
get_template,
|
||||||
wait_for_cleanup,
|
wait_for_cleanup,
|
||||||
find_suitable_host,
|
findSuitableHostForMigration,
|
||||||
get_resource_type
|
get_resource_type
|
||||||
)
|
)
|
||||||
from marvin.integration.lib.utils import cleanup_resources
|
from marvin.integration.lib.utils import cleanup_resources
|
||||||
|
from marvin.codes import ERROR_NO_HOST_FOR_MIGRATION
|
||||||
|
|
||||||
class Services:
|
class Services:
|
||||||
"""Test memory resource limit services
|
"""Test memory resource limit services
|
||||||
@ -291,7 +292,9 @@ class TestProjectsMemoryLimits(cloudstackTestCase):
|
|||||||
resource_count = project_list[0].memorytotal
|
resource_count = project_list[0].memorytotal
|
||||||
self.debug(resource_count)
|
self.debug(resource_count)
|
||||||
|
|
||||||
host = find_suitable_host(self.apiclient, self.vm)
|
host = findSuitableHostForMigration(self.apiclient, self.vm.id)
|
||||||
|
if host is None:
|
||||||
|
self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
|
||||||
self.debug("Migrating instance: %s to host: %s" %
|
self.debug("Migrating instance: %s to host: %s" %
|
||||||
(self.vm.name, host.name))
|
(self.vm.name, host.name))
|
||||||
try:
|
try:
|
||||||
|
|||||||
@ -41,9 +41,10 @@ from marvin.integration.lib.common import (get_domain,
|
|||||||
get_free_vlan,
|
get_free_vlan,
|
||||||
wait_for_cleanup,
|
wait_for_cleanup,
|
||||||
list_virtual_machines,
|
list_virtual_machines,
|
||||||
list_hosts)
|
list_hosts,
|
||||||
|
findSuitableHostForMigration)
|
||||||
|
|
||||||
from marvin.codes import PASS
|
from marvin.codes import PASS, ERROR_NO_HOST_FOR_MIGRATION
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
@ -715,35 +716,13 @@ class TestVMLifeCycleVPC(cloudstackTestCase):
|
|||||||
# works as expected.
|
# works as expected.
|
||||||
# 3. Make sure that we are able to access google.com from this user Vm
|
# 3. Make sure that we are able to access google.com from this user Vm
|
||||||
|
|
||||||
vm_list = VirtualMachine.list(self.apiclient, id=self.vm_1.id)
|
|
||||||
self.assertEqual(validateList(vm_list)[0], PASS, "vm list validation failed, vm list is %s" % vm_list)
|
|
||||||
|
|
||||||
vm_hostid = vm_list[0].hostid
|
|
||||||
|
|
||||||
self.debug("Checking if the host is available for migration?")
|
|
||||||
hosts = Host.list(
|
|
||||||
self.apiclient,
|
|
||||||
zoneid=self.zone.id,
|
|
||||||
type='Routing'
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(
|
|
||||||
isinstance(hosts, list),
|
|
||||||
True,
|
|
||||||
"List hosts should return a valid list"
|
|
||||||
)
|
|
||||||
if len(hosts) < 2:
|
|
||||||
raise unittest.SkipTest(
|
|
||||||
"No host available for migration. Test requires atleast 2 hosts")
|
|
||||||
|
|
||||||
# Remove the host of current VM from the hosts list
|
|
||||||
hosts[:] = [host for host in hosts if host.id != vm_hostid]
|
|
||||||
|
|
||||||
host = hosts[0]
|
|
||||||
|
|
||||||
self.debug("Validating if the network rules work properly or not?")
|
self.debug("Validating if the network rules work properly or not?")
|
||||||
self.validate_network_rules()
|
self.validate_network_rules()
|
||||||
|
|
||||||
|
host = findSuitableHostForMigration(self.apiclient, self.vm_1.id)
|
||||||
|
if host is None:
|
||||||
|
self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
|
||||||
|
|
||||||
self.debug("Migrating VM-ID: %s to Host: %s" % (
|
self.debug("Migrating VM-ID: %s to Host: %s" % (
|
||||||
self.vm_1.id,
|
self.vm_1.id,
|
||||||
host.id
|
host.id
|
||||||
@ -1506,30 +1485,13 @@ class TestVMLifeCycleSharedNwVPC(cloudstackTestCase):
|
|||||||
# works as expected.
|
# works as expected.
|
||||||
# 3. Make sure that we are able to access google.com from this user Vm
|
# 3. Make sure that we are able to access google.com from this user Vm
|
||||||
|
|
||||||
self.debug("Checking if the host is available for migration?")
|
|
||||||
hosts = Host.list(
|
|
||||||
self.apiclient,
|
|
||||||
zoneid=self.zone.id,
|
|
||||||
type='Routing'
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(
|
|
||||||
isinstance(hosts, list),
|
|
||||||
True,
|
|
||||||
"List hosts should return a valid list"
|
|
||||||
)
|
|
||||||
if len(hosts) < 2:
|
|
||||||
raise unittest.SkipTest(
|
|
||||||
"No host available for migration. Test requires atleast 2 hosts")
|
|
||||||
|
|
||||||
# Remove the host of current VM from the hosts list
|
|
||||||
hosts[:] = [host for host in hosts if host.id != self.vm_1.hostid]
|
|
||||||
|
|
||||||
host = hosts[0]
|
|
||||||
|
|
||||||
self.debug("Validating if network rules are coonfigured properly?")
|
self.debug("Validating if network rules are coonfigured properly?")
|
||||||
self.validate_network_rules()
|
self.validate_network_rules()
|
||||||
|
|
||||||
|
host = findSuitableHostForMigration(self.apiclient, self.vm_1.id)
|
||||||
|
if host is None:
|
||||||
|
self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
|
||||||
|
|
||||||
self.debug("Migrating VM-ID: %s to Host: %s" % (
|
self.debug("Migrating VM-ID: %s to Host: %s" % (
|
||||||
self.vm_1.id,
|
self.vm_1.id,
|
||||||
host.id
|
host.id
|
||||||
@ -2559,30 +2521,13 @@ class TestVMLifeCycleStoppedVPCVR(cloudstackTestCase):
|
|||||||
# works as expected.
|
# works as expected.
|
||||||
# 3. Make sure that we are able to access google.com from this user Vm
|
# 3. Make sure that we are able to access google.com from this user Vm
|
||||||
|
|
||||||
self.debug("Checking if the host is available for migration?")
|
|
||||||
hosts = Host.list(
|
|
||||||
self.apiclient,
|
|
||||||
zoneid=self.zone.id,
|
|
||||||
type='Routing'
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(
|
|
||||||
isinstance(hosts, list),
|
|
||||||
True,
|
|
||||||
"List hosts should return a valid list"
|
|
||||||
)
|
|
||||||
if len(hosts) < 2:
|
|
||||||
raise unittest.SkipTest(
|
|
||||||
"No host available for migration. Test requires atleast 2 hosts")
|
|
||||||
|
|
||||||
# Remove the host of current VM from the hosts list
|
|
||||||
hosts[:] = [host for host in hosts if host.id != self.vm_1.hostid]
|
|
||||||
|
|
||||||
host = hosts[0]
|
|
||||||
|
|
||||||
self.debug("Validating if the network rules work properly or not?")
|
self.debug("Validating if the network rules work properly or not?")
|
||||||
self.validate_network_rules()
|
self.validate_network_rules()
|
||||||
|
|
||||||
|
host = findSuitableHostForMigration(self.apiclient, self.vm_1.id)
|
||||||
|
if host is None:
|
||||||
|
self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
|
||||||
|
|
||||||
self.debug("Migrating VM-ID: %s on Host: %s to Host: %s" % (
|
self.debug("Migrating VM-ID: %s on Host: %s to Host: %s" % (
|
||||||
self.vm_1.id,
|
self.vm_1.id,
|
||||||
self.vm_1.hostid,
|
self.vm_1.hostid,
|
||||||
@ -3459,28 +3404,13 @@ class TestVMLifeCycleDiffHosts(cloudstackTestCase):
|
|||||||
# works as expected.
|
# works as expected.
|
||||||
# 3. Make sure that we are able to access google.com from this user Vm
|
# 3. Make sure that we are able to access google.com from this user Vm
|
||||||
|
|
||||||
self.debug("Checking if the host is available for migration?")
|
|
||||||
hosts = Host.listForMigration(
|
|
||||||
self.apiclient,
|
|
||||||
virtualmachineid=self.vm_1.id,
|
|
||||||
)
|
|
||||||
self.debug("Hosts vm can be migrated to are : %s" %(hosts))
|
|
||||||
self.assertEqual(
|
|
||||||
isinstance(hosts, list),
|
|
||||||
True,
|
|
||||||
"List hosts should return a valid list"
|
|
||||||
)
|
|
||||||
# Remove the host of current VM from the hosts list
|
|
||||||
hosts[:] = [host for host in hosts if host.id != self.vm_1.hostid]
|
|
||||||
if len(hosts) <= 0:
|
|
||||||
self.skipTest(
|
|
||||||
"No host available for migration. Test requires atleast 2 hosts tagged with host1")
|
|
||||||
|
|
||||||
host = hosts[0]
|
|
||||||
|
|
||||||
self.debug("Validating if the network rules work properly or not?")
|
self.debug("Validating if the network rules work properly or not?")
|
||||||
self.validate_network_rules()
|
self.validate_network_rules()
|
||||||
|
|
||||||
|
host = findSuitableHostForMigration(self.apiclient, self.vm_1.id)
|
||||||
|
if host is None:
|
||||||
|
self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
|
||||||
|
|
||||||
self.debug("Migrating VM-ID: %s to Host: %s" % (
|
self.debug("Migrating VM-ID: %s to Host: %s" % (
|
||||||
self.vm_1.id,
|
self.vm_1.id,
|
||||||
host.id
|
host.id
|
||||||
|
|||||||
@ -51,3 +51,4 @@ BASIC_ZONE = "basic"
|
|||||||
ISOLATED_NETWORK = "ISOLATED"
|
ISOLATED_NETWORK = "ISOLATED"
|
||||||
SHARED_NETWORK = "SHARED"
|
SHARED_NETWORK = "SHARED"
|
||||||
VPC_NETWORK = "VPC"
|
VPC_NETWORK = "VPC"
|
||||||
|
ERROR_NO_HOST_FOR_MIGRATION = "Could not find suitable host for migration, please ensure setup has required no. of hosts"
|
||||||
|
|||||||
@ -712,18 +712,23 @@ def update_resource_count(apiclient, domainid, accountid=None,
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
def find_suitable_host(apiclient, vm):
|
def findSuitableHostForMigration(apiclient, vmid):
|
||||||
"""Returns a suitable host for VM migration"""
|
"""Returns a suitable host for VM migration"""
|
||||||
|
suitableHost = None
|
||||||
|
try:
|
||||||
|
hosts = Host.listForMigration(apiclient, virtualmachineid=vmid,
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
raise Exception("Exception while getting hosts list suitable for migration: %s" % e)
|
||||||
|
|
||||||
hosts = Host.list(apiclient,
|
suitablehosts = []
|
||||||
virtualmachineid=vm.id,
|
if isinstance(hosts, list) and len(hosts) > 0:
|
||||||
listall=True)
|
suitablehosts = [host for host in hosts if (str(host.resourcestate).lower() == "enabled"\
|
||||||
|
and str(host.state).lower() == "up")]
|
||||||
|
if len(suitablehosts)>0:
|
||||||
|
suitableHost = suitablehosts[0]
|
||||||
|
|
||||||
if isinstance(hosts, list):
|
return suitableHost
|
||||||
assert len(hosts) > 0, "List host should return valid response"
|
|
||||||
else:
|
|
||||||
raise Exception("Exception: List host should return valid response")
|
|
||||||
return hosts[0]
|
|
||||||
|
|
||||||
def get_resource_type(resource_id):
|
def get_resource_type(resource_id):
|
||||||
"""Returns resource type"""
|
"""Returns resource type"""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user