示例#1
0
 def _set_machine_id(self, client_factory, instance):
     """
     Set the machine id of the VM for guest tools to pick up and change
     the IP.
     """
     vm_ref = self._get_vm_ref_from_the_name(instance.name)
     if vm_ref is None:
         raise exception.InstanceNotFound(instance_id=instance.id)
     network = db.network_get_by_instance(context.get_admin_context(),
                                         instance['id'])
     mac_addr = instance.mac_address
     net_mask = network["netmask"]
     gateway = network["gateway"]
     ip_addr = db.instance_get_fixed_address(context.get_admin_context(),
                                         instance['id'])
     machine_id_chanfge_spec = \
         vm_util.get_machine_id_change_spec(client_factory, mac_addr,
                                     ip_addr, net_mask, gateway)
     LOG.debug(_("Reconfiguring VM instance %(name)s to set the machine id "
               "with ip - %(ip_addr)s") %
               ({'name': instance.name,
                'ip_addr': ip_addr}))
     reconfig_task = self._session._call_method(self._session._get_vim(),
                        "ReconfigVM_Task", vm_ref,
                        spec=machine_id_chanfge_spec)
     self._session._wait_for_task(instance.id, reconfig_task)
     LOG.debug(_("Reconfigured VM instance %(name)s to set the machine id "
               "with ip - %(ip_addr)s") %
               ({'name': instance.name,
                'ip_addr': ip_addr}))
示例#2
0
文件: vmops.py 项目: nicoleLiu/nova
    def _set_machine_id(self, client_factory, instance, network_info):
        """
        Set the machine id of the VM for guest tools to pick up and reconfigure
        the network interfaces.
        """
        vm_ref = self._get_vm_ref_from_the_name(instance.name)
        if vm_ref is None:
            raise exception.InstanceNotFound(instance_id=instance.id)

        machine_id_str = ''
        for (network, info) in network_info:
            # TODO(vish): add support for dns2
            # TODO(sateesh): add support for injection of ipv6 configuration
            ip_v4 = ip_v6 = None
            if 'ips' in info and len(info['ips']) > 0:
                ip_v4 = info['ips'][0]
            if 'ip6s' in info and len(info['ip6s']) > 0:
                ip_v6 = info['ip6s'][0]
            if len(info['dns']) > 0:
                dns = info['dns'][0]
            else:
                dns = ''

            interface_str = "%s;%s;%s;%s;%s;%s" % \
                                            (info['mac'],
                                             ip_v4 and ip_v4['ip'] or '',
                                             ip_v4 and ip_v4['netmask'] or '',
                                             info['gateway'],
                                             info['broadcast'],
                                             dns)
            machine_id_str = machine_id_str + interface_str + '#'

        machine_id_change_spec = \
            vm_util.get_machine_id_change_spec(client_factory, machine_id_str)

        LOG.debug(
            _("Reconfiguring VM instance %(name)s to set the machine id "
              "with ip - %(ip_addr)s") % ({
                  'name': instance.name,
                  'ip_addr': ip_v4['ip']
              }))
        reconfig_task = self._session._call_method(self._session._get_vim(),
                                                   "ReconfigVM_Task",
                                                   vm_ref,
                                                   spec=machine_id_change_spec)
        self._session._wait_for_task(instance.id, reconfig_task)
        LOG.debug(
            _("Reconfigured VM instance %(name)s to set the machine id "
              "with ip - %(ip_addr)s") % ({
                  'name': instance.name,
                  'ip_addr': ip_v4['ip']
              }))
示例#3
0
    def _set_machine_id(self, client_factory, instance, network_info):
        """
        Set the machine id of the VM for guest tools to pick up and reconfigure
        the network interfaces.
        """
        vm_ref = self._get_vm_ref_from_the_name(instance.name)
        if vm_ref is None:
            raise exception.InstanceNotFound(instance_id=instance.id)

        machine_id_str = ""
        for (network, info) in network_info:
            # TODO(vish): add support for dns2
            # TODO(sateesh): add support for injection of ipv6 configuration
            ip_v4 = ip_v6 = None
            if "ips" in info and len(info["ips"]) > 0:
                ip_v4 = info["ips"][0]
            if "ip6s" in info and len(info["ip6s"]) > 0:
                ip_v6 = info["ip6s"][0]
            if len(info["dns"]) > 0:
                dns = info["dns"][0]
            else:
                dns = ""

            interface_str = ";".join(
                [
                    info["mac"],
                    ip_v4 and ip_v4["ip"] or "",
                    ip_v4 and ip_v4["netmask"] or "",
                    info["gateway"],
                    info["broadcast"],
                    dns,
                ]
            )
            machine_id_str = machine_id_str + interface_str + "#"

        machine_id_change_spec = vm_util.get_machine_id_change_spec(client_factory, machine_id_str)

        LOG.debug(
            _("Reconfiguring VM instance to set the machine id " "with ip - %(ip_addr)s") % {"ip_addr": ip_v4["ip"]},
            instance=instance,
        )
        reconfig_task = self._session._call_method(
            self._session._get_vim(), "ReconfigVM_Task", vm_ref, spec=machine_id_change_spec
        )
        self._session._wait_for_task(instance["uuid"], reconfig_task)
        LOG.debug(
            _("Reconfigured VM instance to set the machine id " "with ip - %(ip_addr)s") % {"ip_addr": ip_v4["ip"]},
            instance=instance,
        )
