summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Eckersberg <jeckersb@redhat.com>2009-02-09 14:29:31 -0500
committerJohn Eckersberg <jeckersb@redhat.com>2009-03-13 13:52:34 -0400
commitbfdd7754c875ae8ff88471f58d5238b82760f33e (patch)
treec61c94e3d0f0748eb9ca4d421040719886266884
parent34cdbe58d22b842eab7b2284e1a0d9bbe9de240c (diff)
downloadcobbler-bfdd7754c875ae8ff88471f58d5238b82760f33e.tar.gz
cobbler-bfdd7754c875ae8ff88471f58d5238b82760f33e.tar.xz
cobbler-bfdd7754c875ae8ff88471f58d5238b82760f33e.zip
broken state!
-rw-r--r--cobbler/item_network.py60
-rw-r--r--cobbler/item_system.py11
-rw-r--r--cobbler/modules/cli_network.py7
-rw-r--r--cobbler/modules/cli_system.py5
4 files changed, 75 insertions, 8 deletions
diff --git a/cobbler/item_network.py b/cobbler/item_network.py
index 0c784add..8acfa6d6 100644
--- a/cobbler/item_network.py
+++ b/cobbler/item_network.py
@@ -88,12 +88,6 @@ class Network(item.Item):
# def set_free_addresses(self, free_addresses):
# pass
- def take_new_address(self, address):
- pass
-
- def free_address(self, address):
- pass
-
def subtract_and_flatten(self, cidr_list, remove_list):
for item in remove_list:
for i in range(len(cidr_list)):
@@ -103,6 +97,51 @@ class Network(item.Item):
break
return cidr_list
+ def add_existing_interfaces(self):
+ for s in self.config.systems():
+ for i in s.interfaces:
+ pass
+
+ def remove_existing_interfaces(self):
+ for s in self.config.systems():
+ for i in s.interfaces:
+ pass
+
+ def add_interface(self, system, interface):
+ ip = interface['ip_address']
+ if ip == 'auto' or ip == '' or ip == None:
+ return self.add_auto_interface(system, interface)
+
+ ip = _IP(ip)
+ if ip not in self.cidr:
+ raise CX(_("Address (%s) not in %s (%s)" % (ip,
+ self.name,
+ self.cidr)))
+ available = False
+ for block in self.free_addresses:
+ if ip in block:
+ available = True
+ break
+ if not available:
+ raise CX(_("Address %s is not free in network %s" % (ip, self.name)))
+
+ self.used_addresses.append(ip)
+ print self.used_addresses
+ self.update_free()
+ print self.used_addresses
+
+ def sync(self, action):
+ if action == 'add':
+ self.add_existing_interfaces()
+ elif action == 'edit':
+ # horribly inefficient
+ self.remove_existing_interfaces()
+ self.add_existing_interfaces()
+ elif action == 'remove':
+ self.remove_existing_interfaces()
+
+ self.update_free()
+
def update_free(self):
free = [self.cidr]
@@ -125,12 +164,19 @@ class Network(item.Item):
def is_valid(self):
"""
- A network is valid if it has a name and a CIDR
+ A network is valid if:
+ * it has a name and a CIDR
+ * it does not overlap another network
"""
if self.name is None:
raise CX(_("name is required"))
if self.cidr is None:
raise CX(_("cidr is required"))
+ for other in self.config.networks():
+ if other.name == self.name:
+ continue
+ if self.cidr in other.cidr or other.cidr in self.cidr:
+ raise CX(_("cidr %s overlaps with network %s (%s)" % (self.cidr, other.name, other.cidr)))
return True
def to_datastruct(self):
diff --git a/cobbler/item_system.py b/cobbler/item_system.py
index b7e77448..8eafa2e3 100644
--- a/cobbler/item_system.py
+++ b/cobbler/item_system.py
@@ -111,6 +111,7 @@ class System(item.Item):
"bonding_opts" : "",
"dns_name" : "",
"static_routes" : [],
+ "parent" : "",
}
return self.interfaces[name]
@@ -426,6 +427,16 @@ class System(item.Item):
intf["static"] = utils.input_boolean(truthiness)
return True
+ def set_network(self,network,interface):
+ """
+ Add an interface to a network object
+ """
+ intf = self.__get_interface(interface)
+ net = self.config.networks().find(name=network)
+ if net == None:
+ raise CX(_("Network %s does not exist" % network))
+ net.add_interface(self, intf)
+
def set_ip_address(self,address,interface):
"""
Assign a IP or hostname in DHCP when this MAC boots.
diff --git a/cobbler/modules/cli_network.py b/cobbler/modules/cli_network.py
index 16575052..ee18f59c 100644
--- a/cobbler/modules/cli_network.py
+++ b/cobbler/modules/cli_network.py
@@ -107,7 +107,12 @@ class NetworkFunction(commands.CobblerFunction):
if self.options.comment is not None:
obj.set_comment(self.options.comment)
- obj.update_free()
+ if 'add' in self.args:
+ obj.sync('add')
+ elif 'edit' in self.args:
+ obj.sync('edit')
+ elif 'remove' in self.args:
+ obj.sync('remove')
return self.object_manipulator_finish(obj, self.api.networks, self.options)
diff --git a/cobbler/modules/cli_system.py b/cobbler/modules/cli_system.py
index 7c0924ed..0b00a11b 100644
--- a/cobbler/modules/cli_system.py
+++ b/cobbler/modules/cli_system.py
@@ -87,6 +87,9 @@ class SystemFunction(commands.CobblerFunction):
if not self.matches_args(args,["dumpvars","poweron","poweroff","reboot","remove","report","getks","list"]):
p.add_option("--netboot-enabled", dest="netboot_enabled", help="PXE on (1) or off (0)")
+ if self.matches_args(args,["add","edit"]):
+ p.add_option("--network", dest="network", help="network object")
+
if self.matches_args(args,["copy","rename"]):
p.add_option("--newname", dest="newname", help="for use with copy/edit")
@@ -229,6 +232,8 @@ class SystemFunction(commands.CobblerFunction):
obj.set_bonding_opts(self.options.bonding_opts, my_interface)
if self.options.static_routes is not None:
obj.set_static_routes(self.options.static_routes, my_interface)
+ if self.options.network is not None:
+ obj.set_network(self.options.network, my_interface)
if self.options.delete_interface is not None:
success = obj.delete_interface(self.options.delete_interface)