def Exec(self, feedback_fn): """Add the ip pool to the cluster. """ nobj = objects.Network(name=self.op.network_name, network=self.op.network, gateway=self.op.gateway, network6=self.op.network6, gateway6=self.op.gateway6, mac_prefix=self.op.mac_prefix, uuid=self.network_uuid) # Initialize the associated address pool try: pool = network.AddressPool.InitializeNetwork(nobj) except errors.AddressPoolError as err: raise errors.OpExecError( "Cannot create IP address pool for network" " '%s': %s" % (self.op.network_name, err)) # Check if we need to reserve the nodes and the cluster master IP # These may not be allocated to any instances in routed mode, as # they wouldn't function anyway. if self.op.conflicts_check: for node in self.cfg.GetAllNodesInfo().values(): for ip in [node.primary_ip, node.secondary_ip]: try: if pool.Contains(ip): pool.Reserve(ip, external=True) self.LogInfo( "Reserved IP address of node '%s' (%s)", node.name, ip) except errors.AddressPoolError as err: self.LogWarning( "Cannot reserve IP address '%s' of node '%s': %s", ip, node.name, err) master_ip = self.cfg.GetClusterInfo().master_ip try: if pool.Contains(master_ip): pool.Reserve(master_ip, external=True) self.LogInfo("Reserved cluster master IP address (%s)", master_ip) except errors.AddressPoolError as err: self.LogWarning( "Cannot reserve cluster master IP address (%s): %s", master_ip, err) if self.op.add_reserved_ips: for ip in self.op.add_reserved_ips: try: pool.Reserve(ip, external=True) except errors.AddressPoolError as err: raise errors.OpExecError( "Cannot reserve IP address '%s': %s" % (ip, err)) if self.op.tags: for tag in self.op.tags: nobj.AddTag(tag) self.cfg.AddNetwork(nobj, self.proc.GetECId(), check_uuid=False)
def AddNewNetwork(self, uuid=None, name=None, mac_prefix=None, network=None, network6=None, gateway=None, gateway6=None, reservations=None, ext_reservations=None): """Add a new L{objects.Network} to the cluster configuration See L{objects.Network} for parameter documentation. @rtype: L{objects.Network} @return: the newly added network """ net_id = self._cur_net_id self._cur_net_id += 1 if uuid is None: uuid = self._GetUuid() if name is None: name = "mock_net_%d" % net_id if network is None: network = "198.51.100.0/24" if gateway is None: if network[-3:] == "/24": gateway = network[:-4] + "1" else: gateway = "198.51.100.1" if network[-3:] == "/24" and gateway == network[:-4] + "1": if reservations is None: reservations = "0" * 256 if ext_reservations: ext_reservations = "11" + ("0" * 253) + "1" elif reservations is None or ext_reservations is None: raise AssertionError("You have to specify 'reservations' and" " 'ext_reservations'!") net = objects.Network(uuid=uuid, name=name, mac_prefix=mac_prefix, network=network, network6=network6, gateway=gateway, gateway6=gateway6, reservations=reservations, ext_reservations=ext_reservations) self.AddNetwork(net, None) return net
def Exec(self, feedback_fn): """Add the ip pool to the cluster. """ nobj = objects.Network(name=self.op.network_name, network=self.op.network, gateway=self.op.gateway, network6=self.op.network6, gateway6=self.op.gateway6, mac_prefix=self.op.mac_prefix, uuid=self.network_uuid) # Initialize the associated address pool try: pool = network.AddressPool.InitializeNetwork(nobj) except errors.AddressPoolError, err: raise errors.OpExecError("Cannot create IP address pool for network" " '%s': %s" % (self.op.network_name, err))