PK 5J,X›: : acsclient-1.0.6-py2.7-nspkg.pthimport sys, types, os;has_mfs = sys.version_info > (3, 5);p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('acsclient',));importlib = has_mfs and __import__('importlib.util');has_mfs and __import__('importlib.machinery');m = has_mfs and sys.modules.setdefault('acsclient', importlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec('acsclient', [os.path.dirname(p)])));m = m or not has_mfs and sys.modules.setdefault('acsclient', types.ModuleType('acsclient'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p)
PK TxŸIë¯úÜ Ü acsclient/acsclient.pyimport requests
from jinja2 import Environment, FileSystemLoader
import os
class ACSClient(object):
_object_types = ['Common/ACSVersion', 'Common/ServiceLocation',
'ErrorMessage', 'Identity/User', 'User', 'IdentityGroup',
'NetworkDevice/Device', 'NetworkDevice/DeviceGroup',
'Host']
_function_types = ['all', 'name', 'id']
def __init__(self, hostname, username, password,
hide_urllib_warnings=False):
""" Class initialization method
:param hostname: Hostname or IP Address of Cisco ACS 5.6 Sever
:type hostname: str or unicode
:param username: Cisco ACS admin user name
:type username: str or unicode
:param password: Cisco ACS admin user password
:type password: str or unicode
:param hide_urllib_warnings: Hide urllib3 warnings (optional)
:type hide_urllib_warnings: boolean
"""
self.url = "https://%s/Rest/" % (hostname)
self.credentials = (username, password)
if hide_urllib_warnings:
requests.packages.urllib3.disable_warnings()
def _req(self, method, frag, data=None):
""" Creates the XML REST request to the Cisco ACS 5.6 Server
:param method: HTTP Method to use (GET, POST, DELETE, PUT)
:type method: str or unicode
:param frag: URL fragment for request
:type frag: str or unicode
:param data: XML data to send to the server (optional)
:type data: str or unicode
"""
return requests.request(method, self.url + frag,
data=data,
verify=False,
auth=self.credentials,
headers={'Content-Type': 'application/xml'})
def _frag(self, object_type, func, var):
""" Creates the proper URL fragment for HTTP requests
:param object_type: Cisco ACS Object Type
:type object_type: str or unicode
:param func: ACS method function
:type func: str or unicode
:param var: ACS variable either the name or id
:type func: str or unicode
"""
try:
if object_type in self._object_types:
if func in self._function_types:
if func == "all":
frag = object_type
else:
frag = object_type + "/" + func + "/" + str(var)
return frag
else:
raise Exception
except Exception:
print("Invalid object_type or function")
def create(self, object_type, data):
""" Create object on the ACS Server
:param object_type: Cisco ACS Object Type
:type object_type: str or unicode
:param data: XML data to send to the ACS Server
:type data: str or unicode
"""
return self._req("POST", object_type, data)
def read(self, object_type, func="all", var=None):
""" Read data from ACS Server
:param object_type: Cisco ACS Object Type
:type object_type: str or unicode
:param func: ACS method function (optional)
:type func: str or unicode
:param var: ACS variable either the name or id (optional)
:type var: str or unicode
"""
return self._req("GET", self._frag(object_type, func, var))
def update(self, object_type, data):
""" Update object on the ACS Server
:param object_type: Cisco ACS Object Type
:type object_type: str or unicode
:param data: XML data to send to the ACS Server
:type data: str or unicode
"""
return self._req("PUT", object_type, data)
def delete(self, object_type, func, var):
""" Delete object on the ACS Server
:param object_type: Cisco ACS Object Type
:type object_type: str or unicode
:param func: ACS method function
:type func: str or unicode
:param var: ACS variable either the name or id
:type var: str, unicode, or int
"""
return self._req("DELETE", self._frag(object_type, func, var))
def create_device_group(self, name, group_type, description=""):
""" Create ACS Device Group
Create a new Device Group on the server. This will generate the proper
XML to pass to the server.
:param name: Full name of the Device Group
:type name: str or unicode
:param group_type: Device Group Type
:type group_type: str or unicode
:param description: Group Description (optional)
:type description: str or unicode
:returns: HTTP Response code
:rtype: requests.models.Response
"""
ENV = Environment(loader=FileSystemLoader(
os.path.join(os.path.dirname(__file__), "templates")))
template = ENV.get_template("devicegroup.j2")
var = dict(name=name, group_type=group_type, description=description)
data = template.render(config=var)
return self.create("NetworkDevice/DeviceGroup", data)
def create_tacacs_device(self, name, groups, secret, ip, mask=32):
""" Create a new Device with TACACS
:param name: Device name
:type name: str or unicode
:param groups: Groups list
:type groups: dict
:param secret: TACACS secret key
:type secret: str or unicode
:param ip: Device IP address
:type ip: str or unicode
:param mask: Device IP mask (optional)
:type mask: int
"""
ENV = Environment(loader=FileSystemLoader(
os.path.join(os.path.dirname(__file__), "templates")))
template = ENV.get_template("device.j2")
var = dict(name=name, ip=ip, mask=mask, secret=secret, groups=groups)
data = template.render(config=var)
return self.create("NetworkDevice/Device", data)
def create_radius_device(self, name, groups, secret, ip, mask=32):
""" Create a new Device with TACACS
:param name: Device name
:type name: str or unicode
:param groups: Groups list
:type groups: dict
:param secret: Radius secret key
:type secret: str or unicode
:param ip: Device IP address
:type ip: str or unicode
:param mask: Device IP mask (optional)
:type mask: int
"""
ENV = Environment(loader=FileSystemLoader(
os.path.join(os.path.dirname(__file__), "templates")))
template = ENV.get_template("radius_device.j2")
var = dict(name=name, ip=ip, mask=mask, secret=secret, groups=groups)
data = template.render(config=var)
return self.create("NetworkDevice/Device", data)
def create_device_simple(self, name, secret, ip, location, device_type):
""" Simple way to create a new Device with TACACS
:param name: Device name
:type name: str or unicode
:param secret: TACACS secret key
:type secret: str or unicode
:param ip: Device IP address
:type ip: str or unicode
:param location: Device Group Location
:type location: str or unicode
:param device_type: Device Group Device Type
:type device_type: str or unicode
"""
groups = [
{"name": "All Locations:" + location,
"type": "Location"},
{"name": "All Device Types:" + device_type,
"type": "Device Type"},
]
return self.create_tacacs_device(name, groups, secret, ip)
PK ñ»—G⹯<î î " acsclient/templates/devicegroup.j2
{{config.description}}
{{config.name}}
{{config.group_type}}
PK ªºRIªV'Š´ ´ $ acsclient/templates/radius_device.j2
{{config.name}}
{%- for item in config.groups %}
{{item.name}}
{{item.type}}
{%- endfor %}
{{config.ip}}
{{config.mask}}
true
false
1700
{{config.secret}}
PK ðŠ”GHq` acsclient/templates/device.j2
{{config.name}}
{%- for item in config.groups %}
{{item.name}}
{{item.type}}
{%- endfor %}
{{config.ip}}
{{config.mask}}
true
{{config.secret}}
false
PK 5J^-Ò
) acsclient-1.0.6.dist-info/DESCRIPTION.rstUNKNOWN
PK 5Je1‡y, , ' acsclient-1.0.6.dist-info/metadata.json{"extensions": {"python.details": {"contacts": [{"email": "nathan@gotz.co", "name": "Nathan Gotz", "role": "author"}], "document_names": {"description": "DESCRIPTION.rst"}, "project_urls": {"Home": "https://github.com/nlgotz/acsclient"}}}, "extras": [], "generator": "bdist_wheel (0.26.0)", "keywords": ["cisco", "acs", "access", "control", "acsclient"], "license": "Apache 2.0", "metadata_version": "2.0", "name": "acsclient", "run_requires": [{"requires": ["MarkupSafe", "jinja2", "requests"]}], "summary": "Access Cisco ACS 5.6 API", "version": "1.0.6"}PK 5J¸ã.
0 acsclient-1.0.6.dist-info/namespace_packages.txtacsclient
PK ’‰"HqžÄ/ / " acsclient-1.0.6.dist-info/pbr.json{"is_release": false, "git_version": "f465758"}PK 5J¸ã.
' acsclient-1.0.6.dist-info/top_level.txtacsclient
PK 5Jìndªn n acsclient-1.0.6.dist-info/WHEELWheel-Version: 1.0
Generator: bdist_wheel (0.26.0)
Root-Is-Purelib: true
Tag: py2-none-any
Tag: py3-none-any
PK 5JÖTmµ] ] " acsclient-1.0.6.dist-info/METADATAMetadata-Version: 2.0
Name: acsclient
Version: 1.0.6
Summary: Access Cisco ACS 5.6 API
Home-page: https://github.com/nlgotz/acsclient
Author: Nathan Gotz
Author-email: nathan@gotz.co
License: Apache 2.0
Keywords: cisco acs access control acsclient
Platform: UNKNOWN
Requires-Dist: MarkupSafe
Requires-Dist: jinja2
Requires-Dist: requests
UNKNOWN
PK 5J³¥d¼o o acsclient-1.0.6.dist-info/RECORDacsclient-1.0.6-py2.7-nspkg.pth,sha256=NVedRWY_teKZ-lXPQOXP80phDUyG4jdzlQHrCiL-YCE,570
acsclient/acsclient.py,sha256=rvIVB-HYmF46JAuQWCyYJb8XlI5veyiE7CcEEvK9CkQ,7644
acsclient/templates/device.j2,sha256=NUBVx4Ry35R2UExvZTPINt96PpoQ1WizXE2VUZxro_g,685
acsclient/templates/devicegroup.j2,sha256=N2HqT3d0dqSRe5d_v-vydkuw4VNlsp_EoVJ5rEZfcG8,238
acsclient/templates/radius_device.j2,sha256=M42bRhn2TCR66RBLO73jNayL_YTfqu_id7Obx33CqVM,692
acsclient-1.0.6.dist-info/DESCRIPTION.rst,sha256=OCTuuN6LcWulhHS3d5rfjdsQtW22n7HENFRh6jC6ego,10
acsclient-1.0.6.dist-info/METADATA,sha256=4MBSVAgmgcZ0wwdudWSvlHKSEA9a3vF8Fp0XzcCg-1w,349
acsclient-1.0.6.dist-info/RECORD,,
acsclient-1.0.6.dist-info/WHEEL,sha256=GrqQvamwgBV4nLoJe0vhYRSWzWsx7xjlt74FT0SWYfE,110
acsclient-1.0.6.dist-info/metadata.json,sha256=cx3HdfjUlmLPXS-Qm_OHuxI3b46kBgW5JRiG_a4u8is,556
acsclient-1.0.6.dist-info/namespace_packages.txt,sha256=2CE-yKjWj2vz_WTqB8FINT1H0F6NER2YUDPWHhBomPU,10
acsclient-1.0.6.dist-info/pbr.json,sha256=k14Gktc11Fnyl3YlBJNSZkCqb8xZet1sCnChbNlLsnM,47
acsclient-1.0.6.dist-info/top_level.txt,sha256=2CE-yKjWj2vz_WTqB8FINT1H0F6NER2YUDPWHhBomPU,10
PK 5J,X›: : acsclient-1.0.6-py2.7-nspkg.pthPK TxŸIë¯úÜ Ü w acsclient/acsclient.pyPK ñ»—G⹯<î î " ‡ acsclient/templates/devicegroup.j2PK ªºRIªV'Š´ ´ $ µ! acsclient/templates/radius_device.j2PK ðŠ”GHq` «$ acsclient/templates/device.j2PK 5J^-Ò
) “' acsclient-1.0.6.dist-info/DESCRIPTION.rstPK 5Je1‡y, , ' ä' acsclient-1.0.6.dist-info/metadata.jsonPK 5J¸ã.
0 U* acsclient-1.0.6.dist-info/namespace_packages.txtPK ’‰"HqžÄ/ / " * acsclient-1.0.6.dist-info/pbr.jsonPK 5J¸ã.
' + acsclient-1.0.6.dist-info/top_level.txtPK 5Jìndªn n k+ acsclient-1.0.6.dist-info/WHEELPK 5JÖTmµ] ] " , acsclient-1.0.6.dist-info/METADATAPK 5J³¥d¼o o ³- acsclient-1.0.6.dist-info/RECORDPK
`2