Exemple #1
0
    def prepare_ports_for_replace(self):
        if not self.is_using_neutron():
            return

        data = {'external_ports': [], 'internal_ports': []}
        port_data = list(
            itertools.chain(
                [('internal_ports', port) for port in self._data_get_ports()],
                [('external_ports', port)
                 for port in self._data_get_ports('external_ports')]))
        for port_type, port in port_data:
            data[port_type].append({'id': port['id']})

        # detach the ports from the server
        server_id = self.resource_id
        for port_type, port in port_data:
            self.client_plugin().interface_detach(server_id, port['id'])
            try:
                if self.client_plugin().check_interface_detach(
                        server_id, port['id']):
                    LOG.info(
                        _LI('Detach interface %(port)s successful '
                            'from server %(server)s when prepare '
                            'for replace.') % {
                                'port': port['id'],
                                'server': server_id
                            })
            except retrying.RetryError:
                raise exception.InterfaceDetachFailed(port=port['id'],
                                                      server=server_id)
 def detach_ports(self, server):
     existing_server_id = server.resource_id
     for port in self.get_all_ports(server):
         self.client_plugin().interface_detach(existing_server_id,
                                               port['id'])
         try:
             if self.client_plugin().check_interface_detach(
                     existing_server_id, port['id']):
                 LOG.info(
                     _LI('Detach interface %(port)s successful from '
                         'server %(server)s.') % {
                             'port': port['id'],
                             'server': existing_server_id
                         })
         except retrying.RetryError:
             raise exception.InterfaceDetachFailed(
                 port=port['id'], server=existing_server_id)
Exemple #3
0
    def restore_ports_after_rollback(self, convergence):
        if not self.is_using_neutron():
            return

        # In case of convergence, during rollback, the previous rsrc is
        # already selected and is being acted upon.
        backup_res = self.stack._backup_stack().resources.get(self.name)
        prev_server = self if convergence else backup_res

        if convergence:
            rsrc, rsrc_owning_stack, stack = resource.Resource.load(
                prev_server.context, prev_server.replaced_by, True,
                prev_server.stack.cache_data)
            existing_server = rsrc
        else:
            existing_server = self

        port_data = itertools.chain(
            existing_server._data_get_ports(),
            existing_server._data_get_ports('external_ports'))

        existing_server_id = existing_server.resource_id
        for port in port_data:
            # detach the ports from current resource
            self.client_plugin().interface_detach(existing_server_id,
                                                  port['id'])
            try:
                if self.client_plugin().check_interface_detach(
                        existing_server_id, port['id']):
                    LOG.info(
                        _LI('Detach interface %(port)s successful from '
                            'server %(server)s when restore after '
                            'rollback.') % {
                                'port': port['id'],
                                'server': existing_server_id
                            })
            except retrying.RetryError:
                raise exception.InterfaceDetachFailed(
                    port=port['id'], server=existing_server_id)

        # attach the ports for old resource
        prev_port_data = itertools.chain(
            prev_server._data_get_ports(),
            prev_server._data_get_ports('external_ports'))

        prev_server_id = prev_server.resource_id

        for port in prev_port_data:
            self.client_plugin().interface_attach(prev_server_id, port['id'])
            try:
                if self.client_plugin().check_interface_attach(
                        prev_server_id, port['id']):
                    LOG.info(
                        _LI('Attach interface %(port)s successful to '
                            'server %(server)s when restore after '
                            'rollback.') % {
                                'port': port['id'],
                                'server': prev_server_id
                            })
            except retrying.RetryError:
                raise exception.InterfaceAttachFailed(port=port['id'],
                                                      server=prev_server_id)