本文整理汇总了Python中heat.engine.clients.Clients.nova方法的典型用法代码示例。如果您正苦于以下问题:Python Clients.nova方法的具体用法?Python Clients.nova怎么用?Python Clients.nova使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类heat.engine.clients.Clients
的用法示例。
在下文中一共展示了Clients.nova方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Stack
# 需要导入模块: from heat.engine.clients import Clients [as 别名]
# 或者: from heat.engine.clients.Clients import nova [as 别名]
#.........这里部分代码省略.........
self.state_set(stack_status, reason)
# flip the template & parameters to the newstack values
# Note we do this on success and failure, so the current
# stack resources are stored, even if one is in a failed
# state (otherwise we won't remove them on delete)
self.t = newstack.t
self.parameters = newstack.parameters
template_outputs = self.t[template.OUTPUTS]
self.outputs = self.resolve_static_data(template_outputs)
self.store()
def delete(self, action=DELETE):
'''
Delete all of the resources, and then the stack itself.
The action parameter is used to differentiate between a user
initiated delete and an automatic stack rollback after a failed
create, which amount to the same thing, but the states are recorded
differently.
'''
if action == self.DELETE:
self.state_set(self.DELETE_IN_PROGRESS, 'Stack deletion started')
elif action == self.ROLLBACK:
self.state_set(self.ROLLBACK_IN_PROGRESS, 'Stack rollback started')
else:
logger.error("Unexpected action %s passed to delete!" % action)
self.state_set(self.DELETE_FAILED, "Invalid action %s" % action)
return
failures = []
for res in reversed(self):
try:
res.destroy()
except exception.ResourceFailure as ex:
logger.error('Failed to delete %s error: %s' % (str(res),
str(ex)))
failures.append(str(res))
if failures:
if action == self.DELETE:
self.state_set(self.DELETE_FAILED,
'Failed to delete ' + ', '.join(failures))
elif action == self.ROLLBACK:
self.state_set(self.ROLLBACK_FAILED,
'Failed to rollback ' + ', '.join(failures))
else:
if action == self.DELETE:
self.state_set(self.DELETE_COMPLETE, 'Deleted successfully')
elif action == self.ROLLBACK:
self.state_set(self.ROLLBACK_COMPLETE, 'Rollback completed')
db_api.stack_delete(self.context, self.id)
self.id = None
def output(self, key):
'''
Get the value of the specified stack output.
'''
value = self.outputs[key].get('Value', '')
return self.resolve_runtime_data(value)
def restart_resource(self, resource_name):
'''
stop resource_name and all that depend on it
start resource_name and all that depend on it
'''
deps = self.dependencies[self[resource_name]]
failed = False
for res in reversed(deps):
try:
res.destroy()
except exception.ResourceFailure as ex:
failed = True
logger.error('delete: %s' % str(ex))
for res in deps:
if not failed:
try:
scheduler.TaskRunner(res.create)()
except exception.ResourceFailure as ex:
logger.exception('create')
failed = True
else:
res.state_set(res.CREATE_FAILED, 'Resource restart aborted')
# TODO(asalkeld) if any of this fails we Should
# restart the whole stack
def get_availability_zones(self):
if self._zones is None:
self._zones = [
zone.zoneName for zone in
self.clients.nova().availability_zones.list(detailed=False)]
return self._zones
def resolve_static_data(self, snippet):
return resolve_static_data(self.t, self, self.parameters, snippet)
def resolve_runtime_data(self, snippet):
return resolve_runtime_data(self.t, self.resources, snippet)
示例2: Stack
# 需要导入模块: from heat.engine.clients import Clients [as 别名]
# 或者: from heat.engine.clients.Clients import nova [as 别名]
#.........这里部分代码省略.........
except scheduler.Timeout:
stack_status = self.FAILED
reason = '%s timed out' % action.title()
if stack_status != self.FAILED and not backup:
# If we created a trust, delete it
stack = db_api.stack_get(self.context, self.id)
user_creds = db_api.user_creds_get(stack.user_creds_id)
trust_id = user_creds.get('trust_id')
if trust_id:
try:
self.clients.keystone().delete_trust(trust_id)
except Exception as ex:
logger.exception(ex)
stack_status = self.FAILED
reason = "Error deleting trust: %s" % str(ex)
self.state_set(action, stack_status, reason)
if stack_status != self.FAILED:
# delete the stack
db_api.stack_delete(self.context, self.id)
self.id = None
def suspend(self):
'''
Suspend the stack, which invokes handle_suspend for all stack resources
waits for all resources to become SUSPEND_COMPLETE then declares the
stack SUSPEND_COMPLETE.
Note the default implementation for all resources is to do nothing
other than move to SUSPEND_COMPLETE, so the resources must implement
handle_suspend for this to have any effect.
'''
sus_task = scheduler.TaskRunner(self.stack_task,
action=self.SUSPEND,
reverse=True)
sus_task(timeout=self.timeout_secs())
def resume(self):
'''
Resume the stack, which invokes handle_resume for all stack resources
waits for all resources to become RESUME_COMPLETE then declares the
stack RESUME_COMPLETE.
Note the default implementation for all resources is to do nothing
other than move to RESUME_COMPLETE, so the resources must implement
handle_resume for this to have any effect.
'''
sus_task = scheduler.TaskRunner(self.stack_task,
action=self.RESUME,
reverse=False)
sus_task(timeout=self.timeout_secs())
def output(self, key):
'''
Get the value of the specified stack output.
'''
value = self.outputs[key].get('Value', '')
return self.resolve_runtime_data(value)
def restart_resource(self, resource_name):
'''
stop resource_name and all that depend on it
start resource_name and all that depend on it
'''
deps = self.dependencies[self[resource_name]]
failed = False
for res in reversed(deps):
try:
scheduler.TaskRunner(res.destroy)()
except exception.ResourceFailure as ex:
failed = True
logger.error('delete: %s' % str(ex))
for res in deps:
if not failed:
try:
res.state_reset()
scheduler.TaskRunner(res.create)()
except exception.ResourceFailure as ex:
logger.exception('create')
failed = True
else:
res.state_set(res.CREATE, res.FAILED,
'Resource restart aborted')
# TODO(asalkeld) if any of this fails we Should
# restart the whole stack
def get_availability_zones(self):
if self._zones is None:
self._zones = [
zone.zoneName for zone in
self.clients.nova().availability_zones.list(detailed=False)]
return self._zones
def resolve_static_data(self, snippet):
return resolve_static_data(self.t, self, self.parameters, snippet)
def resolve_runtime_data(self, snippet):
return resolve_runtime_data(self.t, self.resources, snippet)
示例3: Stack
# 需要导入模块: from heat.engine.clients import Clients [as 别名]
# 或者: from heat.engine.clients.Clients import nova [as 别名]
#.........这里部分代码省略.........
def resume(self):
'''
Resume the stack, which invokes handle_resume for all stack resources
waits for all resources to become RESUME_COMPLETE then declares the
stack RESUME_COMPLETE.
Note the default implementation for all resources is to do nothing
other than move to RESUME_COMPLETE, so the resources must implement
handle_resume for this to have any effect.
'''
# No need to resume if the stack has been resumed
if self.state == (self.RESUME, self.COMPLETE):
LOG.info(_('%s is already resumed') % str(self))
return
sus_task = scheduler.TaskRunner(self.stack_task,
action=self.RESUME,
reverse=False)
sus_task(timeout=self.timeout_secs())
def output(self, key):
'''
Get the value of the specified stack output.
'''
value = self.outputs[key].get('Value', '')
try:
return function.resolve(value)
except Exception as ex:
self.outputs[key]['error_msg'] = six.text_type(ex)
return None
def restart_resource(self, resource_name):
'''
stop resource_name and all that depend on it
start resource_name and all that depend on it
'''
deps = self.dependencies[self[resource_name]]
failed = False
for res in reversed(deps):
try:
scheduler.TaskRunner(res.destroy)()
except exception.ResourceFailure as ex:
failed = True
LOG.error(_('delete: %s') % ex)
for res in deps:
if not failed:
try:
res.state_reset()
scheduler.TaskRunner(res.create)()
except exception.ResourceFailure as ex:
LOG.exception(_('create'))
failed = True
else:
res.state_set(res.CREATE, res.FAILED,
'Resource restart aborted')
# TODO(asalkeld) if any of this fails we Should
# restart the whole stack
def get_availability_zones(self):
if self._zones is None:
self._zones = [
zone.zoneName for zone in
self.clients.nova().availability_zones.list(detailed=False)]
return self._zones
def set_stack_user_project_id(self, project_id):
self.stack_user_project_id = project_id
self.store()
def prepare_abandon(self):
return {
'name': self.name,
'id': self.id,
'action': self.action,
'status': self.status,
'template': self.t.t,
'resources': dict((res.name, res.prepare_abandon())
for res in self.resources.values())
}
def resolve_static_data(self, snippet):
return self.t.parse(self, snippet)
def resolve_runtime_data(self, snippet):
"""DEPRECATED. Use heat.engine.function.resolve() instead."""
warnings.warn('Stack.resolve_runtime_data() is deprecated. '
'Use heat.engine.function.resolve() instead',
DeprecationWarning)
return function.resolve(snippet)
def reset_resource_attributes(self):
# nothing is cached if no resources exist
if not self._resources:
return
# a change in some resource may have side-effects in the attributes
# of other resources, so ensure that attributes are re-calculated
for res in self.resources.itervalues():
res.attributes.reset_resolved_values()
示例4: Stack
# 需要导入模块: from heat.engine.clients import Clients [as 别名]
# 或者: from heat.engine.clients.Clients import nova [as 别名]
#.........这里部分代码省略.........
user_creds = db_api.user_creds_get(stack.user_creds_id)
trust_id = user_creds.get("trust_id")
if trust_id:
try:
self.clients.keystone().delete_trust(trust_id)
except Exception as ex:
logger.exception(ex)
stack_status = self.FAILED
reason = "Error deleting trust: %s" % str(ex)
self.state_set(action, stack_status, reason)
if stack_status != self.FAILED:
# delete the stack
db_api.stack_delete(self.context, self.id)
self.id = None
def suspend(self):
"""
Suspend the stack, which invokes handle_suspend for all stack resources
waits for all resources to become SUSPEND_COMPLETE then declares the
stack SUSPEND_COMPLETE.
Note the default implementation for all resources is to do nothing
other than move to SUSPEND_COMPLETE, so the resources must implement
handle_suspend for this to have any effect.
"""
sus_task = scheduler.TaskRunner(self.stack_task, action=self.SUSPEND, reverse=True)
sus_task(timeout=self.timeout_secs())
def resume(self):
"""
Resume the stack, which invokes handle_resume for all stack resources
waits for all resources to become RESUME_COMPLETE then declares the
stack RESUME_COMPLETE.
Note the default implementation for all resources is to do nothing
other than move to RESUME_COMPLETE, so the resources must implement
handle_resume for this to have any effect.
"""
sus_task = scheduler.TaskRunner(self.stack_task, action=self.RESUME, reverse=False)
sus_task(timeout=self.timeout_secs())
def output(self, key):
"""
Get the value of the specified stack output.
"""
value = self.outputs[key].get("Value", "")
return self.resolve_runtime_data(value)
def restart_resource(self, resource_name):
"""
stop resource_name and all that depend on it
start resource_name and all that depend on it
"""
deps = self.dependencies[self[resource_name]]
failed = False
for res in reversed(deps):
try:
scheduler.TaskRunner(res.destroy)()
except exception.ResourceFailure as ex:
failed = True
logger.error(_("delete: %s") % str(ex))
for res in deps:
if not failed:
try:
res.state_reset()
scheduler.TaskRunner(res.create)()
except exception.ResourceFailure as ex:
logger.exception(_("create"))
failed = True
else:
res.state_set(res.CREATE, res.FAILED, "Resource restart aborted")
# TODO(asalkeld) if any of this fails we Should
# restart the whole stack
def get_availability_zones(self):
if self._zones is None:
self._zones = [zone.zoneName for zone in self.clients.nova().availability_zones.list(detailed=False)]
return self._zones
def set_deletion_policy(self, policy):
for res in self.resources.values():
res.set_deletion_policy(policy)
def get_abandon_data(self):
return {
"name": self.name,
"id": self.id,
"action": self.action,
"status": self.status,
"template": self.t.t,
"resources": dict((res.name, res.get_abandon_data()) for res in self.resources.values()),
}
def resolve_static_data(self, snippet):
return resolve_static_data(self.t, self, self.parameters, snippet)
def resolve_runtime_data(self, snippet):
return resolve_runtime_data(self.t, self.resources, snippet)