本文整理汇总了Python中cm.models.vm.VM.destroy方法的典型用法代码示例。如果您正苦于以下问题:Python VM.destroy方法的具体用法?Python VM.destroy怎么用?Python VM.destroy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cm.models.vm.VM
的用法示例。
在下文中一共展示了VM.destroy方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_and_shutdown
# 需要导入模块: from cm.models.vm import VM [as 别名]
# 或者: from cm.models.vm.VM import destroy [as 别名]
def save_and_shutdown(farm, name, description):
"""
"""
from cm.models.vm import VM
if farm.state == farm_states["failed"]:
raise CMException("farm_wrong_state")
head_vm = farm.head
try:
VM.save_and_shutdown(head_vm.user_id, head_vm, name, description)
except Exception:
CMException("farm_save")
node_vms = []
if farm.state == farm_states["init_head"]:
for vm in farm.vms.all():
if vm.is_head():
continue
vm.release_resources()
vm.state = vm_states["closed"]
else:
for vm in farm.vms.all():
if not vm.is_head():
node_vms.append(vm)
VM.destroy(node_vms)
try:
farm.state = farm_states["closed"]
farm.save()
except:
CMException("farm_save")
示例2: destroy
# 需要导入模块: from cm.models.vm import VM [as 别名]
# 或者: from cm.models.vm.VM import destroy [as 别名]
def destroy(farms):
"""
Destroyes farms' VMs (Head and Worker Nodes of each farm) without saving them.
@parameter{farms,list} list of farms to destroy
@response{list(dict)} list of statuses returned by destroyed VMs
@raises{farm_wrong_state,CMException}
@raises{farm_destroy,CMException}
"""
from cm.models.vm import VM
vm_resp = []
for farm in farms:
# those are states in which farm can not be destroyed
if farm.state in (farm_states["init"], farm_states["closing"], farm_states["closed"]):
raise CMException("farm_wrong_state")
for farm in farms:
# stop all threads
if farm.state == farm_states["init_head"]:
for vm in farm.vms.all():
if vm.is_head():
continue
vm.release_resources()
vm.state = vm_states["closed"]
vm.stop_time = datetime.now()
vm.save()
log.debug(vm.user.id, "vm state %s" % vm.state)
r = VM.destroy([farm.head])
else:
for vm in farm.vms.all():
if vm.state == vm_states["init"]:
raise CMException("farm_wrong_state")
log.debug(farm.user_id, "killing wn: %s" % farm.vms)
r = VM.destroy(farm.vms.all())
if True in [x["status"] != "ok" for x in r]:
farm.state = farm_states["failed"]
try:
farm.save()
except Exception:
raise CMException("farm_destroy")
vm_resp.append(r)
farm.state = farm_states["closed"]
try:
farm.save()
except Exception:
raise CMException("farm_destroy")
log.debug(farm.user_id, "session commited")
for vm in farm.vms.all():
log.debug(vm.user.id, "vm state %s" % vm.state)
return vm_resp
示例3: destroy
# 需要导入模块: from cm.models.vm import VM [as 别名]
# 或者: from cm.models.vm.VM import destroy [as 别名]
def destroy(caller_id, vm_ids):
"""
This function only destroys VM. All the cleanup (removing disk, saving,
rescuing resources, ...) is done by hook through
\c contextualization.update_vm method (yeah, intuitive).
Simple sequence diagram:
@code
CLM CM CTX Node (HOOK)
.
Destroy -->destroy
| | (LV.destroy)
| |------------------------->HookScript
. . |
. . ctx.update_vm<--|
. . | |
. . |------------->cp
. . |------------->rm
. . update_resources
@endcode
@cmview_user
@param_post{vm_ids,list} list of virtual machines' ids
@response{list(dict)} VM.destroy() retval
"""
vms = []
for vm_id in vm_ids:
vms.append(VM.get(caller_id, vm_id))
return VM.destroy(vms)
示例4: save_and_shutdown
# 需要导入模块: from cm.models.vm import VM [as 别名]
# 或者: from cm.models.vm.VM import destroy [as 别名]
def save_and_shutdown(farm, name, description):
"""
"""
from cm.models.vm import VM
if farm.state == farm_states['failed']:
raise CMException('farm_wrong_state')
head_vm = farm.head
try:
head_vm.name = name
head_vm.description = description
head_vm.save_vm = 2
head_vm.save()
head_vm.save_image()
head_vm.release_resources()
head_vm.remove()
head_vm.state = vm_states['closed']
head_vm.save()
except Exception:
CMException('farm_save')
node_vms = []
if farm.state == farm_states['init_head']:
for vm in farm.vms.all():
if vm.is_head():
continue
vm.release_resources()
vm.state = vm_states['closed']
else:
for vm in farm.vms.all():
node_vms.append(vm)
VM.destroy(node_vms)
try:
farm.state = farm_states['closed']
farm.save()
except:
CMException('farm_save')
示例5: destroy
# 需要导入模块: from cm.models.vm import VM [as 别名]
# 或者: from cm.models.vm.VM import destroy [as 别名]
def destroy(caller_id, vm_id_list):
"""
Method destroyes VMs with ids listed in \c vm_ids.
@cmview_admin_cm
@parameter{vm_ids,list} list of vm id's
@response{src.cm.views.utils.image.destroy()}
"""
vms = []
for vm_id in vm_id_list:
vms.append(VM.admin_get(vm_id))
return VM.destroy(vms)