argparse tests
This commit is contained in:
parent
bc12632061
commit
36f3118b94
36
snap-pg.py
36
snap-pg.py
@ -9,8 +9,9 @@ from lxml.builder import E
|
||||
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser(description='Create snapshot for libvirt machine')
|
||||
parser.add_argument('--name', required=True, help='Machine name')
|
||||
parser.add_argument('--device', required=True, help='Device path (like vda)')
|
||||
parser.add_argument('action', help='Machine name')
|
||||
# parser.add_argument('--name', required=True, help='Machine name')
|
||||
# parser.add_argument('--device', required=True, help='Device path (like vda)')
|
||||
return parser.parse_args()
|
||||
|
||||
def create_snapshot_node(disk_node):
|
||||
@ -40,25 +41,28 @@ def get_disk_by_name(vm, name):
|
||||
return disks[0]
|
||||
|
||||
def main():
|
||||
# args = parse_args()
|
||||
args = parse_args()
|
||||
session = libvirt.open('qemu:///system')
|
||||
tgtDom = 1
|
||||
print(args.action)
|
||||
|
||||
|
||||
|
||||
from time import sleep
|
||||
for i in session.listDefinedDomains():
|
||||
print(i)
|
||||
dom = session.lookupByName(i)
|
||||
# for i in session.listDefinedDomains():
|
||||
# print(i)
|
||||
# dom = session.lookupByName(i)
|
||||
|
||||
print("Is active? "+ str(dom.isActive()))
|
||||
dom.create()
|
||||
sleep(15)
|
||||
# print("Is active? "+ str(dom.isActive()))
|
||||
# dom.create()
|
||||
# sleep(15)
|
||||
|
||||
print(session.listDomainsID())
|
||||
print("Active? "+str(dom.isActive()))
|
||||
sleep(15)
|
||||
dom.shutdown()
|
||||
# print(session.listDomainsID())
|
||||
# print("Active? "+str(dom.isActive()))
|
||||
# sleep(15)
|
||||
# dom.shutdown()
|
||||
|
||||
sleep(15)
|
||||
print("Active? "+str(dom.isActive()))
|
||||
# sleep(15)
|
||||
# print("Active? "+str(dom.isActive()))
|
||||
|
||||
# print(session.getHostname())
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user