Exemplo n.º 1
0
def delete_floating_ips():
    n = os_utils.get_nova_client()
    fips = os_utils.get_floating_ips(n)
    if fips is None:
        return
    for fip in fips:
        logger.info("Removing floating ip: {0}".format(fip.ip))
        os_utils.delete_floating_ip(n, fip.id)
Exemplo n.º 2
0
def remove_floatingips(nova_client, default_floatingips):
    logger.debug("Removing floating IPs...")
    floatingips = os_utils.get_floating_ips(nova_client)
    if floatingips is None or len(floatingips) == 0:
        logger.debug("No floating IPs found.")
        return

    init_len = len(floatingips)
    deleted = 0
    for fip in floatingips:
        fip_id = getattr(fip, 'id')
        fip_ip = getattr(fip, 'ip')
        logger.debug("'%s', ID=%s " % (fip_ip, fip_id))
        if (fip_id not in default_floatingips
                and fip_ip not in default_floatingips.values()):
            logger.debug("Removing floating IP %s ..." % fip_id)
            if os_utils.delete_floating_ip(nova_client, fip_id):
                logger.debug("  > Done!")
                deleted += 1
            else:
                logger.error("There has been a problem removing the "
                             "floating IP %s..." % fip_id)
        else:
            logger.debug("   > this is a default floating IP and will "
                         "NOT be deleted.")

    timeout = 50
    while timeout > 0:
        floatingips = os_utils.get_floating_ips(nova_client)
        if floatingips is None or len(floatingips) == (init_len - deleted):
            break
        else:
            logger.debug("Waiting for floating ips to be released...")
            timeout -= 1
            time.sleep(1)
Exemplo n.º 3
0
def remove_floatingips(nova_client, default_floatingips):
    logger.info("Removing floating IPs...")
    floatingips = os_utils.get_floating_ips(nova_client)
    if floatingips is None or len(floatingips) == 0:
        logger.debug("No floating IPs found.")
        return

    init_len = len(floatingips)
    deleted = 0
    for fip in floatingips:
        fip_id = getattr(fip, 'id')
        fip_ip = getattr(fip, 'ip')
        logger.debug("'%s', ID=%s " % (fip_ip, fip_id))
        if fip_id not in default_floatingips:
            logger.debug("Removing floating IP %s ..." % fip_id)
            if os_utils.delete_floating_ip(nova_client, fip_id):
                logger.debug("  > Done!")
                deleted += 1
            else:
                logger.error("There has been a problem removing the "
                             "floating IP %s..." % fip_id)
        else:
            logger.debug("   > this is a default floating IP and will "
                         "NOT be deleted.")

    timeout = 50
    while timeout > 0:
        floatingips = os_utils.get_floating_ips(nova_client)
        if floatingips is None or len(floatingips) == (init_len - deleted):
            break
        else:
            logger.debug("Waiting for floating ips to be released...")
            timeout -= 1
            time.sleep(1)
Exemplo n.º 4
0
def cleanup_neutron(neutron_client, floatingip_ids, bgpvpn_ids, interfaces,
                    subnet_ids, router_ids, network_ids):

    if len(floatingip_ids) != 0:
        for floatingip_id in floatingip_ids:
            if not os_utils.delete_floating_ip(neutron_client, floatingip_id):
                logging.error('Fail to delete all floating ips. '
                              'Floating ip with id {} was not deleted.'.format(
                                  floatingip_id))
                return False

    if len(bgpvpn_ids) != 0:
        for bgpvpn_id in bgpvpn_ids:
            delete_bgpvpn(neutron_client, bgpvpn_id)

    if len(interfaces) != 0:
        for router_id, subnet_id in interfaces:
            if not os_utils.remove_interface_router(neutron_client, router_id,
                                                    subnet_id):
                logging.error(
                    'Fail to delete all interface routers. '
                    'Interface router with id {} was not deleted.'.format(
                        router_id))

    if len(router_ids) != 0:
        for router_id in router_ids:
            if not os_utils.remove_gateway_router(neutron_client, router_id):
                logging.error(
                    'Fail to delete all gateway routers. '
                    'Gateway router with id {} was not deleted.'.format(
                        router_id))

    if len(subnet_ids) != 0:
        for subnet_id in subnet_ids:
            if not os_utils.delete_neutron_subnet(neutron_client, subnet_id):
                logging.error(
                    'Fail to delete all subnets. '
                    'Subnet with id {} was not deleted.'.format(subnet_id))
                return False

    if len(router_ids) != 0:
        for router_id in router_ids:
            if not os_utils.delete_neutron_router(neutron_client, router_id):
                logging.error(
                    'Fail to delete all routers. '
                    'Router with id {} was not deleted.'.format(router_id))
                return False

    if len(network_ids) != 0:
        for network_id in network_ids:
            if not os_utils.delete_neutron_net(neutron_client, network_id):
                logging.error(
                    'Fail to delete all networks. '
                    'Network with id {} was not deleted.'.format(network_id))
                return False
    return True
