X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=apex%2Fclean.py;h=f56287e141b34170893f26489131e6bd29690c02;hb=4a08bfe63a3fedbd1d15119ea979080e9cdc58b8;hp=9d0e648e63fd2e73520ca7c255c92855317cb986;hpb=b12062bf50f211efb8568d0643a9c8ae33c472f6;p=apex.git diff --git a/apex/clean.py b/apex/clean.py index 9d0e648e..f56287e1 100644 --- a/apex/clean.py +++ b/apex/clean.py @@ -70,7 +70,7 @@ def clean_vms(): if domain.isActive(): logging.debug('Destroying domain') domain.destroy() - domain.undefine() + domain.undefineFlags(libvirt.VIR_DOMAIN_UNDEFINE_NVRAM) # delete storage volume try: stgvol = pool.storageVolLookupByName("{}.qcow2".format(vm)) @@ -87,12 +87,36 @@ def clean_vms(): def clean_ssh_keys(key_file='/root/.ssh/authorized_keys'): logging.info('Removing any stack pub keys from root authorized keys') + if not os.path.isfile(key_file): + logging.warning("Key file does not exist: ".format(key_file)) + return for line in fileinput.input(key_file, inplace=True): line = line.strip('\n') if 'stack@undercloud' not in line: print(line) +def clean_networks(): + logging.debug('Cleaning all network config') + for network in constants.OPNFV_NETWORK_TYPES: + logging.info("Cleaning Jump Host Network config for network " + "{}".format(network)) + jumphost.detach_interface_from_ovs(network) + jumphost.remove_ovs_bridge(network) + + conn = libvirt.open('qemu:///system') + if not conn: + raise ApexCleanException('Unable to open libvirt connection') + logging.debug('Destroying all virsh networks') + for network in conn.listNetworks(): + if network in constants.OPNFV_NETWORK_TYPES: + virsh_net = conn.networkLookupByName(network) + logging.debug("Destroying virsh network: {}".format(network)) + if virsh_net.isActive(): + virsh_net.destroy() + virsh_net.undefine() + + def main(): clean_parser = argparse.ArgumentParser() clean_parser.add_argument('-i', @@ -123,11 +147,7 @@ def main(): # Delete vbmc clean_vbmcs() # Clean network config - for network in constants.ADMIN_NETWORK, constants.EXTERNAL_NETWORK: - logging.info("Cleaning Jump Host Network config for network " - "{}".format(network)) - jumphost.detach_interface_from_ovs(network) - jumphost.remove_ovs_bridge(network) + clean_networks() # clean pub keys from root's auth keys clean_ssh_keys()