Revision 62f0dd02 lib/cmdlib.py
b/lib/cmdlib.py | ||
---|---|---|
501 | 501 |
|
502 | 502 |
if nics: |
503 | 503 |
nic_count = len(nics) |
504 |
for idx, (ip, bridge, mac) in enumerate(nics):
|
|
504 |
for idx, (ip, mac, mode, link) in enumerate(nics):
|
|
505 | 505 |
if ip is None: |
506 | 506 |
ip = "" |
507 | 507 |
env["INSTANCE_NIC%d_IP" % idx] = ip |
508 |
env["INSTANCE_NIC%d_BRIDGE" % idx] = bridge |
|
509 | 508 |
env["INSTANCE_NIC%d_MAC" % idx] = mac |
509 |
env["INSTANCE_NIC%d_MODE" % idx] = mode |
|
510 |
env["INSTANCE_NIC%d_LINK" % idx] = link |
|
511 |
if mode == constants.NIC_MODE_BRIDGED: |
|
512 |
env["INSTANCE_NIC%d_BRIDGE" % idx] = link |
|
510 | 513 |
else: |
511 | 514 |
nic_count = 0 |
512 | 515 |
|
... | ... | |
524 | 527 |
|
525 | 528 |
return env |
526 | 529 |
|
530 |
def _PreBuildNICHooksList(lu, nics): |
|
531 |
"""Build a list of nic information tuples. |
|
532 |
|
|
533 |
This list is suitable to be passed to _BuildInstanceHookEnv. |
|
534 |
|
|
535 |
@type lu: L{LogicalUnit} |
|
536 |
@param lu: the logical unit on whose behalf we execute |
|
537 |
@type nics: list of L{objects.NIC} |
|
538 |
@param nics: list of nics to convert to hooks tuples |
|
539 |
|
|
540 |
""" |
|
541 |
hooks_nics = [] |
|
542 |
c_nicparams = lu.cfg.GetClusterInfo().nicparams[constants.PP_DEFAULT] |
|
543 |
for nic in nics: |
|
544 |
ip = nic.ip |
|
545 |
mac = nic.mac |
|
546 |
filled_params = objects.FillDict(c_nicparams, nic.nicparams) |
|
547 |
mode = filled_params[constants.NIC_MODE] |
|
548 |
link = filled_params[constants.NIC_LINK] |
|
549 |
hooks_nics.append((ip, mac, mode, link)) |
|
550 |
return hooks_nics |
|
527 | 551 |
|
528 | 552 |
def _BuildInstanceHookEnvByObject(lu, instance, override=None): |
529 | 553 |
"""Builds instance related env variables for hooks from an object. |
... | ... | |
549 | 573 |
'status': instance.admin_up, |
550 | 574 |
'memory': bep[constants.BE_MEMORY], |
551 | 575 |
'vcpus': bep[constants.BE_VCPUS], |
552 |
'nics': [(nic.ip, nic.bridge, nic.mac) for nic in instance.nics],
|
|
576 |
'nics': _PreBuildNICHooksList(lu, instance.nics),
|
|
553 | 577 |
'disk_template': instance.disk_template, |
554 | 578 |
'disks': [(disk.size, disk.mode) for disk in instance.disks], |
555 | 579 |
} |
... | ... | |
4623 | 4647 |
os_type=self.op.os_type, |
4624 | 4648 |
memory=self.be_full[constants.BE_MEMORY], |
4625 | 4649 |
vcpus=self.be_full[constants.BE_VCPUS], |
4626 |
nics=[(n.ip, n.bridge, n.mac) for n in self.nics],
|
|
4650 |
nics=_PreBuildNICHooksList(self, self.nics),
|
|
4627 | 4651 |
disk_template=self.op.disk_template, |
4628 | 4652 |
disks=[(d["size"], d["mode"]) for d in self.disks], |
4629 | 4653 |
)) |
... | ... | |
5944 | 5968 |
if self.op.nics: |
5945 | 5969 |
args['nics'] = [] |
5946 | 5970 |
nic_override = dict(self.op.nics) |
5971 |
c_nicparams = self.cluster.nicparams[constants.PP_DEFAULT] |
|
5947 | 5972 |
for idx, nic in enumerate(self.instance.nics): |
5948 | 5973 |
if idx in nic_override: |
5949 | 5974 |
this_nic_override = nic_override[idx] |
... | ... | |
5953 | 5978 |
ip = this_nic_override['ip'] |
5954 | 5979 |
else: |
5955 | 5980 |
ip = nic.ip |
5956 |
if 'bridge' in this_nic_override: |
|
5957 |
bridge = this_nic_override['bridge'] |
|
5958 |
else: |
|
5959 |
bridge = nic.bridge |
|
5960 | 5981 |
if 'mac' in this_nic_override: |
5961 | 5982 |
mac = this_nic_override['mac'] |
5962 | 5983 |
else: |
5963 | 5984 |
mac = nic.mac |
5964 |
args['nics'].append((ip, bridge, mac)) |
|
5985 |
if idx in self.nic_pnew: |
|
5986 |
nicparams = self.nic_pnew[idx] |
|
5987 |
else: |
|
5988 |
nicparams = objects.FillDict(c_nicparams, nic.nicparams) |
|
5989 |
mode = nicparams[constants.NIC_MODE] |
|
5990 |
link = nicparams[constants.NIC_LINK] |
|
5991 |
args['nics'].append((ip, mac, mode, link)) |
|
5965 | 5992 |
if constants.DDM_ADD in nic_override: |
5966 | 5993 |
ip = nic_override[constants.DDM_ADD].get('ip', None) |
5967 |
bridge = nic_override[constants.DDM_ADD]['bridge'] |
|
5968 | 5994 |
mac = nic_override[constants.DDM_ADD]['mac'] |
5969 |
args['nics'].append((ip, bridge, mac)) |
|
5995 |
nicparams = self.nic_pnew[constants.DDM_ADD] |
|
5996 |
mode = nicparams[constants.NIC_MODE] |
|
5997 |
link = nicparams[constants.NIC_LINK] |
|
5998 |
args['nics'].append((ip, mac, mode, link)) |
|
5970 | 5999 |
elif constants.DDM_REMOVE in nic_override: |
5971 | 6000 |
del args['nics'][-1] |
5972 | 6001 |
|
Also available in: Unified diff