Exemplo n.º 5
0
    def clean(self):
        """Clean created objects/functions."""
        try:
            if not self.orchestrator['requirements']['preserve_setup']:
                self.__logger.info("Removing deployment files...")
                testresult = os.path.join(self.case_dir, 'TestResults.json')
                if os.path.exists(testresult):
                    os.remove(testresult)
                self.__logger.info("Removing %s file ", self.filename)
                if os.path.exists(self.filename):
                    os.remove(self.filename)
                self.__logger.info("Destroying Orchestrator...")
                os.system('juju destroy-controller -y abot-controller '
                          '--destroy-all-models')
        except Exception:  # pylint: disable=broad-except
            self.__logger.warn("Some issue during the undeployment ..")
            self.__logger.warn("Tenant clean continue ..")

        if not self.orchestrator['requirements']['preserve_setup']:
            self.__logger.info('Remove the Abot_epc OS object ..')
            for creator in reversed(self.created_object):
                try:
                    creator.clean()
                except Exception as exc:  # pylint: disable=broad-except
                    self.__logger.error('Unexpected error cleaning - %s', exc)

            self.__logger.info("Releasing all the floating IPs")
            floating_ips = os_utils.get_floating_ips(self.neutron_client)
            tenant_id = os_utils.get_tenant_id(self.keystone_client,
                                               self.tenant_name)
            self.__logger.info("TENANT ID : %s", tenant_id)
            for item in floating_ips:
                if item['tenant_id'] == tenant_id:
                    os_utils.delete_floating_ip(self.neutron_client,
                                                item['id'])
            self.__logger.info("Cleaning Projects and Users")
            for creator in reversed(self.created_object):
                try:
                    creator.clean()
                except Exception as exc:  # pylint: disable=broad-except
                    self.__logger.error('Unexpected error cleaning - %s', exc)
        return True
Exemplo n.º 6
0
    def clean(self):
        try:
            if not self.orchestrator['requirements']['preserve_setup']:
                self.__logger.info("Removing deployment files...")
                os.system('rm -f -- {}'.format(self.case_dir + '/' +
                                               'TestResults.json'))
                os.system("sed -i '/project-domain-name/Q' {}/abot_epc"
                          "_credential.yaml".format(self.case_dir))
                self.__logger.info("Destroying Orchestrator...")
                os.system('juju destroy-controller -y abot-controller '
                          '--destroy-all-models')
                self.__logger.info("Uninstalling dependency packages...")
        except:
            self.__logger.warn("Some issue during the undeployment ..")
            self.__logger.warn("Tenant clean continue ..")

        if not self.orchestrator['requirements']['preserve_setup']:
            self.__logger.info('Remove the Abot_epc OS object ..')
            for creator in reversed(self.created_object):
                try:
                    creator.clean()
                except Exception as exc:
                    self.__logger.error('Unexpected error cleaning - %s', exc)

            self.__logger.info("Releasing all the floating IPs")
            user_id = os_utils.get_user_id(self.keystone_client,
                                           self.tenant_name)
            floating_ips = os_utils.get_floating_ips(self.neutron_client)
            tenant_id = os_utils.get_tenant_id(self.keystone_client,
                                               self.tenant_name)
            self.__logger.info("USER ID : %s", user_id)
            self.__logger.info("FLOATING IP : %s", floating_ips)
            self.__logger.info("TENANT ID : %s", tenant_id)
            for item in floating_ips:
                if item['tenant_id'] == tenant_id:
                    os_utils.delete_floating_ip(self.neutron_client,
                                                item['id'])
            self.__logger.info("Cleaning Projects and Users")
            super(JujuEpc, self).clean()

        return True