Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions acos_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from acos_client.v21.vrrp_a import VRRPA as v21_VRRPA

from acos_client.v30 import axapi_http as v30_http
from acos_client.v30.access_list import AccessList
from acos_client.v30.delete.delete import Delete
from acos_client.v30.device_context import DeviceContext as v30_DeviceContext
from acos_client.v30.dns import DNS as v30_DNS
Expand All @@ -56,6 +57,7 @@

VERSION_IMPORTS = {
'21': {
'AccessList': None,
'DNS': v21_DNS,
'http': v21_http,
'HA': v21_HA,
Expand All @@ -71,6 +73,7 @@
'VRRPA': v21_VRRPA
},
'30': {
'AccessList': AccessList,
'DNS': v30_DNS,
'http': v30_http,
'Interface': v30_Interface,
Expand Down Expand Up @@ -125,6 +128,10 @@ def __init__(
def _just_digits(self, s):
return ''.join(i for i in str(s) if i.isdigit())

@property
def access_list(self):
return VERSION_IMPORTS[self._version]['AccessList'](self)

@property
def dns(self):
return VERSION_IMPORTS[self._version]['DNS'](self)
Expand Down
66 changes: 66 additions & 0 deletions acos_client/tests/unit/v30/test_access_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
try:
import unittest
except ImportError:
import unittest2 as unittest

from acos_client import client
import responses


HOSTNAME = 'fake_a10'
BASE_URL = "https://{}:443/axapi/v3".format(HOSTNAME)
AUTH_URL = "{}/auth".format(BASE_URL)
VSERVER_NAME = 'test'
OK_RESP = {'response': {'status': 'OK'}}


class TestAccessList(unittest.TestCase):

def setUp(self):
self.client = client.Client(HOSTNAME, '30', 'fake_username', 'fake_password')

@responses.activate
def test_list_access_list(self):
responses.add(responses.POST, AUTH_URL, json={'session_id': 'foobar'})
json_response = [{'foo': 'bar'}]
responses.add(responses.GET, '{}/access-list'.format(BASE_URL),
json=json_response, status=200)

resp = self.client.access_list.list()
self.assertEqual(resp, json_response)

@responses.activate
def test_get_access_list(self):
responses.add(responses.POST, AUTH_URL, json={'session_id': 'foobar'})
json_response = [{'foo': 'bar'}]
responses.add(responses.GET, '{}/access-list/standard/123'.format(BASE_URL),
json=json_response, status=200)

resp = self.client.access_list.get(123)
self.assertEqual(resp, json_response)

@responses.activate
def test_post_access_list(self):
responses.add(responses.POST, AUTH_URL, json={'session_id': 'foobar'})
responses.add(responses.POST, '{}/access-list/standard'.format(BASE_URL),
json=OK_RESP, status=200)
request_params = {
'std': 1,
'stdrules': [{
'action': 'permit',
'host': '192.168.0.1'
}]
}

resp = self.client.access_list.create(**request_params)
self.assertEqual(resp, OK_RESP)

@responses.activate
def test_delete_access_list(self):
responses.add(responses.POST, AUTH_URL, json={'session_id': 'foobar'})
json_response = [{'foo': 'bar'}]
responses.add(responses.DELETE, '{}/access-list/standard/123'.format(BASE_URL),
json=json_response, status=200)

resp = self.client.access_list.delete(123)
self.assertEqual(resp, json_response)
27 changes: 27 additions & 0 deletions acos_client/v30/access_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from __future__ import absolute_import
from __future__ import unicode_literals

from acos_client import errors as acos_errors
from acos_client.v30 import base


class AccessList(base.BaseV30):
url_prefix = "/access-list"

def list(self, **kwargs):
return self._get(self.url_prefix, axapi_args=kwargs)

def get(self, id, **kwargs):
return self._get("%s/standard/%s" % (self.url_prefix, id), axapi_args=kwargs)

def create(self, std, stdrules, **kwargs):
request_params = {
"standard-list": [{
"std": std,
"stdrules": stdrules
}]
}
return self._post("%s/standard" % self.url_prefix, request_params, axapi_args=kwargs)

def delete(self, id, **kwargs):
return self._delete("%s/standard/%s" % (self.url_prefix, id), axapi_args=kwargs)