Beispiel #1
0
    def do(self):
        for instance in self.host.instances.all():
            old_instance = instance.future_instance
            DNSAPIProvider.update_database_dns_content(
                self.infra, old_instance.dns,
                old_instance.address, instance.address
            )

            instance.dns = old_instance.dns
            old_instance.dns = old_instance.address
            old_instance.save()
            instance.save()

            if self.instance.id == instance.id:
                self.instance.dns = instance.dns

        old_host = self.host.future_host
        self.host.hostname = old_host.hostname
        old_host.hostname = old_host.address

        old_host.save()
        self.host.save()

        if self.infra.endpoint and old_host.address in self.infra.endpoint:
            self.infra.endpoint = self.infra.endpoint.replace(
                old_host.address, self.host.address
            )
            self.infra.save()
def switch_dns_forward(databaseinfra, source_object_list, ip_attribute_name,
                       dns_attribute_name, equivalent_atribute_name,
                       workflow_dict):

    for source_object in source_object_list:
        old_ip = source_object.__getattribute__(ip_attribute_name)
        dns = source_object.__getattribute__(dns_attribute_name)
        source_object.__setattr__(dns_attribute_name, old_ip)

        target_object = source_object.__getattribute__(
            equivalent_atribute_name)
        new_ip = target_object.__getattribute__(ip_attribute_name)
        target_object.__setattr__(dns_attribute_name, dns)

        LOG.info("Changing {}: from {} to {}".format(dns, old_ip, new_ip))

        DNSAPIProvider.update_database_dns_content(
            databaseinfra=databaseinfra,
            dns=dns,
            old_ip=old_ip,
            new_ip=new_ip)

        source_object.save()
        target_object.save()
        workflow_dict['objects_changed'].append({
            'source_object': source_object,
            'ip_attribute_name': ip_attribute_name,
            'dns_attribute_name': dns_attribute_name,
            'equivalent_atribute_name': equivalent_atribute_name,
        })
def switch_dns_forward(databaseinfra, source_object_list, ip_attribute_name,
                       dns_attribute_name, equivalent_atribute_name,
                       workflow_dict):

    for source_object in source_object_list:
        old_ip = source_object.__getattribute__(ip_attribute_name)
        dns = source_object.__getattribute__(dns_attribute_name)
        source_object.__setattr__(dns_attribute_name, old_ip)

        target_object = source_object.__getattribute__(
            equivalent_atribute_name)
        new_ip = target_object.__getattribute__(ip_attribute_name)
        target_object.__setattr__(dns_attribute_name, dns)

        LOG.info("Changing {}: from {} to {}".format(dns, old_ip, new_ip))

        DNSAPIProvider.update_database_dns_content(databaseinfra=databaseinfra,
                                                   dns=dns,
                                                   old_ip=old_ip,
                                                   new_ip=new_ip)

        source_object.save()
        target_object.save()
        workflow_dict['objects_changed'].append({
            'source_object':
            source_object,
            'ip_attribute_name':
            ip_attribute_name,
            'dns_attribute_name':
            dns_attribute_name,
            'equivalent_atribute_name':
            equivalent_atribute_name,
        })
