Revision cc3a2cd9 lib/hypervisor/hv_kvm.py

b/lib/hypervisor/hv_kvm.py
1043 1043
        raise
1044 1044

  
1045 1045
  @staticmethod
1046
  def _ConfigureNIC(instance, seq, nic, tap):
1047
    """Run the network configuration script for a specified NIC
1046
  def _CreateNICEnv(instance_name, nic, tap, seq=None, instance_tags=None):
1047
    """Create environment variables for a specific NIC
1048 1048

  
1049
    @param instance: instance we're acting on
1050
    @type instance: instance object
1051
    @param seq: nic sequence number
1052
    @type seq: int
1053
    @param nic: nic we're acting on
1054
    @type nic: nic object
1055
    @param tap: the host's tap interface this NIC corresponds to
1056
    @type tap: str
1049
    This is needed during NIC ifup/ifdown scripts.
1050
    Since instance tags may change during NIC creation and removal
1051
    and because during cleanup instance object is not available we
1052
    pass them only upon NIC creation (instance startup/NIC hot-plugging).
1057 1053

  
1058 1054
    """
1059 1055
    env = {
1060 1056
      "PATH": "%s:/sbin:/usr/sbin" % os.environ["PATH"],
1061
      "INSTANCE": instance.name,
1057
      "INSTANCE": instance_name,
1062 1058
      "MAC": nic.mac,
1063 1059
      "MODE": nic.nicparams[constants.NIC_MODE],
1064
      "INTERFACE": tap,
1065
      "INTERFACE_INDEX": str(seq),
1066 1060
      "INTERFACE_UUID": nic.uuid,
1067
      "TAGS": " ".join(instance.GetTags()),
1068 1061
    }
1069 1062

  
1063
    if instance_tags:
1064
      env["TAGS"] = " ".join(instance_tags)
1065

  
1066
    # This should always be available except for old instances in the
1067
    # cluster without uuid indexed tap files.
1068
    if tap:
1069
      env["INTERFACE"] = tap
1070

  
1071
    if seq:
1072
      env["INTERFACE_INDEX"] = str(seq)
1073

  
1070 1074
    if nic.ip:
1071 1075
      env["IP"] = nic.ip
1072 1076

  
......
1083 1087
    if nic.nicparams[constants.NIC_MODE] == constants.NIC_MODE_BRIDGED:
1084 1088
      env["BRIDGE"] = nic.nicparams[constants.NIC_LINK]
1085 1089

  
1090
    return env
1091

  
1092
  @classmethod
1093
  def _ConfigureNIC(cls, instance, seq, nic, tap):
1094
    """Run the network configuration script for a specified NIC
1095

  
1096
    @param instance: instance we're acting on
1097
    @type instance: instance object
1098
    @param seq: nic sequence number
1099
    @type seq: int
1100
    @param nic: nic we're acting on
1101
    @type nic: nic object
1102
    @param tap: the host's tap interface this NIC corresponds to
1103
    @type tap: str
1104

  
1105
    """
1106
    env = cls._CreateNICEnv(instance.name, nic, tap, seq, instance.GetTags())
1086 1107
    result = utils.RunCmd([pathutils.KVM_IFUP, tap], env=env)
1087 1108
    if result.failed:
1088 1109
      raise errors.HypervisorError("Failed to configure interface %s: %s;"

Also available in: Unified diff