Revision c6407ff7 lib/hypervisor/hv_kvm.py

b/lib/hypervisor/hv_kvm.py
1058 1058
        raise
1059 1059

  
1060 1060
  @staticmethod
1061
  def _ConfigureNIC(instance, seq, nic, tap):
1062
    """Run the network configuration script for a specified NIC
1061
  def _CreateNICEnv(instance_name, nic, tap, seq=None, instance_tags=None):
1062
    """Create environment variables for a specific NIC
1063 1063

  
1064
    @param instance: instance we're acting on
1065
    @type instance: instance object
1066
    @param seq: nic sequence number
1067
    @type seq: int
1068
    @param nic: nic we're acting on
1069
    @type nic: nic object
1070
    @param tap: the host's tap interface this NIC corresponds to
1071
    @type tap: str
1064
    This is needed during NIC ifup/ifdown scripts.
1065
    Since instance tags may change during NIC creation and removal
1066
    and because during cleanup instance object is not available we
1067
    pass them only upon NIC creation (instance startup/NIC hot-plugging).
1072 1068

  
1073 1069
    """
1074 1070
    env = {
1075 1071
      "PATH": "%s:/sbin:/usr/sbin" % os.environ["PATH"],
1076
      "INSTANCE": instance.name,
1072
      "INSTANCE": instance_name,
1077 1073
      "MAC": nic.mac,
1078 1074
      "MODE": nic.nicparams[constants.NIC_MODE],
1079
      "INTERFACE": tap,
1080
      "INTERFACE_INDEX": str(seq),
1081 1075
      "INTERFACE_UUID": nic.uuid,
1082
      "TAGS": " ".join(instance.GetTags()),
1083 1076
    }
1084 1077

  
1078
    if instance_tags:
1079
      env["TAGS"] = " ".join(instance_tags)
1080

  
1081
    # This should always be available except for old instances in the
1082
    # cluster without uuid indexed tap files.
1083
    if tap:
1084
      env["INTERFACE"] = tap
1085

  
1086
    if seq:
1087
      env["INTERFACE_INDEX"] = str(seq)
1088

  
1085 1089
    if nic.ip:
1086 1090
      env["IP"] = nic.ip
1087 1091

  
......
1098 1102
    if nic.nicparams[constants.NIC_MODE] == constants.NIC_MODE_BRIDGED:
1099 1103
      env["BRIDGE"] = nic.nicparams[constants.NIC_LINK]
1100 1104

  
1105
    return env
1106

  
1107
  @classmethod
1108
  def _ConfigureNIC(cls, instance, seq, nic, tap):
1109
    """Run the network configuration script for a specified NIC
1110

  
1111
    @param instance: instance we're acting on
1112
    @type instance: instance object
1113
    @param seq: nic sequence number
1114
    @type seq: int
1115
    @param nic: nic we're acting on
1116
    @type nic: nic object
1117
    @param tap: the host's tap interface this NIC corresponds to
1118
    @type tap: str
1119

  
1120
    """
1121
    env = cls._CreateNICEnv(instance.name, nic, tap, seq, instance.GetTags())
1101 1122
    result = utils.RunCmd([pathutils.KVM_IFUP, tap], env=env)
1102 1123
    if result.failed:
1103 1124
      raise errors.HypervisorError("Failed to configure interface %s: %s;"

Also available in: Unified diff