add shutdown option do copy_vm_xcp
This commit is contained in:
parent
1805b22476
commit
9d4456faa4
@ -43,10 +43,11 @@ class copy_vm_xcp(backup_generic):
|
|||||||
type = 'copy-vm-xcp'
|
type = 'copy-vm-xcp'
|
||||||
|
|
||||||
required_params = backup_generic.required_params + ['server_name','storage_name','password_file','vm_name','network_name']
|
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"
|
start_vm = "no"
|
||||||
max_copies = 1
|
max_copies = 1
|
||||||
|
halt_vm = "no"
|
||||||
delete_snapshot = "yes"
|
delete_snapshot = "yes"
|
||||||
|
|
||||||
def read_config(self,iniconf):
|
def read_config(self,iniconf):
|
||||||
@ -92,18 +93,29 @@ class copy_vm_xcp(backup_generic):
|
|||||||
result = (1,"error get VM opaqueref %s"%(error))
|
result = (1,"error get VM opaqueref %s"%(error))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
#do the snapshot
|
if str2bool(self.halt_vm):
|
||||||
self.logger.debug("[%s] Snapshot in progress",self.backup_name)
|
status_vm = session.xenapi.VM.get_power_state(vm)
|
||||||
try:
|
self.logger.debug("[%s] Status of VM: %s",self.backup_name,status_vm)
|
||||||
snapshot = session.xenapi.VM.snapshot(vm,"tisbackup-%s"%(vm_name))
|
if status_vm == "Running":
|
||||||
except XenAPI.Failure, error:
|
self.logger.debug("[%s] Shudown in progress",self.backup_name)
|
||||||
result = (1,"error when snapshot %s"%(error))
|
if dry_run:
|
||||||
return result
|
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:
|
||||||
|
snapshot = session.xenapi.VM.snapshot(vm,"tisbackup-%s"%(vm_name))
|
||||||
|
except XenAPI.Failure, error:
|
||||||
|
result = (1,"error when snapshot %s"%(error))
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
#get snapshot opaqueRef
|
#get snapshot opaqueRef
|
||||||
snapshot = session.xenapi.VM.get_by_name_label("tisbackup-%s"%(vm_name))[0]
|
snapshot = session.xenapi.VM.get_by_name_label("tisbackup-%s"%(vm_name))[0]
|
||||||
session.xenapi.VM.set_name_description(snapshot,"snapshot created by tisbackup on : %s"%(now.strftime("%Y-%m-%d %H:%M")))
|
session.xenapi.VM.set_name_description(snapshot,"snapshot created by tisbackup on : %s"%(now.strftime("%Y-%m-%d %H:%M")))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -218,20 +230,28 @@ class copy_vm_xcp(backup_generic):
|
|||||||
if self.delete_snapshot == 'no':
|
if self.delete_snapshot == 'no':
|
||||||
return result
|
return result
|
||||||
|
|
||||||
#delete the snapshot
|
if not str2bool(self.halt_vm):
|
||||||
try:
|
#delete the snapshot
|
||||||
for vbd in session.xenapi.VM.get_VBDs(snapshot):
|
try:
|
||||||
if session.xenapi.VBD.get_type(vbd) == 'CD' and session.xenapi.VBD.get_record(vbd)['empty'] == False:
|
for vbd in session.xenapi.VM.get_VBDs(snapshot):
|
||||||
session.xenapi.VBD.eject(vbd)
|
if session.xenapi.VBD.get_type(vbd) == 'CD' and session.xenapi.VBD.get_record(vbd)['empty'] == False:
|
||||||
|
session.xenapi.VBD.eject(vbd)
|
||||||
|
else:
|
||||||
|
vdi = session.xenapi.VBD.get_VDI(vbd)
|
||||||
|
if not 'NULL' in vdi:
|
||||||
|
session.xenapi.VDI.destroy(vdi)
|
||||||
|
session.xenapi.VM.destroy(snapshot)
|
||||||
|
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:
|
else:
|
||||||
vdi = session.xenapi.VBD.get_VDI(vbd)
|
session.xenapi.VM.start(vm,False,True)
|
||||||
if not 'NULL' in vdi:
|
|
||||||
session.xenapi.VDI.destroy(vdi)
|
|
||||||
session.xenapi.VM.destroy(snapshot)
|
|
||||||
except XenAPI.Failure, error:
|
|
||||||
result = (1,"error when destroy snapshot %s"%(error))
|
|
||||||
return result
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user