Ejemplo n.º 1
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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
def get_floatinips(nova_client):
    logger.debug("Getting Floating IPs...")
    dic_floatingips = {}
    floatingips = os_utils.get_floating_ips(nova_client)
    if not (floatingips is None or len(floatingips) == 0):
        for floatingip in floatingips:
            dic_floatingips.update({floatingip.id: floatingip.ip})
    return {'floatingips': dic_floatingips}
Ejemplo n.º 4
0
def get_floatinips(nova_client):
    logger.debug("Getting Floating IPs...")
    dic_floatingips = {}
    floatingips = os_utils.get_floating_ips(nova_client)
    if not (floatingips is None or len(floatingips) == 0):
        for floatingip in floatingips:
            dic_floatingips.update({floatingip.id: floatingip.ip})
    return {'floatingips': dic_floatingips}
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
def get_floatingips(neutron_client):
    logger.debug("Getting Floating IPs...")
    dic_floatingips = {}
    floatingips = os_utils.get_floating_ips(neutron_client)
    if not (floatingips is None or len(floatingips) == 0):
        for floatingip in floatingips:
            dic_floatingips.update(
                {floatingip['id']: floatingip['floating_ip_address']})
    return {'floatingips': dic_floatingips}
Ejemplo n.º 7
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
Ejemplo n.º 8
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
Ejemplo n.º 9
0
 def prepare_floating_ip(self):
     """Select/Create Floating IP if it doesn't exist yet"""
     self.logger.info("Retrieving floating IP for Open Baton NFVO")
     neutron_client = snaps_utils.neutron_utils.neutron_client(
         self.snaps_creds)
     # Finding Tenant ID to check to which tenant the Floating IP belongs
     tenant_id = os_utils.get_tenant_id(
         os_utils.get_keystone_client(self.creds),
         self.tenant_name)
     # Use os_utils to retrieve complete information of Floating IPs
     floating_ips = os_utils.get_floating_ips(neutron_client)
     my_floating_ips = []
     # Filter Floating IPs with tenant id
     for floating_ip in floating_ips:
         # self.logger.info("Floating IP: %s", floating_ip)
         if floating_ip.get('tenant_id') == tenant_id:
             my_floating_ips.append(floating_ip.get('floating_ip_address'))
     # Select if Floating IP exist else create new one
     if len(my_floating_ips) >= 1:
         # Get Floating IP object from snaps for clean up
         snaps_floating_ips = snaps_utils.neutron_utils.get_floating_ips(
             neutron_client)
         for my_floating_ip in my_floating_ips:
             for snaps_floating_ip in snaps_floating_ips:
                 if snaps_floating_ip.ip == my_floating_ip:
                     self.mano['details']['fip'] = snaps_floating_ip
                     self.logger.info(
                         "Selected floating IP for Open Baton NFVO %s",
                         (self.mano['details']['fip'].ip))
                     break
             if self.mano['details']['fip'] is not None:
                 break
     else:
         self.logger.info("Creating floating IP for Open Baton NFVO")
         self.mano['details']['fip'] = (
             snaps_utils.neutron_utils. create_floating_ip(
                 neutron_client, self.mano['details']['external_net_name']))
         self.logger.info(
             "Created floating IP for Open Baton NFVO %s",
             (self.mano['details']['fip'].ip))