Revision 1862d460 lib/cmdlib.py
b/lib/cmdlib.py | ||
---|---|---|
2837 | 2837 |
HTYPE = constants.HTYPE_INSTANCE |
2838 | 2838 |
_OP_REQP = ["instance_name", "mem_size", "disk_size", "pnode", |
2839 | 2839 |
"disk_template", "swap_size", "mode", "start", "vcpus", |
2840 |
"wait_for_sync", "ip_check"] |
|
2840 |
"wait_for_sync", "ip_check", "mac"]
|
|
2841 | 2841 |
|
2842 | 2842 |
def BuildHooksEnv(self): |
2843 | 2843 |
"""Build hooks env. |
... | ... | |
3013 | 3013 |
raise errors.OpPrereqError("IP %s of instance %s already in use" % |
3014 | 3014 |
(hostname1.ip, instance_name)) |
3015 | 3015 |
|
3016 |
# MAC address verification |
|
3017 |
if self.op.mac != "auto": |
|
3018 |
if not utils.IsValidMac(self.op.mac.lower()): |
|
3019 |
raise errors.OpPrereqError("invalid MAC address specified: %s" % |
|
3020 |
self.op.mac) |
|
3021 |
|
|
3016 | 3022 |
# bridge verification |
3017 | 3023 |
bridge = getattr(self.op, "bridge", None) |
3018 | 3024 |
if bridge is None: |
... | ... | |
3037 | 3043 |
instance = self.op.instance_name |
3038 | 3044 |
pnode_name = self.pnode.name |
3039 | 3045 |
|
3040 |
nic = objects.NIC(bridge=self.op.bridge, mac=self.cfg.GenerateMAC()) |
|
3046 |
if self.op.mac == "auto": |
|
3047 |
mac_address=self.cfg.GenerateMAC() |
|
3048 |
else: |
|
3049 |
mac_address=self.op.mac |
|
3050 |
|
|
3051 |
nic = objects.NIC(bridge=self.op.bridge, mac=mac_address) |
|
3041 | 3052 |
if self.inst_ip is not None: |
3042 | 3053 |
nic.ip = self.inst_ip |
3043 | 3054 |
|
... | ... | |
4073 | 4084 |
self.mem = getattr(self.op, "mem", None) |
4074 | 4085 |
self.vcpus = getattr(self.op, "vcpus", None) |
4075 | 4086 |
self.ip = getattr(self.op, "ip", None) |
4087 |
self.mac = getattr(self.op, "mac", None) |
|
4076 | 4088 |
self.bridge = getattr(self.op, "bridge", None) |
4077 |
if [self.mem, self.vcpus, self.ip, self.bridge].count(None) == 4:
|
|
4089 |
if [self.mem, self.vcpus, self.ip, self.bridge, self.mac].count(None) == 5:
|
|
4078 | 4090 |
raise errors.OpPrereqError("No changes submitted") |
4079 | 4091 |
if self.mem is not None: |
4080 | 4092 |
try: |
... | ... | |
4096 | 4108 |
else: |
4097 | 4109 |
self.do_ip = False |
4098 | 4110 |
self.do_bridge = (self.bridge is not None) |
4111 |
if self.mac is not None: |
|
4112 |
if self.cfg.IsMacInUse(self.mac): |
|
4113 |
raise errors.OpPrereqError('MAC address %s already in use in cluster' % |
|
4114 |
self.mac) |
|
4115 |
if not utils.IsValidMac(self.mac): |
|
4116 |
raise errors.OpPrereqError('Invalid MAC address %s' % self.mac) |
|
4099 | 4117 |
|
4100 | 4118 |
instance = self.cfg.GetInstanceInfo( |
4101 | 4119 |
self.cfg.ExpandInstanceName(self.op.instance_name)) |
... | ... | |
4125 | 4143 |
if self.bridge: |
4126 | 4144 |
instance.nics[0].bridge = self.bridge |
4127 | 4145 |
result.append(("bridge", self.bridge)) |
4146 |
if self.mac: |
|
4147 |
instance.nics[0].mac = self.mac |
|
4148 |
result.append(("mac", self.mac)) |
|
4128 | 4149 |
|
4129 | 4150 |
self.cfg.AddInstance(instance) |
4130 | 4151 |
|
Also available in: Unified diff