aboutsummaryrefslogtreecommitdiffstats
path: root/os_net_config/objects.py
diff options
context:
space:
mode:
authorDan Prince <dprince@redhat.com>2014-06-09 10:42:19 -0400
committerDan Prince <dprince@redhat.com>2014-06-09 10:42:19 -0400
commit846e00d0072533e817c3d2248834e3b3ac5cae98 (patch)
treeb057b0161c2f1c1b8faa06acf7eeba92906a568c /os_net_config/objects.py
parent8d3dc898425810a3399a6c2718c35c536137b22e (diff)
Add interface, address, and route objects
Add some initial objects for interfaces, routes and addresses.
Diffstat (limited to 'os_net_config/objects.py')
-rw-r--r--os_net_config/objects.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/os_net_config/objects.py b/os_net_config/objects.py
new file mode 100644
index 0000000..8c1fcd5
--- /dev/null
+++ b/os_net_config/objects.py
@@ -0,0 +1,66 @@
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+import netaddr
+
+
+class NetworkObjectException(Exception):
+ pass
+
+
+class Route(object):
+ """Base class for network routes."""
+
+ def __init__(self, netmask_cidr, gateway):
+ self.netmask_cidr = netmask_cidr
+ self.gateway = gateway
+
+
+class Address(object):
+ """Base class for network addresses."""
+
+ def __init__(self, ip_netmask, routes=[]):
+ self.ip_netmask = ip_netmask
+ ip_nw = netaddr.IPNetwork(self.ip_netmask)
+ self.ip = str(ip_nw.ip)
+ self.netmask = str(ip_nw.netmask)
+ self.version = ip_nw.version
+ self.routes = routes
+
+
+class Interface(object):
+ """Base class for network interfaces."""
+
+ def __init__(self, name, use_dhcp=False, use_dhcpv6=False, addresses=[],
+ mtu=1500):
+ self.name = name
+ self.mtu = mtu
+ self.use_dhcp = use_dhcp
+ self.addresses = addresses
+ self.bridge = None
+ self.type = None
+
+ def v4_addresses(self):
+ v4_addresses = []
+ for addr in self.addresses:
+ if addr.version == 4:
+ v4_addresses.append(addr)
+
+ return v4_addresses
+
+ def v6_addresses(self):
+ v6_addresses = []
+ for addr in self.addresses:
+ if addr.version == 6:
+ v6_addresses.append(addr)
+
+ return v6_addresses