Beispiel #4
0
    def undo(self, workflow_dict):
        LOG.info("Running undo...")
        try:
            databaseinfra = workflow_dict['databaseinfra']

            vip_ip = get_vip_ip_from_databaseinfra(databaseinfra=databaseinfra)

            databaseinfraattr = workflow_dict['source_secondary_ips'][0]

            dnslist = DatabaseInfraDNSList.objects.filter(
                dns__startswith="{}.".format(databaseinfra.name), type=FOXHA)
            if dnslist:
                infradns = dnslist[0]
                infradns.type = FLIPPER
                infradns.save()

                DNSAPIProvider.update_database_dns_content(
                    databaseinfra=databaseinfra,
                    dns=infradns.dns,
                    old_ip=vip_ip,
                    new_ip=databaseinfraattr.ip)

            if 'objects_changed' in workflow_dict:
                for object_changed in workflow_dict['objects_changed']:
                    switch_dns_backward(
                        databaseinfra=databaseinfra,
                        source_object_list=[
                            object_changed['source_object'],
                        ],
                        ip_attribute_name=object_changed['ip_attribute_name'],
                        dns_attribute_name=object_changed[
                            'dns_attribute_name'],
                        equivalent_atribute_name=object_changed[
                            'equivalent_atribute_name'])
                return True

            switch_dns_backward(
                databaseinfra=databaseinfra,
                source_object_list=workflow_dict['source_hosts'],
                ip_attribute_name='address',
                dns_attribute_name='hostname',
                equivalent_atribute_name='future_host')

            switch_dns_backward(
                databaseinfra=databaseinfra,
                source_object_list=workflow_dict['source_instances'],
                ip_attribute_name='address',
                dns_attribute_name='dns',
                equivalent_atribute_name='future_instance')

            return True
        except Exception:
            traceback = full_stack()

            workflow_dict['exceptions']['error_codes'].append(DBAAS_0020)
            workflow_dict['exceptions']['traceback'].append(traceback)

            return False
Beispiel #5
0
 def update_host_dns(self, origin_host, destiny_host):
     DNSAPIProvider.update_database_dns_content(self.infra,
                                                origin_host.hostname,
                                                origin_host.address,
                                                destiny_host.address)
     destiny_host.hostname = origin_host.hostname
     origin_host.hostname = origin_host.address
     origin_host.save()
     destiny_host.save()
Beispiel #6
0
 def update_instance_dns(self, origin_instance, destiny_instance):
     DNSAPIProvider.update_database_dns_content(self.infra,
                                                origin_instance.dns,
                                                origin_instance.address,
                                                destiny_instance.address)
     destiny_instance.dns = origin_instance.dns
     origin_instance.dns = origin_instance.address
     origin_instance.save()
     destiny_instance.save()
     if self.instance.id == origin_instance.id:
         self.instance.dns = origin_instance.dns
     if self.instance.id == destiny_instance.id:
         self.instance.dns = destiny_instance.dns
     if self.instance.future_instance.id == origin_instance.id:
         self.instance.future_instance.dns = origin_instance.dns
     if self.instance.future_instance.id == destiny_instance.id:
         self.instance.future_instance.dns = destiny_instance.dns
Beispiel #7
0
    def do(self, workflow_dict):
        try:
            databaseinfra = workflow_dict['databaseinfra']

            vip_ip = get_vip_ip_from_databaseinfra(databaseinfra=databaseinfra)

            databaseinfraattr = workflow_dict['source_secondary_ips'][0]

            infradns = DatabaseInfraDNSList.objects.get(
                dns__startswith="{}.".format(databaseinfra.name), type=FLIPPER)
            infradns.type = FOXHA
            infradns.save()

            DNSAPIProvider.update_database_dns_content(
                databaseinfra=databaseinfra,
                dns=infradns.dns,
                old_ip=databaseinfraattr.ip,
                new_ip=vip_ip)

            workflow_dict['objects_changed'] = []

            switch_dns_forward(
                databaseinfra=databaseinfra,
                source_object_list=workflow_dict['source_hosts'],
                ip_attribute_name='address',
                dns_attribute_name='hostname',
                equivalent_atribute_name='future_host',
                workflow_dict=workflow_dict)

            switch_dns_forward(
                databaseinfra=databaseinfra,
                source_object_list=workflow_dict['source_instances'],
                ip_attribute_name='address',
                dns_attribute_name='dns',
                equivalent_atribute_name='future_instance',
                workflow_dict=workflow_dict)

            return True
        except Exception:
            traceback = full_stack()

            workflow_dict['exceptions']['error_codes'].append(DBAAS_0020)
            workflow_dict['exceptions']['traceback'].append(traceback)

            return False
