Skip to content

Commit

Permalink
Create DHCPRelay IPv4 and IPv6 list, add and delete features
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcus Vinicius G. Cesario committed Oct 2, 2015
1 parent e45c26f commit a73d9c7
Show file tree
Hide file tree
Showing 4 changed files with 265 additions and 2 deletions.
20 changes: 20 additions & 0 deletions networkapiclient/ClientFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
from networkapiclient.UsuarioGrupo import UsuarioGrupo
from networkapiclient.DireitoGrupoEquipamento import DireitoGrupoEquipamento
from networkapiclient.Network import Network
from networkapiclient.Network import DHCPRelayIPv4
from networkapiclient.Network import DHCPRelayIPv6
from networkapiclient.EnvironmentVIP import EnvironmentVIP
from networkapiclient.OptionVIP import OptionVIP
from networkapiclient.Filter import Filter
Expand Down Expand Up @@ -289,6 +291,24 @@ def create_network(self):
self.password,
self.user_ldap)

def create_dhcprelay_ipv4(self):
"""Get an instance of DHCPRelayIPv4 services facade."""
return DHCPRelayIPv4(
self.networkapi_url,
self.user,
self.password,
self.user_ldap
)

def create_dhcprelay_ipv6(self):
"""Get an instance of DHCPRelayIPv6 services facade."""
return DHCPRelayIPv6(
self.networkapi_url,
self.user,
self.password,
self.user_ldap
)

def create_environment_vip(self):
"""Get an instance of environment_vip services facade."""
return EnvironmentVIP(
Expand Down
243 changes: 243 additions & 0 deletions networkapiclient/Network.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from networkapiclient.GenericClient import GenericClient
from networkapiclient.utils import is_valid_int_param
from networkapiclient.exception import InvalidParameterError
from networkapiclient.ApiGenericClient import ApiGenericClient


class Network(GenericClient):
Expand Down Expand Up @@ -527,3 +528,245 @@ def remove_networks(self, ids):
{'network': network_map}, 'PUT', 'network/remove/')

return self.response(code, xml)

class DHCPRelayIPv4(ApiGenericClient):

def __init__(self, networkapi_url, user, password, user_ldap=None):
"""Class constructor receives parameters to connect to the networkAPI.
:param networkapi_url: URL to access the network API.
:param user: User for authentication.
:param password: Password for authentication.
"""
super(DHCPRelayIPv4, self).__init__(networkapi_url, user, password, user_ldap)

def add(self, networkipv4_id, ipv4_id):
"""List all DHCPRelayIPv4.
:param: networkipv4_id, ipv4_id
:return: Following dictionary:
{
"networkipv4": <networkipv4_id>,
"id": <id>,
"ipv4": {
"oct4": <oct4>,
"oct2": <oct2>,
"oct3": <oct3>,
"oct1": <oct1>,
"ip_formated": "<string IPv4>",
"networkipv4": <networkipv4_id>,
"id": <ipv4_id>,
"descricao": "<string description>"
}
:raise NetworkAPIException: Falha ao acessar fonte de dados
"""

data = dict()

data["networkipv4"] = networkipv4_id
data["ipv4"] = dict()
data["ipv4"]["id"] = ipv4_id
print data
uri = "api/dhcprelayv4/"
return self.post(uri, data=data)

def get_by_pk(self, dhcprelayv4_id):
"""List DHCPRelayIPv4 by ID
:param: dhcprelayv4_id
:return: Following dictionary:
{
"networkipv4": <networkipv4_id>,
"id": <id>,
"ipv4": {
"oct4": <oct4>,
"oct2": <oct2>,
"oct3": <oct3>,
"oct1": <oct1>,
"ip_formated": "<string IPv4>",
"networkipv4": <networkipv4_id>,
"id": <ipv4_id>,
"descricao": "<string description>"
}
:raise NetworkAPIException: Falha ao acessar fonte de dados
"""

uri = "api/dhcprelayv4/%s" % dhcprelayv4_id
return self.get(uri)

def list(self, networkipv4=None, ipv4=None):
"""List all DHCPRelayIPv4.
:param: networkipv4: networkipv4 id - list all dhcprelay filtering by networkipv4 id
ipv4: ipv4 id - list all dhcprelay filtering by ipv4 id
:return: Following dictionary:
[
{
"networkipv4": <networkipv4_id>,
"id": <id>,
"ipv4": {
"oct4": <oct4>,
"oct2": <oct2>,
"oct3": <oct3>,
"oct1": <oct1>,
"ip_formated": "<string IPv4>",
"networkipv4": <networkipv4_id>,
"id": <ipv4_id>,
"descricao": "<string description>"
},
{...}
]
:raise NetworkAPIException: Falha ao acessar fonte de dados
"""

