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():
|
def parse_args():
|
||||||
parser = argparse.ArgumentParser(description='Create snapshot for libvirt machine')
|
parser = argparse.ArgumentParser(description='Create snapshot for libvirt machine')
|
||||||
parser.add_argument('--name', required=True, help='Machine name')
|
parser.add_argument('action', help='Machine name')
|
||||||
parser.add_argument('--device', required=True, help='Device path (like vda)')
|
# parser.add_argument('--name', required=True, help='Machine name')
|
||||||
|
# parser.add_argument('--device', required=True, help='Device path (like vda)')
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
def create_snapshot_node(disk_node):
|
def create_snapshot_node(disk_node):
|
||||||
@ -40,25 +41,28 @@ def get_disk_by_name(vm, name):
|
|||||||
return disks[0]
|
return disks[0]
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# args = parse_args()
|
args = parse_args()
|
||||||
session = libvirt.open('qemu:///system')
|
session = libvirt.open('qemu:///system')
|
||||||
tgtDom = 1
|
print(args.action)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
from time import sleep
|
from time import sleep
|
||||||
for i in session.listDefinedDomains():
|
# for i in session.listDefinedDomains():
|
||||||
print(i)
|
# print(i)
|
||||||
dom = session.lookupByName(i)
|
# dom = session.lookupByName(i)
|
||||||
|
|
||||||
print("Is active? "+ str(dom.isActive()))
|
# print("Is active? "+ str(dom.isActive()))
|
||||||
dom.create()
|
# dom.create()
|
||||||
sleep(15)
|
# sleep(15)
|
||||||
|
|
||||||
print(session.listDomainsID())
|
# print(session.listDomainsID())
|
||||||
print("Active? "+str(dom.isActive()))
|
# print("Active? "+str(dom.isActive()))
|
||||||
sleep(15)
|
# sleep(15)
|
||||||
dom.shutdown()
|
# dom.shutdown()
|
||||||
|
|
||||||
sleep(15)
|
# sleep(15)
|
||||||
print("Active? "+str(dom.isActive()))
|
# print("Active? "+str(dom.isActive()))
|
||||||
|
|
||||||
# print(session.getHostname())
|
# print(session.getHostname())
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user