add shutdown option do copy_vm_xcp

This commit is contained in:
ssamson-tis 2015-09-14 16:33:31 +02:00
parent 1805b22476
commit 9d4456faa4

View File

@ -43,10 +43,11 @@ class copy_vm_xcp(backup_generic):
type = 'copy-vm-xcp'
required_params = backup_generic.required_params + ['server_name','storage_name','password_file','vm_name','network_name']
optional_params = backup_generic.optional_params + ['start_vm','max_copies', 'delete_snapshot']
optional_params = backup_generic.optional_params + ['start_vm','max_copies', 'delete_snapshot', 'halt_vm']
start_vm = "no"
max_copies = 1
halt_vm = "no"
delete_snapshot = "yes"
def read_config(self,iniconf):
@ -92,6 +93,17 @@ class copy_vm_xcp(backup_generic):
result = (1,"error get VM opaqueref %s"%(error))
return result
if str2bool(self.halt_vm):
status_vm = session.xenapi.VM.get_power_state(vm)
self.logger.debug("[%s] Status of VM: %s",self.backup_name,status_vm)
if status_vm == "Running":
self.logger.debug("[%s] Shudown in progress",self.backup_name)
if dry_run:
print "session.xenapi.VM.clean_shutdown(vm)"
else:
session.xenapi.VM.clean_shutdown(vm)
snapshot = vm
else:
#do the snapshot
self.logger.debug("[%s] Snapshot in progress",self.backup_name)
try:
@ -218,6 +230,7 @@ class copy_vm_xcp(backup_generic):
if self.delete_snapshot == 'no':
return result
if not str2bool(self.halt_vm):
#delete the snapshot
try:
for vbd in session.xenapi.VM.get_VBDs(snapshot):
@ -231,6 +244,13 @@ class copy_vm_xcp(backup_generic):
except XenAPI.Failure, error:
result = (1,"error when destroy snapshot %s"%(error))
return result
else:
if status_vm == "Running":
self.logger.debug("[%s] Starting in progress",self.backup_name)
if dry_run:
print "session.xenapi.VM.start(vm,False,True)"
else:
session.xenapi.VM.start(vm,False,True)
return result