Beispiel #8
0
    def do(self):
        for instance in self.host.instances.all():
            DNSAPIProvider.update_database_dns_content(self.infra,
                                                       instance.dns,
                                                       instance.address,
                                                       self.host.address)
            instance.address = self.host.address
            instance.save()

        DNSAPIProvider.update_database_dns_content(self.infra,
                                                   self.host.hostname,
                                                   self.instance.address,
                                                   self.host.address)

        if self.infra.endpoint and self.instance.address in self.infra.endpoint:
            self.infra.endpoint = self.infra.endpoint.replace(
                self.instance.address, self.host.address)
            self.infra.save()
        self.instance.address = self.host.address
Beispiel #9
0
    def update_host_dns(self, origin_host, destiny_host):
        for instance in self.instances:
            DNSAPIProvider.update_database_dns_content(self.infra,
                                                       instance.dns,
                                                       origin_host.address,
                                                       destiny_host.address)

        DNSAPIProvider.update_database_dns_content(self.infra,
                                                   origin_host.hostname,
                                                   origin_host.address,
                                                   destiny_host.address)

        destiny_host.hostname = origin_host.hostname
        origin_host.hostname = origin_host.address
        origin_host.save()
        destiny_host.save()

        if self.infra.endpoint and origin_host.address in self.infra.endpoint:
            self.infra.endpoint = self.infra.endpoint.replace(
                origin_host.address, destiny_host.address)
            self.infra.save()
Beispiel #10
0
    def update_host_dns(self, origin_host, destiny_host):
        for instance in self.instances:
            DNSAPIProvider.update_database_dns_content(
                self.infra, instance.dns,
                origin_host.address, destiny_host.address
            )

        DNSAPIProvider.update_database_dns_content(
            self.infra, origin_host.hostname,
            origin_host.address, destiny_host.address
        )

        destiny_host.hostname = origin_host.hostname
        origin_host.hostname = origin_host.address
        origin_host.save()
        destiny_host.save()

        if self.infra.endpoint and origin_host.address in self.infra.endpoint:
            self.infra.endpoint = self.infra.endpoint.replace(
                origin_host.address, destiny_host.address
            )
            self.infra.save()
def switch_dns_backward(databaseinfra, source_object_list, ip_attribute_name,
                        dns_attribute_name, equivalent_atribute_name):

    for source_object in source_object_list:
        target_object = source_object.__getattribute__(
            equivalent_atribute_name)
        old_ip = target_object.__getattribute__(ip_attribute_name)
        dns = target_object.__getattribute__(dns_attribute_name)
        target_object.__setattr__(dns_attribute_name, old_ip)

        new_ip = source_object.__getattribute__(ip_attribute_name)
        source_object.__setattr__(dns_attribute_name, dns)

        LOG.info("Changing {}: from {} to {}".format(dns, old_ip, new_ip))

        DNSAPIProvider.update_database_dns_content(databaseinfra=databaseinfra,
                                                   dns=dns,
                                                   old_ip=old_ip,
                                                   new_ip=new_ip)

        target_object.save()
        source_object.save()
def switch_dns_backward(databaseinfra, source_object_list, ip_attribute_name,
                        dns_attribute_name, equivalent_atribute_name):

    for source_object in source_object_list:
        target_object = source_object.__getattribute__(equivalent_atribute_name)
        old_ip = target_object.__getattribute__(ip_attribute_name)
        dns = target_object.__getattribute__(dns_attribute_name)
        target_object.__setattr__(dns_attribute_name, old_ip)

        new_ip = source_object.__getattribute__(ip_attribute_name)
        source_object.__setattr__(dns_attribute_name, dns)

        LOG.info("Changing {}: from {} to {}".format(dns, old_ip, new_ip))

        DNSAPIProvider.update_database_dns_content(
            databaseinfra=databaseinfra,
            dns=dns,
            old_ip=old_ip,
            new_ip=new_ip)

        target_object.save()
        source_object.save()
Beispiel #13
0
 def update_vip_dns(self, origin_vip, destiny_vip):
     if origin_vip and destiny_vip:
         vip_dns = self.infra.endpoint_dns.split(':')[0]
         DNSAPIProvider.update_database_dns_content(self.infra, vip_dns,
                                                    origin_vip.vip_ip,
                                                    destiny_vip.vip_ip)