<commit_before># -*- coding: utf-8 -*-
import logging
from dbaas_credentials.models import CredentialType
from util import get_credentials_for
from util import full_stack
from dbaas_cloudstack.models import DatabaseInfraAttr
from dbaas_cloudstack.provider import CloudStackProvider
from workflow.steps.util.base import BaseStep
from workflow.exceptions.error_codes import DBAAS_0010

LOG = logging.getLogger(__name__)


class RemoveSecondaryIp(BaseStep):
    def __unicode__(self):
        return "Removing secondary ips..."

    def do(self, workflow_dict):
        try:
            databaseinfraattr = DatabaseInfraAttr.objects.filter(
                databaseinfra=workflow_dict['databaseinfra'])

            cs_credentials = get_credentials_for(
                environment=workflow_dict['source_environment'],
                credential_type=CredentialType.CLOUDSTACK)

            networkapi_credentials = get_credentials_for(
                environment=workflow_dict['source_environment'],
                credential_type=CredentialType.NETWORKAPI)

            cs_provider = CloudStackProvider(credentials=cs_credentials,
                                             networkapi_credentials=networkapi_credentials)

            for infra_attr in databaseinfraattr:

                networkapi_equipment_id = infra_attr.networkapi_equipment_id
                networkapi_ip_id = infra_attr.networkapi_ip_id
                if networkapi_ip_id:
                    LOG.info("Removing network api IP for %s" % networkapi_ip_id)
                    ip_removed = cs_provider.remove_networkapi_ip(equipment_id=networkapi_equipment_id,
                                                                  ip_id=networkapi_ip_id)
                    if not ip_removed:
                        return False

                LOG.info("Removing secondary_ip for %s" % infra_attr.cs_ip_id)
                if not cs_provider.remove_secondary_ips(infra_attr.cs_ip_id):<commit_msg>Fix bug: this step was removing all secondary ips instead of only the olds<commit_after># -*- coding: utf-8 -*-
import logging
from dbaas_credentials.models import CredentialType
from util import get_credentials_for
from util import full_stack
from dbaas_cloudstack.models import DatabaseInfraAttr
from dbaas_cloudstack.provider import CloudStackProvider
from workflow.steps.util.base import BaseStep
from workflow.exceptions.error_codes import DBAAS_0010

LOG = logging.getLogger(__name__)


class RemoveSecondaryIp(BaseStep):
    def __unicode__(self):
        return "Removing secondary ips..."

    def do(self, workflow_dict):
        try:
            cs_credentials = get_credentials_for(
                environment=workflow_dict['source_environment'],
                credential_type=CredentialType.CLOUDSTACK)

            networkapi_credentials = get_credentials_for(
                environment=workflow_dict['source_environment'],
                credential_type=CredentialType.NETWORKAPI)

            cs_provider = CloudStackProvider(credentials=cs_credentials,
                                             networkapi_credentials=networkapi_credentials)

            for infra_attr in workflow_dict['source_secondary_ips']:

                networkapi_equipment_id = infra_attr.networkapi_equipment_id
                networkapi_ip_id = infra_attr.networkapi_ip_id
                if networkapi_ip_id:
                    LOG.info("Removing network api IP for %s" % networkapi_ip_id)
                    ip_removed = cs_provider.remove_networkapi_ip(equipment_id=networkapi_equipment_id,
                                                                  ip_id=networkapi_ip_id)
                    if not ip_removed:
                        return False

                LOG.info("Removing secondary_ip for %s" % infra_attr.cs_ip_id)
                if not cs_provider.remove_secondary_ips(infra_attr.cs_ip_id):
{'fraction_non_alphanumeric': 0.056182657773217036, 'fraction_numerical': 0.002565418163160595, 'mean_word_length': 2.405240174672489, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3020129', 'n_tokens_mistral': 1067, 'n_tokens_neox': 986, 'n_words': 197}