本文整理汇总了Python中sahara.utils.openstack.nova.client函数的典型用法代码示例。如果您正苦于以下问题:Python client函数的具体用法?Python client怎么用?Python client使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了client函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _shutdown_instance
def _shutdown_instance(self, instance):
ctx = context.ctx()
if instance.node_group.floating_ip_pool:
try:
networks.delete_floating_ip(instance.instance_id)
except nova_exceptions.NotFound:
LOG.warn(_LW("Attempted to delete non-existent floating IP in "
"pool %(pool)s from instance %(instance)s"),
{'pool': instance.node_group.floating_ip_pool,
'instance': instance.instance_id})
try:
volumes.detach_from_instance(instance)
except Exception:
LOG.warn(_LW("Detaching volumes from instance %s failed"),
instance.instance_id)
try:
nova.client().servers.delete(instance.instance_id)
except nova_exceptions.NotFound:
LOG.warn(_LW("Attempted to delete non-existent instance %s"),
instance.instance_id)
conductor.instance_remove(ctx, instance)
示例2: _shutdown_instance
def _shutdown_instance(self, instance):
ctx = context.ctx()
if instance.node_group.floating_ip_pool:
try:
networks.delete_floating_ip(instance.instance_id)
except nova_exceptions.NotFound:
LOG.warning(_LW("Attempted to delete non-existent floating IP "
"in pool {pool} from instance {instance}")
.format(pool=instance.node_group.floating_ip_pool,
instance=instance.instance_id))
try:
volumes.detach_from_instance(instance)
except Exception:
LOG.warning(_LW("Detaching volumes from instance {id} failed")
.format(id=instance.instance_id))
try:
nova.client().servers.delete(instance.instance_id)
except nova_exceptions.NotFound:
LOG.warning(_LW("Attempted to delete non-existent instance {id}")
.format(id=instance.instance_id))
conductor.instance_remove(ctx, instance)
示例3: _detach_volume
def _detach_volume(instance, volume_id):
volume = cinder.get_volume(volume_id)
try:
LOG.debug("Detaching volume %s from instance %s" % (
volume_id, instance.instance_name))
nova.client().volumes.delete_server_volume(instance.instance_id,
volume_id)
except Exception:
LOG.exception(_LE("Can't detach volume %s"), volume.id)
detach_timeout = CONF.detach_volume_timeout
LOG.debug("Waiting %d seconds to detach %s volume" % (detach_timeout,
volume_id))
s_time = tu.utcnow()
while tu.delta_seconds(s_time, tu.utcnow()) < detach_timeout:
volume = cinder.get_volume(volume_id)
if volume.status not in ['available', 'error']:
context.sleep(2)
else:
LOG.debug("Volume %s has been detached" % volume_id)
return
else:
LOG.warn(_LW("Can't detach volume %(volume)s. "
"Current status of volume: %(status)s"),
{'volume': volume_id, 'status': volume.status})
示例4: _delete_auto_security_group
def _delete_auto_security_group(self, node_group):
if not node_group.auto_security_group:
return
name = node_group.security_groups[-1]
try:
nova.client().security_groups.delete(name)
except Exception:
LOG.exception("Failed to delete security group %s", name)
示例5: _detach_volume
def _detach_volume(instance, volume_id):
volume = cinder.get_volume(volume_id)
try:
LOG.debug("Detaching volume {id} from instance {instance}".format(
id=volume_id, instance=instance.instance_name))
nova.client().volumes.delete_server_volume(instance.instance_id,
volume_id)
except Exception:
LOG.error(_LE("Can't detach volume {id}").format(id=volume.id))
detach_timeout = CONF.timeouts.detach_volume_timeout
LOG.debug("Waiting {timeout} seconds to detach {id} volume".format(
timeout=detach_timeout, id=volume_id))
_await_detach(volume_id)
示例6: _run_instance
def _run_instance(self, cluster, node_group, idx, aa_group=None,
old_aa_groups=None):
"""Create instance using nova client and persist them into DB."""
ctx = context.ctx()
name = g.generate_instance_name(cluster.name, node_group.name, idx)
userdata = self._generate_user_data_script(node_group, name)
if old_aa_groups:
# aa_groups: node process -> instance ids
aa_ids = []
for node_process in node_group.node_processes:
aa_ids += old_aa_groups.get(node_process) or []
# create instances only at hosts w/ no instances
# w/ aa-enabled processes
hints = {'different_host': sorted(set(aa_ids))} if aa_ids else None
else:
hints = {'group': aa_group} if (
aa_group and self._need_aa_server_group(node_group)) else None
if CONF.use_neutron:
net_id = cluster.neutron_management_network
nics = [{"net-id": net_id, "v4-fixed-ip": ""}]
nova_instance = nova.client().servers.create(
name, node_group.get_image_id(), node_group.flavor_id,
scheduler_hints=hints, userdata=userdata,
key_name=cluster.user_keypair_id,
nics=nics, security_groups=node_group.security_groups)
else:
nova_instance = nova.client().servers.create(
name, node_group.get_image_id(), node_group.flavor_id,
scheduler_hints=hints, userdata=userdata,
key_name=cluster.user_keypair_id,
security_groups=node_group.security_groups)
instance_id = conductor.instance_add(ctx, node_group,
{"instance_id": nova_instance.id,
"instance_name": name})
if old_aa_groups:
# save instance id to aa_groups to support aa feature
for node_process in node_group.node_processes:
if node_process in cluster.anti_affinity:
aa_group_ids = old_aa_groups.get(node_process, [])
aa_group_ids.append(nova_instance.id)
old_aa_groups[node_process] = aa_group_ids
return instance_id
示例7: _create_auto_security_group
def _create_auto_security_group(self, node_group):
name = g.generate_auto_security_group_name(node_group)
nova_client = nova.client()
security_group = nova_client.security_groups.create(
name, "Auto security group created by Sahara for Node Group '%s' "
"of cluster '%s'." %
(node_group.name, node_group.cluster.name))
# ssh remote needs ssh port, agents are not implemented yet
nova_client.security_group_rules.create(
security_group.id, 'tcp', SSH_PORT, SSH_PORT, "0.0.0.0/0")
# open all traffic for private networks
if CONF.use_neutron:
for cidr in neutron.get_private_network_cidrs(node_group.cluster):
for protocol in ['tcp', 'udp']:
nova_client.security_group_rules.create(
security_group.id, protocol, 1, 65535, cidr)
nova_client.security_group_rules.create(
security_group.id, 'icmp', -1, -1, cidr)
# enable ports returned by plugin
for port in node_group.open_ports:
nova_client.security_group_rules.create(
security_group.id, 'tcp', port, port, "0.0.0.0/0")
security_groups = list(node_group.security_groups or [])
security_groups.append(security_group.id)
conductor.node_group_update(context.ctx(), node_group,
{"security_groups": security_groups})
return security_groups
示例8: test_list_registered_images
def test_list_registered_images(self, url_for_mock):
self.override_config('auth_uri', 'https://127.0.0.1:8080/v3/',
'keystone_authtoken')
some_images = [
FakeImage('foo', ['bar', 'baz'], 'test'),
FakeImage('baz', [], 'test'),
FakeImage('spam', [], "")]
with mock.patch('novaclient.v2.images.ImageManager.list',
return_value=some_images):
nova = nova_client.client()
images = nova.images.list_registered()
self.assertEqual(2, len(images))
images = nova.images.list_registered(name='foo')
self.assertEqual(1, len(images))
self.assertEqual('foo', images[0].name)
self.assertEqual('test', images[0].username)
images = nova.images.list_registered(name='eggs')
self.assertEqual(0, len(images))
images = nova.images.list_registered(tags=['bar'])
self.assertEqual(1, len(images))
self.assertEqual('foo', images[0].name)
images = nova.images.list_registered(tags=['bar', 'eggs'])
self.assertEqual(0, len(images))
示例9: check_security_groups_exist
def check_security_groups_exist(security_groups):
security_group_list = nova.client().security_groups.list()
allowed_groups = set(reduce(
operator.add, [[sg.id, sg.name] for sg in security_group_list], []))
for sg in security_groups:
if sg not in allowed_groups:
raise ex.InvalidException(_("Security group '%s' not found") % sg)
示例10: test_list_registered_images
def test_list_registered_images(self, url_for_mock):
some_images = [
FakeImage('foo', ['bar', 'baz'], 'test'),
FakeImage('baz', [], 'test'),
FakeImage('spam', [], "")]
with mock.patch('novaclient.v2.images.ImageManager.list',
return_value=some_images):
nova = nova_client.client()
images = nova.images.list_registered()
self.assertEqual(2, len(images))
images = nova.images.list_registered(name='foo')
self.assertEqual(1, len(images))
self.assertEqual('foo', images[0].name)
self.assertEqual('test', images[0].username)
images = nova.images.list_registered(name='eggs')
self.assertEqual(0, len(images))
images = nova.images.list_registered(tags=['bar'])
self.assertEqual(1, len(images))
self.assertEqual('foo', images[0].name)
images = nova.images.list_registered(tags=['bar', 'eggs'])
self.assertEqual(0, len(images))
示例11: _create_attach_volume
def _create_attach_volume(ctx, instance, size, display_name=None,
volume_type=None):
volume = cinder.client().volumes.create(size=size,
display_name=display_name,
volume_type=volume_type)
conductor.append_volume(ctx, instance, volume.id)
while volume.status != 'available':
volume = cinder.get_volume(volume.id)
if volume.status == 'error':
raise ex.SystemError("Volume %s has error status" % volume.id)
context.sleep(1)
nova.client().volumes.create_server_volume(instance.instance_id,
volume.id, None)
示例12: check_auto_security_group
def check_auto_security_group(cluster_name, nodegroup):
if nodegroup.get('auto_security_group'):
name = g.generate_auto_security_group_name(
cluster_name, nodegroup['name'])
if name in [security_group.name for security_group in
nova.client().security_groups.list()]:
raise ex.NameAlreadyExistsException(
_("Security group with name '%s' already exists") % name)
示例13: _delete_aa_server_group
def _delete_aa_server_group(self, cluster):
if cluster.anti_affinity:
server_group_name = g.generate_aa_group_name(cluster.name)
client = nova.client().server_groups
server_groups = client.findall(name=server_group_name)
if len(server_groups) == 1:
client.delete(server_groups[0].id)
示例14: check_security_groups_exist
def check_security_groups_exist(security_groups):
security_group_list = nova.client().security_groups.list()
allowed_groups = set(reduce(
operator.add, [[six.text_type(sg.id), sg.name]
for sg in security_group_list], []))
for sg in security_groups:
if sg not in allowed_groups:
raise ex.NotFoundException(
sg, _("Security group '%s' not found"))
示例15: _get_nova_limits
def _get_nova_limits():
limits = {}
nova = nova_client.client()
lim = b.execute_with_retries(nova.limits.get).to_dict()['absolute']
limits['ram'] = _sub_limit(lim['maxTotalRAMSize'], lim['totalRAMUsed'])
limits['cpu'] = _sub_limit(lim['maxTotalCores'], lim['totalCoresUsed'])
limits['instances'] = _sub_limit(lim['maxTotalInstances'],
lim['totalInstancesUsed'])
return limits