Add interface, address, and route objects
Add some initial objects for interfaces, routes and addresses.
This commit is contained in:
@@ -16,4 +16,4 @@ import pbr.version
|
|||||||
|
|
||||||
|
|
||||||
__version__ = pbr.version.VersionInfo(
|
__version__ = pbr.version.VersionInfo(
|
||||||
'os_net_config').version_string()
|
'os_net_config').version_string()
|
||||||
|
|||||||
66
os_net_config/objects.py
Normal file
66
os_net_config/objects.py
Normal file
@@ -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
|
||||||
@@ -10,4 +10,4 @@
|
|||||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
import fixtures
|
import fixtures
|
||||||
|
import stubout
|
||||||
import testtools
|
import testtools
|
||||||
|
|
||||||
_TRUE_VALUES = ('True', 'true', '1', 'yes')
|
_TRUE_VALUES = ('True', 'true', '1', 'yes')
|
||||||
@@ -31,6 +32,7 @@ class TestCase(testtools.TestCase):
|
|||||||
"""Run before each test method to initialize test environment."""
|
"""Run before each test method to initialize test environment."""
|
||||||
|
|
||||||
super(TestCase, self).setUp()
|
super(TestCase, self).setUp()
|
||||||
|
self.stubs = stubout.StubOutForTesting()
|
||||||
test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0)
|
test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0)
|
||||||
try:
|
try:
|
||||||
test_timeout = int(test_timeout)
|
test_timeout = int(test_timeout)
|
||||||
@@ -50,4 +52,9 @@ class TestCase(testtools.TestCase):
|
|||||||
stderr = self.useFixture(fixtures.StringStream('stderr')).stream
|
stderr = self.useFixture(fixtures.StringStream('stderr')).stream
|
||||||
self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))
|
self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))
|
||||||
|
|
||||||
self.log_fixture = self.useFixture(fixtures.FakeLogger())
|
self.log_fixture = self.useFixture(fixtures.FakeLogger())
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
self.stubs.UnsetAll()
|
||||||
|
self.stubs.SmartUnsetAll()
|
||||||
|
super(TestCase, self).tearDown()
|
||||||
|
|||||||
@@ -25,4 +25,4 @@ from os_net_config.tests import base
|
|||||||
class TestOs_net_config(base.TestCase):
|
class TestOs_net_config(base.TestCase):
|
||||||
|
|
||||||
def test_something(self):
|
def test_something(self):
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
pbr>=0.5.21,<1.0
|
pbr>=0.5.21,<1.0
|
||||||
Babel>=0.9.6
|
Babel>=0.9.6
|
||||||
|
netaddr>=0.7.6
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -19,4 +19,4 @@ import setuptools
|
|||||||
|
|
||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
setup_requires=['pbr'],
|
setup_requires=['pbr'],
|
||||||
pbr=True)
|
pbr=True)
|
||||||
|
|||||||
@@ -8,4 +8,6 @@ sphinx>=1.1.2
|
|||||||
oslosphinx
|
oslosphinx
|
||||||
testrepository>=0.0.17
|
testrepository>=0.0.17
|
||||||
testscenarios>=0.4,<0.5
|
testscenarios>=0.4,<0.5
|
||||||
testtools>=0.9.32
|
testtools>=0.9.32
|
||||||
|
mock>=1.0
|
||||||
|
mox>=0.5.3
|
||||||
|
|||||||
Reference in New Issue
Block a user