本文整理汇总了Python中nova.db.instance_get_all函数的典型用法代码示例。如果您正苦于以下问题:Python instance_get_all函数的具体用法?Python instance_get_all怎么用?Python instance_get_all使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了instance_get_all函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_bless_instance
def test_bless_instance(self):
instance_uuid = utils.create_instance(self.context)
num_instance_before = len(db.instance_get_all(self.context))
blessed_instance = self.cobalt_api.bless_instance(self.context, instance_uuid)
self.assertEquals(vm_states.BUILDING, blessed_instance['vm_state'])
# Ensure that we have a 2nd instance in the database that is a "clone"
# of our original instance.
instances = db.instance_get_all(self.context)
self.assertTrue(len(instances) == (num_instance_before + 1),
"There should be one new instance after blessing.")
# The virtual machine should be marked that it is now blessed.
metadata = db.instance_metadata_get(self.context, blessed_instance['uuid'])
self.assertTrue(metadata.has_key('blessed_from'),
"The instance should have a bless metadata after being blessed.")
self.assertTrue(metadata['blessed_from'] == '%s' % instance_uuid,
"The instance should have the blessed_from metadata set to true after being blessed. " \
+ "(value=%s)" % (metadata['blessed_from']))
system_metadata = db.instance_system_metadata_get(self.context, blessed_instance['uuid'])
self.assertTrue(system_metadata.has_key('blessed_from'),
"The instance should have a bless system_metadata after being blessed.")
self.assertTrue(system_metadata['blessed_from'] == '%s' % instance_uuid,
"The instance should have the blessed_from system_metadata set to true after being blessed. "\
+ "(value=%s)" % (system_metadata['blessed_from']))
db_blessed_instance = db.instance_get_by_uuid(self.context,
blessed_instance['uuid'])
self.assertTrue(db_blessed_instance['info_cache'])
self.assertIsNotNone(db_blessed_instance['info_cache']['network_info'])
示例2: test_run_kill_vm
def test_run_kill_vm(self):
"""Detect when a vm is terminated behind the scenes"""
self.stubs = stubout.StubOutForTesting()
self.stubs.Set(compute_manager.ComputeManager,
'_report_driver_status', nop_report_driver_status)
instance_id = self._create_instance()
self.compute.run_instance(self.context, instance_id)
instances = db.instance_get_all(context.get_admin_context())
LOG.info(_("Running instances: %s"), instances)
self.assertEqual(len(instances), 1)
instance_name = instances[0].name
self.compute.driver.test_remove_vm(instance_name)
# Force the compute manager to do its periodic poll
error_list = self.compute.periodic_tasks(context.get_admin_context())
self.assertFalse(error_list)
instances = db.instance_get_all(context.get_admin_context())
LOG.info(_("After force-killing instances: %s"), instances)
self.assertEqual(len(instances), 1)
self.assertEqual(power_state.SHUTOFF, instances[0]['state'])
示例3: mox_host_manager_db_calls
def mox_host_manager_db_calls(mock, context):
mock.StubOutWithMock(db, 'compute_node_get_all')
mock.StubOutWithMock(db, 'instance_get_all')
db.compute_node_get_all(mox.IgnoreArg()).AndReturn(COMPUTE_NODES)
db.instance_get_all(mox.IgnoreArg(),
columns_to_join=['instance_type']).AndReturn(INSTANCES)
示例4: test_instance_get_all
def test_instance_get_all(self):
self.mox.StubOutWithMock(db, "instance_get_all_by_filters")
db.instance_get_all(self.context)
db.instance_get_all_by_filters(self.context, {"name": "fake-inst"}, "updated_at", "asc")
self.mox.ReplayAll()
self.conductor.instance_get_all(self.context)
self.conductor.instance_get_all_by_filters(self.context, {"name": "fake-inst"}, "updated_at", "asc")
示例5: index
def index(self, req):
context = req.environ['nova.context'].elevated()
instances = db.instance_get_all(context)
builder = self._get_builder(req)
server_list = db.instance_get_all(context)
servers = [builder.build(inst, True)['server']
for inst in instances]
return dict(servers=servers)
示例6: test_instance_get_all
def test_instance_get_all(self):
self.mox.StubOutWithMock(db, 'instance_get_all_by_filters')
db.instance_get_all(self.context)
db.instance_get_all_by_filters(self.context, {'name': 'fake-inst'},
'updated_at', 'asc')
self.mox.ReplayAll()
self.conductor.instance_get_all(self.context)
self.conductor.instance_get_all_by_filters(self.context,
{'name': 'fake-inst'},
'updated_at', 'asc')
示例7: test_bless_instance_twice
def test_bless_instance_twice(self):
instance_uuid = utils.create_instance(self.context)
num_instance_before = len(db.instance_get_all(self.context))
self.cobalt_api.bless_instance(self.context, instance_uuid)
self.cobalt_api.bless_instance(self.context, instance_uuid)
instances = db.instance_get_all(self.context)
self.assertTrue(len(instances) == num_instance_before + 2,
"There should be 2 more instances because we blessed twice.")
示例8: test_run_terminate
def test_run_terminate(self):
"""Make sure it is possible to run and terminate instance"""
instance_id = self._create_instance()
self.compute.run_instance(self.context, instance_id)
instances = db.instance_get_all(context.get_admin_context())
LOG.info(_("Running instances: %s"), instances)
self.assertEqual(len(instances), 1)
self.compute.terminate_instance(self.context, instance_id)
instances = db.instance_get_all(context.get_admin_context())
LOG.info(_("After terminating instances: %s"), instances)
self.assertEqual(len(instances), 0)
示例9: list_vms
def list_vms(host=None):
"""
make a list of vms and expand out their fixed_ip and floating ips sensibly
"""
flags.parse_args([])
my_instances = []
if host is None:
instances = db.instance_get_all(context.get_admin_context())
else:
instances = db.instance_get_all_by_host(
context.get_admin_context(), host)
for instance in instances:
my_inst = {}
my_inst = dict(instance).copy()
for (k,v) in my_inst.items():
try:
json.encoder(v)
except TypeError, e:
v = str(v)
my_inst[k] = v
ec2_id = db.get_ec2_instance_id_by_uuid(context.get_admin_context(), instance.uuid)
ec2_id = 'i-' + hex(int(ec2_id)).replace('0x', '').zfill(8)
my_inst['ec2_id'] = ec2_id
try:
fixed_ips = db.fixed_ip_get_by_instance(context.get_admin_context(), instance.uuid)
except:
pass
my_inst['fixed_ips'] = [ ip.address for ip in fixed_ips ]
my_inst['floating_ips'] = []
for ip in fixed_ips:
my_inst['floating_ips'].extend([ f_ip.address for f_ip in db.floating_ip_get_by_fixed_address(context.get_admin_context(), ip.address)])
my_instances.append(my_inst)
示例10: get_all_instances
def get_all_instances(self, context, instance_uuid=None):
"""Returns a list of HostStates that represents all the hosts
the HostManager knows about. Also, each of the consumable resources
in HostState are pre-populated and adjusted based on data in the db.
"""
# Get resource usage across the available compute nodes:
instances = db.instance_get_all(context)
instance_states = [];
if instance_uuid == None:
LOG.info(_("None instance_uuid"));
for instance in instances:
vm_state = instance.get('vm_state')
if vm_state == None or vm_state != vm_states.ACTIVE:
continue;
if instance_uuid != None and instance['uuid'] == instance_uuid:
LOG.info(_("found matching uuid instance"));
continue;
instance_state = self.instance_state_cls(instance);
instance_states.append(instance_state);
return instance_states;
示例11: _list_running_instances
def _list_running_instances(self, context):
"""List running instances (on all compute nodes)."""
self.used_images = {}
self.image_popularity = {}
self.instance_names = set()
instances = db.instance_get_all(context)
for instance in instances:
self.instance_names.add(instance['name'])
resize_states = [task_states.RESIZE_PREP,
task_states.RESIZE_MIGRATING,
task_states.RESIZE_MIGRATED,
task_states.RESIZE_FINISH]
if instance['task_state'] in resize_states or \
instance['vm_state'] in vm_states.RESIZED:
self.instance_names.add(instance['name'] + '_resize')
image_ref_str = str(instance['image_ref'])
local, remote, insts = self.used_images.get(image_ref_str,
(0, 0, []))
if instance['host'] == FLAGS.host:
local += 1
else:
remote += 1
insts.append(instance['name'])
self.used_images[image_ref_str] = (local, remote, insts)
self.image_popularity.setdefault(image_ref_str, 0)
self.image_popularity[image_ref_str] += 1
示例12: test_boot_servers_with_affinity_overquota
def test_boot_servers_with_affinity_overquota(self):
# Tests that we check server group member quotas and cleanup created
# resources when we fail with OverQuota.
self.flags(quota_server_group_members=1)
# make sure we start with 0 servers
servers = self.api.get_servers(detail=False)
self.assertEqual(0, len(servers))
created_group = self.api.post_server_groups(self.affinity)
ex = self.assertRaises(client.OpenStackApiException,
self._boot_servers_to_group,
created_group)
self.assertEqual(403, ex.response.status_code)
# _boot_servers_to_group creates 2 instances in the group in order, not
# multiple servers in a single request. Since our quota is 1, the first
# server create would pass, the second should fail, and we should be
# left with 1 server and it's 1 block device mapping.
servers = self.api.get_servers(detail=False)
self.assertEqual(1, len(servers))
ctxt = context.get_admin_context()
servers = db.instance_get_all(ctxt)
self.assertEqual(1, len(servers))
ctxt_mgr = db_api.get_context_manager(ctxt)
with ctxt_mgr.reader.using(ctxt):
bdms = db_api._block_device_mapping_get_query(ctxt).all()
self.assertEqual(1, len(bdms))
self.assertEqual(servers[0]['uuid'], bdms[0]['instance_uuid'])
示例13: test_monitor_normal_instance
def test_monitor_normal_instance(self):
fake_instance = {'uuid': 'fake_uuid',
'host': 'fake_compute_host'}
instances = [fake_instance]
self.mox.StubOutWithMock(db, 'instance_get_all')
self.mox.StubOutWithMock(self.manager, '_is_instance_abnormal')
self.mox.StubOutWithMock(self.manager, '_is_instance_ha')
#instance normal
db.instance_get_all(self.context).AndReturn(instances)
self.manager._is_instance_abnormal(self.context,
fake_instance).AndReturn(False)
self.mox.ReplayAll()
self.manager.monitor_instance(self.context)
示例14: list
def list(self, host=None):
"""Lists all fixed ips (optionally by host)."""
ctxt = context.get_admin_context()
try:
if host is None:
fixed_ips = db.fixed_ip_get_all(ctxt)
else:
fixed_ips = db.fixed_ip_get_by_host(ctxt, host)
except exception.NotFound as ex:
print(_("error: %s") % ex)
return(2)
instances = db.instance_get_all(context.get_admin_context())
instances_by_uuid = {}
for instance in instances:
instances_by_uuid[instance['uuid']] = instance
print("%-18s\t%-15s\t%-15s\t%s" % (_('network'),
_('IP address'),
_('hostname'),
_('host')))
all_networks = {}
try:
# use network_get_all to retrieve all existing networks
# this is to ensure that IPs associated with deleted networks
# will not throw exceptions.
for network in db.network_get_all(context.get_admin_context()):
all_networks[network.id] = network
except exception.NoNetworksFound:
# do not have any networks, so even if there are IPs, these
# IPs should have been deleted ones, so return.
print(_('No fixed IP found.'))
return
has_ip = False
for fixed_ip in fixed_ips:
hostname = None
host = None
network = all_networks.get(fixed_ip['network_id'])
if network:
has_ip = True
if fixed_ip.get('instance_uuid'):
instance = instances_by_uuid.get(fixed_ip['instance_uuid'])
if instance:
hostname = instance['hostname']
host = instance['host']
else:
print(_('WARNING: fixed ip %s allocated to missing'
' instance') % str(fixed_ip['address']))
print("%-18s\t%-15s\t%-15s\t%s" % (
network['cidr'],
fixed_ip['address'],
hostname, host))
if not has_ip:
print(_('No fixed IP found.'))
示例15: test_bless_instance
def test_bless_instance(self):
instance_id = utils.create_instance(self.context)
num_instance_before = len(db.instance_get_all(self.context))
self.gridcentric.bless_instance(self.context, instance_id)
# Ensure that we have a 2nd instance in the database that is a "clone"
# of our original instance.
instances = db.instance_get_all(self.context)
self.assertTrue(len(instances) == (num_instance_before + 1),
"There should be one new instances after blessing.")
# The virtual machine should be marked that it is now blessed.
metadata = db.instance_metadata_get(self.context, instance_id + 1)
self.assertTrue(metadata.has_key('blessed'),
"The instance should have a bless metadata after being blessed.")
self.assertTrue(metadata['blessed'] == '1',
"The instance should have the bless metadata set to true after being blessed. " \
+ "(value=%s)" % (metadata['blessed']))