Etalon atnevezes, snapshot create/remove
This commit is contained in:
parent
4cd15a9423
commit
831cb45d1a
12
etalon
12
etalon
@ -83,7 +83,7 @@ if (!defined $opts{site}) {
|
|||||||
if (!exists $site_conf{$opts{site}}) {
|
if (!exists $site_conf{$opts{site}}) {
|
||||||
die "site not found: $opts{site}\n";
|
die "site not found: $opts{site}\n";
|
||||||
}
|
}
|
||||||
for my $o (qw(dns ntp domain clone_ip mgmt_ssh_key postfix_relayhost)) {
|
for my $o (qw(dns ntp domain clone_ip mgmt_ssh_key postfix_relayhost rhsm_user rhsm_passwd)) {
|
||||||
if (!defined $opts{$o}) {
|
if (!defined $opts{$o}) {
|
||||||
$opts{$o} = $site_conf{$opts{site}}->{$o};
|
$opts{$o} = $site_conf{$opts{site}}->{$o};
|
||||||
}
|
}
|
||||||
@ -152,6 +152,10 @@ if ($opts{border_dbpasswd}) {
|
|||||||
if ($opts{postfix_relayhost}) {
|
if ($opts{postfix_relayhost}) {
|
||||||
push @vars, "postfix_relayhost=$opts{postfix_relayhost}";
|
push @vars, "postfix_relayhost=$opts{postfix_relayhost}";
|
||||||
}
|
}
|
||||||
|
if ($opts{rhsm_user} and $opts{rhsm_passwd}) {
|
||||||
|
push @vars, "rhsm_user=$opts{rhsm_user}";
|
||||||
|
push @vars, "rhsm_passwd=$opts{rhsm_passwd}";
|
||||||
|
}
|
||||||
|
|
||||||
if ($opts{tmpip}) {
|
if ($opts{tmpip}) {
|
||||||
if (!$opts{tmpip_skip}) {
|
if (!$opts{tmpip_skip}) {
|
||||||
@ -159,14 +163,14 @@ if ($opts{tmpip}) {
|
|||||||
$opts{tmpgw} = $opts{tmpip};
|
$opts{tmpgw} = $opts{tmpip};
|
||||||
$opts{tmpgw} =~ s/\.\d+$/.254/;
|
$opts{tmpgw} =~ s/\.\d+$/.254/;
|
||||||
}
|
}
|
||||||
my $cmd = "ansible -i etalon-debian, -e ansible_host=$opts{clone_ip} ".
|
my $cmd = "ansible -i etalon, -e ansible_host=$opts{clone_ip} ".
|
||||||
"-u root -B 30 -P 0 -m shell -a '".
|
"-u root -B 30 -P 0 -m shell -a '".
|
||||||
"sleep 3; DEV=\$(cd /sys/class/net; \\ls -1d e* | head -1);".
|
"sleep 3; DEV=\$(cd /sys/class/net; \\ls -1d e* | head -1);".
|
||||||
"ip a flu dev \$DEV; ".
|
"ip a flu dev \$DEV; ".
|
||||||
"ip a add $opts{tmpip}/$opts{tmpmask} dev \$DEV; ".
|
"ip a add $opts{tmpip}/$opts{tmpmask} dev \$DEV; ".
|
||||||
"ip r add default via $opts{tmpgw}; ".
|
"ip r add default via $opts{tmpgw}; ".
|
||||||
"ping -c 3 $opts{tmpgw}".
|
"ping -c 3 $opts{tmpgw}".
|
||||||
"' etalon-debian";
|
"' etalon";
|
||||||
print "$cmd\n";
|
print "$cmd\n";
|
||||||
system $cmd;
|
system $cmd;
|
||||||
exit 1 if $? > 0;
|
exit 1 if $? > 0;
|
||||||
@ -197,7 +201,7 @@ my $skip = '';
|
|||||||
if (scalar @skip) {
|
if (scalar @skip) {
|
||||||
$skip = "--skip-tags=". join(',', @skip);
|
$skip = "--skip-tags=". join(',', @skip);
|
||||||
}
|
}
|
||||||
my $cmd = "ansible-playbook -i etalon-debian, -e ansible_host=$opts{clone_ip} $skip $vars etalon.yml";
|
my $cmd = "ansible-playbook -i etalon, -e ansible_host=$opts{clone_ip} $skip $vars etalon.yml";
|
||||||
|
|
||||||
print "$cmd\n";
|
print "$cmd\n";
|
||||||
system $cmd;
|
system $cmd;
|
||||||
|
|||||||
103
vmw_snapshot_create
Executable file
103
vmw_snapshot_create
Executable file
@ -0,0 +1,103 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
from pyVmomi import vim
|
||||||
|
import pyVim.connect
|
||||||
|
import atexit
|
||||||
|
import argparse
|
||||||
|
from pprint import pprint
|
||||||
|
import sys
|
||||||
|
import siteconf
|
||||||
|
|
||||||
|
site_conf = siteconf.read()
|
||||||
|
|
||||||
|
|
||||||
|
def get_args():
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description='Creates a vm snapshot.')
|
||||||
|
|
||||||
|
parser.add_argument('-s', '--site',
|
||||||
|
required=True,
|
||||||
|
action='store',
|
||||||
|
help='name of the site to connect to')
|
||||||
|
|
||||||
|
parser.add_argument('-v', '--vm',
|
||||||
|
required=True,
|
||||||
|
action='store',
|
||||||
|
help='vm to create snapshot of')
|
||||||
|
|
||||||
|
parser.add_argument('-n', '--snapshotname',
|
||||||
|
required=True,
|
||||||
|
action='store',
|
||||||
|
help='snapshot name')
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
return args
|
||||||
|
|
||||||
|
def get_obj(content, vimtype, name):
|
||||||
|
"""
|
||||||
|
Return an object by name, if name is None the
|
||||||
|
first found object is returned
|
||||||
|
"""
|
||||||
|
obj = None
|
||||||
|
container = content.viewManager.CreateContainerView(
|
||||||
|
content.rootFolder, vimtype, True)
|
||||||
|
for c in container.view:
|
||||||
|
if name:
|
||||||
|
if c.name == name:
|
||||||
|
obj = c
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
obj = c
|
||||||
|
break
|
||||||
|
return obj
|
||||||
|
|
||||||
|
|
||||||
|
def wait_for_task(task):
|
||||||
|
""" wait for a vCenter task to finish """
|
||||||
|
task_done = False
|
||||||
|
while not task_done:
|
||||||
|
if task.info.state == 'success':
|
||||||
|
return task.info.result
|
||||||
|
|
||||||
|
if task.info.state == 'error':
|
||||||
|
print("there was an error")
|
||||||
|
task_done = True
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
args = get_args()
|
||||||
|
|
||||||
|
if not args.site in site_conf:
|
||||||
|
print(f"site not found: {args.site}")
|
||||||
|
exit(1)
|
||||||
|
host = site_conf[args.site]['vcenter']
|
||||||
|
user = site_conf[args.site]['vcenter_user']
|
||||||
|
passwd = site_conf[args.site]['vcenter_passwd']
|
||||||
|
|
||||||
|
|
||||||
|
si = pyVim.connect.SmartConnect(
|
||||||
|
host = host,
|
||||||
|
user = user,
|
||||||
|
pwd = passwd,
|
||||||
|
disableSslCertValidation = True
|
||||||
|
)
|
||||||
|
atexit.register(pyVim.connect.Disconnect, si)
|
||||||
|
content = si.RetrieveContent()
|
||||||
|
|
||||||
|
vm = get_obj(content, [vim.VirtualMachine], args.vm)
|
||||||
|
if not vm:
|
||||||
|
print("vm not found")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
description = 'vmw_snapshot_create'
|
||||||
|
dump_memory = True
|
||||||
|
quiesce = False
|
||||||
|
|
||||||
|
wait_for_task(vm.CreateSnapshot(
|
||||||
|
args.snapshotname, description, dump_memory, quiesce
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
||||||
|
# vim: set tabstop=4 shiftwidth=4 expandtab smarttab:
|
||||||
114
vmw_snapshot_remove
Executable file
114
vmw_snapshot_remove
Executable file
@ -0,0 +1,114 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
from pyVmomi import vim
|
||||||
|
import pyVim.connect
|
||||||
|
import atexit
|
||||||
|
import argparse
|
||||||
|
from pprint import pprint
|
||||||
|
import sys
|
||||||
|
import siteconf
|
||||||
|
|
||||||
|
site_conf = siteconf.read()
|
||||||
|
|
||||||
|
|
||||||
|
def get_args():
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description='Deletes a vm snapshot.')
|
||||||
|
|
||||||
|
parser.add_argument('-s', '--site',
|
||||||
|
required=True,
|
||||||
|
action='store',
|
||||||
|
help='name of the site to connect to')
|
||||||
|
|
||||||
|
parser.add_argument('-v', '--vm',
|
||||||
|
required=True,
|
||||||
|
action='store',
|
||||||
|
help='vm to delete snapshot from')
|
||||||
|
|
||||||
|
parser.add_argument('-n', '--snapshotname',
|
||||||
|
required=True,
|
||||||
|
action='store',
|
||||||
|
help='snapshot name')
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
return args
|
||||||
|
|
||||||
|
def get_obj(content, vimtype, name):
|
||||||
|
"""
|
||||||
|
Return an object by name, if name is None the
|
||||||
|
first found object is returned
|
||||||
|
"""
|
||||||
|
obj = None
|
||||||
|
container = content.viewManager.CreateContainerView(
|
||||||
|
content.rootFolder, vimtype, True)
|
||||||
|
for c in container.view:
|
||||||
|
if name:
|
||||||
|
if c.name == name:
|
||||||
|
obj = c
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
obj = c
|
||||||
|
break
|
||||||
|
return obj
|
||||||
|
|
||||||
|
|
||||||
|
def wait_for_task(task):
|
||||||
|
""" wait for a vCenter task to finish """
|
||||||
|
task_done = False
|
||||||
|
while not task_done:
|
||||||
|
if task.info.state == 'success':
|
||||||
|
return task.info.result
|
||||||
|
|
||||||
|
if task.info.state == 'error':
|
||||||
|
print("there was an error")
|
||||||
|
task_done = True
|
||||||
|
|
||||||
|
|
||||||
|
def find_snapshots(snapshots, name):
|
||||||
|
snap_obj = []
|
||||||
|
for snapshot in snapshots:
|
||||||
|
if snapshot.name == name:
|
||||||
|
snap_obj.append(snapshot)
|
||||||
|
snap_obj = snap_obj + find_snapshots(
|
||||||
|
snapshot.childSnapshotList, name)
|
||||||
|
return snap_obj
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
args = get_args()
|
||||||
|
|
||||||
|
if not args.site in site_conf:
|
||||||
|
print(f"site not found: {args.site}")
|
||||||
|
exit(1)
|
||||||
|
host = site_conf[args.site]['vcenter']
|
||||||
|
user = site_conf[args.site]['vcenter_user']
|
||||||
|
passwd = site_conf[args.site]['vcenter_passwd']
|
||||||
|
|
||||||
|
|
||||||
|
si = pyVim.connect.SmartConnect(
|
||||||
|
host = host,
|
||||||
|
user = user,
|
||||||
|
pwd = passwd,
|
||||||
|
disableSslCertValidation = True
|
||||||
|
)
|
||||||
|
atexit.register(pyVim.connect.Disconnect, si)
|
||||||
|
content = si.RetrieveContent()
|
||||||
|
|
||||||
|
vm = get_obj(content, [vim.VirtualMachine], args.vm)
|
||||||
|
if vm == None:
|
||||||
|
print("vm not found: "+ args.vm)
|
||||||
|
exit(1)
|
||||||
|
if vm.snapshot is None:
|
||||||
|
print("vm has no snapshots: "+ args.vm)
|
||||||
|
exit(1)
|
||||||
|
snaplist = find_snapshots(vm.snapshot.rootSnapshotList, args.snapshotname)
|
||||||
|
for s in snaplist:
|
||||||
|
print(f"removing {args.vm} snapshot {s.name} ({s.createTime})")
|
||||||
|
remove_children = False
|
||||||
|
consolidate = True
|
||||||
|
wait_for_task(s.snapshot.RemoveSnapshot_Task(remove_children, consolidate))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
||||||
|
# vim: set tabstop=4 shiftwidth=4 expandtab smarttab:
|
||||||
Loading…
x
Reference in New Issue
Block a user