Revision 0d2863a2 lib/hypervisor/hv_kvm.py
b/lib/hypervisor/hv_kvm.py | ||
---|---|---|
1059 | 1059 |
raise |
1060 | 1060 |
|
1061 | 1061 |
@staticmethod |
1062 |
def _ConfigureNIC(instance, seq, nic, tap):
|
|
1063 |
"""Run the network configuration script for a specified NIC
|
|
1062 |
def _CreateNICEnv(instance_name, nic, tap, seq=None, instance_tags=None):
|
|
1063 |
"""Create environment variables for a specific NIC
|
|
1064 | 1064 |
|
1065 |
@param instance: instance we're acting on |
|
1066 |
@type instance: instance object |
|
1067 |
@param seq: nic sequence number |
|
1068 |
@type seq: int |
|
1069 |
@param nic: nic we're acting on |
|
1070 |
@type nic: nic object |
|
1071 |
@param tap: the host's tap interface this NIC corresponds to |
|
1072 |
@type tap: str |
|
1065 |
This is needed during NIC ifup/ifdown scripts. |
|
1066 |
Since instance tags may change during NIC creation and removal |
|
1067 |
and because during cleanup instance object is not available we |
|
1068 |
pass them only upon NIC creation (instance startup/NIC hot-plugging). |
|
1073 | 1069 |
|
1074 | 1070 |
""" |
1075 | 1071 |
env = { |
1076 | 1072 |
"PATH": "%s:/sbin:/usr/sbin" % os.environ["PATH"], |
1077 |
"INSTANCE": instance.name,
|
|
1073 |
"INSTANCE": instance_name,
|
|
1078 | 1074 |
"MAC": nic.mac, |
1079 | 1075 |
"MODE": nic.nicparams[constants.NIC_MODE], |
1080 |
"INTERFACE": tap, |
|
1081 |
"INTERFACE_INDEX": str(seq), |
|
1082 | 1076 |
"INTERFACE_UUID": nic.uuid, |
1083 |
"TAGS": " ".join(instance.GetTags()), |
|
1084 | 1077 |
} |
1085 | 1078 |
|
1079 |
if instance_tags: |
|
1080 |
env["TAGS"] = " ".join(instance_tags) |
|
1081 |
|
|
1082 |
# This should always be available except for old instances in the |
|
1083 |
# cluster without uuid indexed tap files. |
|
1084 |
if tap: |
|
1085 |
env["INTERFACE"] = tap |
|
1086 |
|
|
1087 |
if seq: |
|
1088 |
env["INTERFACE_INDEX"] = str(seq) |
|
1089 |
|
|
1086 | 1090 |
if nic.ip: |
1087 | 1091 |
env["IP"] = nic.ip |
1088 | 1092 |
|
... | ... | |
1099 | 1103 |
if nic.nicparams[constants.NIC_MODE] == constants.NIC_MODE_BRIDGED: |
1100 | 1104 |
env["BRIDGE"] = nic.nicparams[constants.NIC_LINK] |
1101 | 1105 |
|
1106 |
return env |
|
1107 |
|
|
1108 |
@classmethod |
|
1109 |
def _ConfigureNIC(cls, instance, seq, nic, tap): |
|
1110 |
"""Run the network configuration script for a specified NIC |
|
1111 |
|
|
1112 |
@param instance: instance we're acting on |
|
1113 |
@type instance: instance object |
|
1114 |
@param seq: nic sequence number |
|
1115 |
@type seq: int |
|
1116 |
@param nic: nic we're acting on |
|
1117 |
@type nic: nic object |
|
1118 |
@param tap: the host's tap interface this NIC corresponds to |
|
1119 |
@type tap: str |
|
1120 |
|
|
1121 |
""" |
|
1122 |
env = cls._CreateNICEnv(instance.name, nic, tap, seq, instance.GetTags()) |
|
1102 | 1123 |
result = utils.RunCmd([pathutils.KVM_IFUP, tap], env=env) |
1103 | 1124 |
if result.failed: |
1104 | 1125 |
raise errors.HypervisorError("Failed to configure interface %s: %s;" |
Also available in: Unified diff