예제 #1
0
파일: instance.py 프로젝트: zzjeric/heat
    def _update_instance_type(self, prop_diff):
        flavor = prop_diff[self.INSTANCE_TYPE]
        flavor_id = self.client_plugin().find_flavor_by_name_or_id(flavor)
        handler_args = {'args': (flavor_id, )}
        checker_args = {'args': (flavor_id, )}

        prg_resize = progress.ServerUpdateProgress(self.resource_id,
                                                   'resize',
                                                   handler_extra=handler_args,
                                                   checker_extra=checker_args)
        prg_verify = progress.ServerUpdateProgress(self.resource_id,
                                                   'verify_resize')
        return prg_resize, prg_verify
예제 #2
0
 def test_extra_all_defaults(self):
     prg = progress.ServerUpdateProgress(self.server_id, self.handler)
     self._assert_common(prg)
     self.assertEqual((self.server_id, ), prg.handler_args)
     self.assertEqual((self.server_id, ), prg.checker_args)
     self.assertEqual({}, prg.handler_kwargs)
     self.assertEqual({}, prg.checker_kwargs)
예제 #3
0
 def test_handler_extra_kwargs_missing(self):
     handler_extra = {'args': ()}
     prg = progress.ServerUpdateProgress(self.server_id, self.handler,
                                         handler_extra=handler_extra)
     self._assert_common(prg)
     self.assertEqual((self.server_id,), prg.handler_args)
     self.assertEqual((self.server_id,), prg.checker_args)
     self.assertEqual({}, prg.handler_kwargs)
     self.assertEqual({}, prg.checker_kwargs)
예제 #4
0
파일: instance.py 프로젝트: zzjeric/heat
    def _update_network_interfaces(self, server, prop_diff):
        updaters = []
        new_network_ifaces = prop_diff.get(self.NETWORK_INTERFACES)
        old_network_ifaces = self.properties.get(self.NETWORK_INTERFACES)

        # if there is entrys in old_network_ifaces and new_network_ifaces,
        # remove the same entrys from old and new ifaces
        if old_network_ifaces and new_network_ifaces:
            # there are four situations:
            # 1.old includes new, such as: old = 2,3, new = 2
            # 2.new includes old, such as: old = 2,3, new = 1,2,3
            # 3.has overlaps, such as: old = 2,3, new = 1,2
            # 4.different, such as: old = 2,3, new = 1,4
            # detach unmatched ones in old, attach unmatched ones in new
            self._remove_matched_ifaces(old_network_ifaces, new_network_ifaces)
            if old_network_ifaces:
                old_nics = self._build_nics(old_network_ifaces)
                for nic in old_nics:
                    updaters.append(
                        progress.ServerUpdateProgress(
                            self.resource_id,
                            'interface_detach',
                            complete=True,
                            handler_extra={'args': (nic['port-id'], )}))
            if new_network_ifaces:
                new_nics = self._build_nics(new_network_ifaces)
                for nic in new_nics:
                    handler_kwargs = {'port_id': nic['port-id']}
                    updaters.append(
                        progress.ServerUpdateProgress(
                            self.resource_id,
                            'interface_attach',
                            complete=True,
                            handler_extra={'kwargs': handler_kwargs}))
        # if there is no change of 'NetworkInterfaces', do nothing,
        # keep the behavior as creation
        elif (old_network_ifaces
              and (self.NETWORK_INTERFACES not in prop_diff)):
            LOG.warning(
                'There is no change of "%(net_interfaces)s" '
                'for instance %(server)s, do nothing '
                'when updating.', {
                    'net_interfaces': self.NETWORK_INTERFACES,
                    'server': self.resource_id
                })
        # if the interfaces not come from property 'NetworkInterfaces',
        # the situation is somewhat complex, so to detach the old ifaces,
        # and then attach the new ones.
        else:
            subnet_id = (prop_diff.get(self.SUBNET_ID)
                         or self.properties.get(self.SUBNET_ID))
            security_groups = self._get_security_groups()
            if not server:
                server = self.client().servers.get(self.resource_id)

            interfaces = server.interface_list()
            for iface in interfaces:
                updaters.append(
                    progress.ServerUpdateProgress(
                        self.resource_id,
                        'interface_detach',
                        complete=True,
                        handler_extra={'args': (iface.port_id, )}))
            # first to delete the port which implicit-created by heat
            self._port_data_delete()
            nics = self._build_nics(new_network_ifaces,
                                    security_groups=security_groups,
                                    subnet_id=subnet_id)
            # 'SubnetId' property is empty(or None) and
            # 'NetworkInterfaces' property is empty(or None),
            # _build_nics() will return nics = None,we should attach
            # first free port, according to similar behavior during
            # instance creation
            if not nics:
                updaters.append(
                    progress.ServerUpdateProgress(self.resource_id,
                                                  'interface_attach',
                                                  complete=True))
            else:
                for nic in nics:
                    updaters.append(
                        progress.ServerUpdateProgress(self.resource_id,
                                                      'interface_attach',
                                                      complete=True,
                                                      handler_extra={
                                                          'kwargs': {
                                                              'port_id':
                                                              nic['port-id']
                                                          }
                                                      }))

        return updaters