summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--os_net_config/__init__.py2
-rw-r--r--os_net_config/objects.py66
-rw-r--r--os_net_config/tests/__init__.py2
-rw-r--r--os_net_config/tests/base.py9
-rw-r--r--os_net_config/tests/test_os_net_config.py2
-rw-r--r--requirements.txt3
-rwxr-xr-xsetup.py2
-rw-r--r--test-requirements.txt4
8 files changed, 83 insertions, 7 deletions
diff --git a/os_net_config/__init__.py b/os_net_config/__init__.py
index 5f946b8..dbc60ab 100644
--- a/os_net_config/__init__.py
+++ b/os_net_config/__init__.py
@@ -16,4 +16,4 @@ import pbr.version
__version__ = pbr.version.VersionInfo(
- 'os_net_config').version_string() \ No newline at end of file
+ 'os_net_config').version_string()
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
diff --git a/os_net_config/tests/__init__.py b/os_net_config/tests/__init__.py
index f88664e..19f5e72 100644
--- a/os_net_config/tests/__init__.py
+++ b/os_net_config/tests/__init__.py
@@ -10,4 +10,4 @@
# 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. \ No newline at end of file
+# under the License.
diff --git a/os_net_config/tests/base.py b/os_net_config/tests/base.py
index 3bf12a8..c8ad7c4 100644
--- a/os_net_config/tests/base.py
+++ b/os_net_config/tests/base.py
@@ -18,6 +18,7 @@
import os
import fixtures
+import stubout
import testtools
_TRUE_VALUES = ('True', 'true', '1', 'yes')
@@ -31,6 +32,7 @@ class TestCase(testtools.TestCase):
"""Run before each test method to initialize test environment."""
super(TestCase, self).setUp()
+ self.stubs = stubout.StubOutForTesting()
test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0)
try:
test_timeout = int(test_timeout)
@@ -50,4 +52,9 @@ class TestCase(testtools.TestCase):
stderr = self.useFixture(fixtures.StringStream('stderr')).stream
self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))
- self.log_fixture = self.useFixture(fixtures.FakeLogger()) \ No newline at end of file
+ self.log_fixture = self.useFixture(fixtures.FakeLogger())
+
+ def tearDown(self):
+ self.stubs.UnsetAll()
+ self.stubs.SmartUnsetAll()
+ super(TestCase, self).tearDown()
diff --git a/os_net_config/tests/test_os_net_config.py b/os_net_config/tests/test_os_net_config.py
index f9fd95e..384dc2c 100644
--- a/os_net_config/tests/test_os_net_config.py
+++ b/os_net_config/tests/test_os_net_config.py
@@ -25,4 +25,4 @@ from os_net_config.tests import base
class TestOs_net_config(base.TestCase):
def test_something(self):
- pass \ No newline at end of file
+ pass
diff --git a/requirements.txt b/requirements.txt
index 8646341..8883e46 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,2 +1,3 @@
pbr>=0.5.21,<1.0
-Babel>=0.9.6 \ No newline at end of file
+Babel>=0.9.6
+netaddr>=0.7.6
diff --git a/setup.py b/setup.py
index 7eeb36b..70c2b3f 100755
--- a/setup.py
+++ b/setup.py
@@ -19,4 +19,4 @@ import setuptools
setuptools.setup(
setup_requires=['pbr'],
- pbr=True) \ No newline at end of file
+ pbr=True)
diff --git a/test-requirements.txt b/test-requirements.txt
index 2a46bd8..07c4914 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -8,4 +8,6 @@ sphinx>=1.1.2
oslosphinx
testrepository>=0.0.17
testscenarios>=0.4,<0.5
-testtools>=0.9.32 \ No newline at end of file
+testtools>=0.9.32
+mock>=1.0
+mox>=0.5.3