示例#4
0
文件: vmops.py 项目: nicopal/nova
    def _set_machine_id(self, client_factory, instance, network_info):
        """
        Set the machine id of the VM for guest tools to pick up and reconfigure
        the network interfaces.
        """
        vm_ref = self._get_vm_ref_from_the_name(instance.name)
        if vm_ref is None:
            raise exception.InstanceNotFound(instance_id=instance.id)

        machine_id_str = ''
        for (network, info) in network_info:
            # TODO(vish): add support for dns2
            # TODO(sateesh): add support for injection of ipv6 configuration
            ip_v4 = ip_v6 = None
            if 'ips' in info and len(info['ips']) > 0:
                ip_v4 = info['ips'][0]
            if 'ip6s' in info and len(info['ip6s']) > 0:
                ip_v6 = info['ip6s'][0]
            if len(info['dns']) > 0:
                dns = info['dns'][0]
            else:
                dns = ''

            interface_str = "%s;%s;%s;%s;%s;%s" % \
                                            (info['mac'],
                                             ip_v4 and ip_v4['ip'] or '',
                                             ip_v4 and ip_v4['netmask'] or '',
                                             info['gateway'],
                                             info['broadcast'],
                                             dns)
            machine_id_str = machine_id_str + interface_str + '#'

        machine_id_change_spec = \
            vm_util.get_machine_id_change_spec(client_factory, machine_id_str)

        LOG.debug(_("Reconfiguring VM instance %(name)s to set the machine id "
                  "with ip - %(ip_addr)s") %
                  ({'name': instance.name,
                   'ip_addr': ip_v4['ip']}))
        reconfig_task = self._session._call_method(self._session._get_vim(),
                           "ReconfigVM_Task", vm_ref,
                           spec=machine_id_change_spec)
        self._session._wait_for_task(instance.id, reconfig_task)
        LOG.debug(_("Reconfigured VM instance %(name)s to set the machine id "
                  "with ip - %(ip_addr)s") %
                  ({'name': instance.name,
                   'ip_addr': ip_v4['ip']}))
示例#5
0
文件: vmops.py 项目: cp16net/reddwarf
    def _set_machine_id(self, client_factory, instance):
        """
        Set the machine id of the VM for guest tools to pick up and change
        the IP.
        """
        admin_context = context.get_admin_context()
        vm_ref = self._get_vm_ref_from_the_name(instance.name)
        if vm_ref is None:
            raise exception.InstanceNotFound(instance_id=instance.id)
        network = db.network_get_by_instance(context.get_admin_context(),
                                             instance['id'])
        mac_address = None
        if instance['mac_addresses']:
            mac_address = instance['mac_addresses'][0]['address']

        net_mask = network["netmask"]
        gateway = network["gateway"]
        broadcast = network["broadcast"]
        # TODO(vish): add support for dns2
        dns = network["dns1"]

        addresses = db.instance_get_fixed_addresses(admin_context,
                                                    instance['id'])
        ip_addr = addresses[0] if addresses else None

        machine_id_change_spec = \
            vm_util.get_machine_id_change_spec(client_factory, mac_address,
                                               ip_addr, net_mask, gateway,
                                               broadcast, dns)
        LOG.debug(
            _("Reconfiguring VM instance %(name)s to set the machine id "
              "with ip - %(ip_addr)s") % ({
                  'name': instance.name,
                  'ip_addr': ip_addr
              }))
        reconfig_task = self._session._call_method(self._session._get_vim(),
                                                   "ReconfigVM_Task",
                                                   vm_ref,
                                                   spec=machine_id_change_spec)
        self._session._wait_for_task(instance.id, reconfig_task)
        LOG.debug(
            _("Reconfigured VM instance %(name)s to set the machine id "
              "with ip - %(ip_addr)s") % ({
                  'name': instance.name,
                  'ip_addr': ip_addr
              }))
示例#6
0
文件: vmops.py 项目: YouthSun/nova
    def _set_machine_id(self, client_factory, instance):
        """
        Set the machine id of the VM for guest tools to pick up and change
        the IP.
        """
        admin_context = nova_context.get_admin_context()
        vm_ref = self._get_vm_ref_from_the_name(instance.name)
        if vm_ref is None:
            raise exception.InstanceNotFound(instance_id=instance.id)
        network = db.network_get_by_instance(nova_context.get_admin_context(),
                                            instance['id'])
        mac_address = None
        if instance['mac_addresses']:
            mac_address = instance['mac_addresses'][0]['address']

        net_mask = network["netmask"]
        gateway = network["gateway"]
        broadcast = network["broadcast"]
        # TODO(vish): add support for dns2
        dns = network["dns1"]

        addresses = db.instance_get_fixed_addresses(admin_context,
                                                    instance['id'])
        ip_addr = addresses[0] if addresses else None

        machine_id_change_spec = \
            vm_util.get_machine_id_change_spec(client_factory, mac_address,
                                               ip_addr, net_mask, gateway,
                                               broadcast, dns)
        LOG.debug(_("Reconfiguring VM instance %(name)s to set the machine id "
                  "with ip - %(ip_addr)s") %
                  ({'name': instance.name,
                   'ip_addr': ip_addr}))
        reconfig_task = self._session._call_method(self._session._get_vim(),
                           "ReconfigVM_Task", vm_ref,
                           spec=machine_id_change_spec)
        self._session._wait_for_task(instance.id, reconfig_task)
        LOG.debug(_("Reconfigured VM instance %(name)s to set the machine id "
                  "with ip - %(ip_addr)s") %
                  ({'name': instance.name,
                   'ip_addr': ip_addr}))