uri = "api/dhcprelayv4/?"
if networkipv4:
uri += "networkipv4=%d&" % networkipv4
if ipv4:
uri += "ipv4=%d" % ipv4

return self.get(uri)

def remove(self, dhcprelayv4_id):
"""Remove DHCPRelayIPv4 by ID
:param: dhcprelayv4_id
:return: Nothing
:raise NetworkAPIException: Falha ao acessar fonte de dados
"""
uri = "api/dhcprelayv4/%s" % dhcprelayv4_id
return self.delete(uri)


class DHCPRelayIPv6(ApiGenericClient):

def __init__(self, networkapi_url, user, password, user_ldap=None):
"""Class constructor receives parameters to connect to the networkAPI.
:param networkapi_url: URL to access the network API.
:param user: User for authentication.
:param password: Password for authentication.
"""
super(DHCPRelayIPv6, self).__init__(networkapi_url, user, password, user_ldap)

def add(self, networkipv6_id, ipv6_id):
"""List all DHCPRelayIPv4.
:param: Object DHCPRelayIPv4
:return: Following dictionary:
{
"networkipv6": <networkipv4_id>,
"id": <id>,
"ipv6": {
"block1": <block1>,
"block2": <block2>,
"block3": <block3>,
"block4": <block4>,
"block5": <block5>,
"block6": <block6>,
"block7": <block7>,
"block8": <block8>,
"ip_formated": "<string IPv6>",
"networkipv6": <networkipv6_id>,
"id": <ipv6_id>,
"description": "<string description>"
}
:raise NetworkAPIException: Falha ao acessar fonte de dados
"""

data = dict()

data["networkipv6"] = networkipv6_id
data["ipv6"] = dict()
data["ipv6"]["id"] = ipv6_id
uri = "api/dhcprelayv6/"
return self.post(uri, data=data)

def get_by_pk(self, dhcprelayv6_id):
"""List DHCPRelayIPv6 by ID
:param: dhcprelayv4_id
:return: Following dictionary:
{
"networkipv6": <networkipv4_id>,
"id": <id>,
"ipv6": {
"block1": <block1>,
"block2": <block2>,
"block3": <block3>,
"block4": <block4>,
"block5": <block5>,
"block6": <block6>,
"block7": <block7>,
"block8": <block8>,
"ip_formated": "<string IPv6>",
"networkipv6": <networkipv6_id>,
"id": <ipv6_id>,
"description": "<string description>"
}
:raise NetworkAPIException: Falha ao acessar fonte de dados
"""

uri = "api/dhcprelayv6/%s" % dhcprelayv6_id
return self.get(uri)

def list(self, networkipv6=None, ipv6=None):
"""List all DHCPRelayIPv6.
:param: networkipv6: networkipv6 id - list all dhcprelay filtering by networkipv6 id
ipv6: ipv6 id - list all dhcprelay filtering by ipv6 id
:return: Following dictionary:
[
{
"networkipv6": <networkipv4_id>,
"id": <id>,
"ipv6": {
"block1": <block1>,
"block2": <block2>,
"block3": <block3>,
"block4": <block4>,
"block5": <block5>,
"block6": <block6>,
"block7": <block7>,
"block8": <block8>,
"ip_formated": "<string IPv6>",
"networkipv6": <networkipv6_id>,
"id": <ipv6_id>,
"description": "<string description>"
},
{...}
]
:raise NetworkAPIException: Falha ao acessar fonte de dados
"""

uri = "api/dhcprelayv6/?"
if networkipv6:
uri += "networkipv6=%d&" % networkipv6
if ipv6:
uri += "ipv6=%d" % ipv6

return self.get(uri)

def remove(self, dhcprelayv6_id):
"""Remove DHCPRelayIPv6 by ID
:param: dhcprelayv6_id
:return: Nothing
:raise NetworkAPIException: Falha ao acessar fonte de dados
"""
uri = "api/dhcprelayv6/%s" % dhcprelayv6_id
return self.delete(uri)
2 changes: 1 addition & 1 deletion networkapiclient/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@

MAJOR_VERSION = '0'
MINOR_VERSION = '6'
PATCH_VERSION = '6'
PATCH_VERSION = '7'
VERSION = '.'.join((MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION,))

2 changes: 1 addition & 1 deletion networkapiclient/version_control.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CLIENT_VERSION = '0.6.4'
CLIENT_VERSION = '0.6.7'

0 comments on commit a73d9c7

Please sign in to comment.