Revision 2abc8f57 lib/cmdlib.py
b/lib/cmdlib.py | ||
---|---|---|
7720 | 7720 |
if nic_mode is None: |
7721 | 7721 |
nic_mode = cluster.nicparams[constants.PP_DEFAULT][constants.NIC_MODE] |
7722 | 7722 |
|
7723 |
# bridge verification |
|
7724 |
bridge = nic.get("bridge", None) |
|
7725 |
link = nic.get("link", None) |
|
7726 |
if bridge and link: |
|
7727 |
raise errors.OpPrereqError("Cannot pass 'bridge' and 'link'" |
|
7728 |
" at the same time", errors.ECODE_INVAL) |
|
7729 |
elif bridge and nic_mode == constants.NIC_MODE_ROUTED: |
|
7730 |
raise errors.OpPrereqError("Cannot pass 'bridge' on a routed nic", |
|
7731 |
errors.ECODE_INVAL) |
|
7732 |
elif bridge: |
|
7733 |
link = bridge |
|
7734 |
|
|
7735 |
nicparams = {} |
|
7736 |
if nic_mode_req: |
|
7737 |
nicparams[constants.NIC_MODE] = nic_mode_req |
|
7738 |
if link: |
|
7739 |
nicparams[constants.NIC_LINK] = link |
|
7740 |
|
|
7723 | 7741 |
# in routed mode, for the first nic, the default ip is 'auto' |
7724 | 7742 |
if nic_mode == constants.NIC_MODE_ROUTED and idx == 0: |
7725 | 7743 |
default_ip_mode = constants.VALUE_AUTO |
... | ... | |
7736 | 7754 |
" have been skipped", |
7737 | 7755 |
errors.ECODE_INVAL) |
7738 | 7756 |
nic_ip = self.hostname1.ip |
7757 |
try: |
|
7758 |
self.cfg.ReserveIp(link, nic_ip, self.proc.GetECId()) |
|
7759 |
except errors.ReservationError: |
|
7760 |
raise errors.OpPrereqError("IP address %s already in use" |
|
7761 |
" in cluster" % nic_ip, |
|
7762 |
errors.ECODE_NOTUNIQUE) |
|
7763 |
elif ip.lower() == constants.NIC_IP_POOL: |
|
7764 |
nic_ip = self.cfg.GenerateIp(link, self.proc.GetECId()) |
|
7765 |
logging.info("Chose ip %s from pool %s" % (nic_ip, link)) |
|
7739 | 7766 |
else: |
7740 | 7767 |
if not netutils.IPAddress.IsValid(ip): |
7741 | 7768 |
raise errors.OpPrereqError("Invalid IP address '%s'" % ip, |
7742 | 7769 |
errors.ECODE_INVAL) |
7743 | 7770 |
nic_ip = ip |
7771 |
try: |
|
7772 |
self.cfg.ReserveIp(link, nic_ip, self.proc.GetECId()) |
|
7773 |
except errors.ReservationError: |
|
7774 |
raise errors.OpPrereqError("IP address %s already in use" |
|
7775 |
" in cluster" % nic_ip, |
|
7776 |
errors.ECODE_NOTUNIQUE) |
|
7744 | 7777 |
|
7745 | 7778 |
# TODO: check the ip address for uniqueness |
7746 | 7779 |
if nic_mode == constants.NIC_MODE_ROUTED and not nic_ip: |
... | ... | |
7759 | 7792 |
" in cluster" % mac, |
7760 | 7793 |
errors.ECODE_NOTUNIQUE) |
7761 | 7794 |
|
7762 |
# bridge verification |
|
7763 |
bridge = nic.get("bridge", None) |
|
7764 |
link = nic.get("link", None) |
|
7765 |
if bridge and link: |
|
7766 |
raise errors.OpPrereqError("Cannot pass 'bridge' and 'link'" |
|
7767 |
" at the same time", errors.ECODE_INVAL) |
|
7768 |
elif bridge and nic_mode == constants.NIC_MODE_ROUTED: |
|
7769 |
raise errors.OpPrereqError("Cannot pass 'bridge' on a routed nic", |
|
7770 |
errors.ECODE_INVAL) |
|
7771 |
elif bridge: |
|
7772 |
link = bridge |
|
7773 |
|
|
7774 |
nicparams = {} |
|
7775 |
if nic_mode_req: |
|
7776 |
nicparams[constants.NIC_MODE] = nic_mode_req |
|
7777 |
if link: |
|
7778 |
nicparams[constants.NIC_LINK] = link |
|
7779 |
|
|
7780 | 7795 |
check_params = cluster.SimpleFillNIC(nicparams) |
7781 | 7796 |
objects.NIC.CheckParameterSyntax(check_params) |
7782 | 7797 |
self.nics.append(objects.NIC(mac=mac, ip=nic_ip, nicparams=nicparams)) |
Also available in: Unified diff