Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #2

Merged
merged 12 commits into from
Feb 23, 2021
30 changes: 30 additions & 0 deletions examples/get_all_devices.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env python
'''
' Riverbed Community SteelScript
'
' get_all_devices.py
'
' Encoding: UTF8
' End of Line Sequence: LF
'
' Copyright (c) 2021 Riverbed Technology, Inc.
'
' This software is licensed under the terms and conditions of the MIT License
' accompanying the software ("License"). This software is distributed "AS IS"
' as set forth in the License.
'''

from steelscript.common import UserAuth
from steelscript.netim.core.device import Device
import pprint

# Fill these in with appropriate values
host = '$host'
username = '$username'
password = '$password'

auth=UserAuth(username, password)
netim_device = Device(host, auth)

device_list = netim_device.get_all_devices()
pprint.pprint(device_list)
31 changes: 31 additions & 0 deletions examples/print_devices-raw.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env python
'''
' Riverbed Community SteelScript
'
' print_devices-raw.py`
'
' Encoding: UTF8
' End of Line Sequence: LF
'
' Usage
' python print_devices-raw.py netim-ip-address -u admin -p password
'
' Example
' python print_hostgroups-raw.py 10.10.10.10 -u admin -p password
'
' Copyright (c) 2021 Riverbed Technology, Inc.
'
' This software is licensed under the terms and conditions of the MIT License
' accompanying the software ("License"). This software is distributed "AS IS"
' as set forth in the License.
'''

from steelscript.netim.core.app import NetIM
from steelscript.common.datautils import Formatter
class DevicesApp(NetIMApp):
def main(self):
for device in self.netim.classification.get_devices():
print(device)

app = DevicesApp()
app.run()
77 changes: 77 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Copyright (c) 2019 Riverbed Technology, Inc.
#
# This software is licensed under the terms and conditions of the MIT License
# accompanying the software ("License"). This software is distributed "AS IS"
# as set forth in the License.

from glob import glob

from setuptools import setup, find_packages
packagedata = True


#from gitpy_versioning import get_version

setup_args = {
'name': 'steelscript.netim',
'namespace_packages': ['steelscript'],
#'version': get_version(),
'author': 'Riverbed Community',
'author_email': 'community@riverbed.com',
'url': 'https://community.riverbed.com',
'license': 'MIT',
'description': 'Python module for interacting with Riverbed '
'NetIM with SteelScript',

'long_description': '''SteelScript for NetIM
===========================
SteelScript is a collection of libraries and scripts in Python and JavaScript
for interacting with Riverbed Technology devices.
For a complete guide to installation, see:
https://support.riverbed.com/apis/steelscript
''',

'platforms': 'Linux, Mac OS, Windows',

'classifiers': [
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'Intended Audience :: Information Technology',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3.5',
'Topic :: System :: Networking',
],

'packages': find_packages(exclude=('gitpy_versioning',)),

'data_files': (
('share/doc/steelscript/docs/netim', glob('docs/*')),
('share/doc/steelscript/examples/netim', glob('examples/*')),
('share/doc/steelscript/notebooks/netim', glob('notebooks/*')),
),

'install_requires': (
'steelscript>=2.0',
),

'extras_require': None,

'tests_require': '',

'python_requires': '>3.5.0',

'entry_points': {
'steel.commands': [
'netim = steelscript.netim.commands'
],
'portal.plugins': [
'netim = steelscript.netim.appfwk.plugin:NetIMPlugin'
],
},
}

if packagedata:
setup_args['include_package_data'] = True

setup(**setup_args)
1 change: 1 addition & 0 deletions steelscript/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__import__("pkg_resources").declare_namespace(__name__)
Empty file added steelscript/netim/__init__.py
Empty file.
1 change: 1 addition & 0 deletions steelscript/netim/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

14 changes: 14 additions & 0 deletions steelscript/netim/core/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

# Copyright (c) 2019 Riverbed Technology, Inc.
#
# This software is licensed under the terms and conditions of the MIT License
# accompanying the software ("License"). This software is distributed "AS IS"
# as set forth in the License.



"""
The NetProfiler package offers a set of interfaces to control and work with
a SteelCentral NetIM appliance.
"""
from steelscript.netim.core.device import *
64 changes: 64 additions & 0 deletions steelscript/netim/core/device.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Copyright (c) 2021 Riverbed Technology, Inc.
#
# This software is licensed under the terms and conditions of the MIT License
# accompanying the software ("License"). This software is distributed "AS IS"
# as set forth in the License.
from steelscript.common.service import Service
import logging

logger = logging.getLogger(__name__)

class Device(object):
"""NetIM Core Device API

Responsible for DELETE, GET, POST, PUT methods against NetIM Device.

"""
def __init__(self, host, auth, port=8543, version=None):
"""Initialize Device object.
:param str host: name or IP address of the NetIM Core.

:param auth: defines the authentication method and credentials
to use to access the NetIM Core. It should be an instance of
:py:class:`UserAuth<steelscript.common.service.UserAuth>` or
:py:class:`OAuth<steelscript.common.service.OAuth>`

:param port: integer, port number to connect to core

:param str version: API version to use when communicating.
if unspecified, this will use the latest version
"""

self.host = host
self.auth = auth

self.service = Service('NetIM', host=host, auth=auth, port=port,
verify_ssl=False, versions=None,
enable_auth_detection = False,
supports_auth_basic=True,
supports_auth_cookie=False,
supports_auth_oauth=False,
enable_services_version_detection=False
)

if version is None:
self.version = 'v1'
else:
self.version = version

self.base_url = f'/api/netim/{self.version}/'
logger.info("Initialized NetIM Core Device API object with %s" % self.host)

def get_all_devices(self):
"""Return all of the devices in the data model
Args:

Returns:
result (dict): All data associated with a response.
"""

url = f"{self.base_url}devices"
response = self.service.conn.json_request('GET', url)
# result = ParseMethods.parse_data(response)
print(response)
return response
29 changes: 29 additions & 0 deletions steelscript/netim/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) 2019 Riverbed Technology, Inc.
#
# This software is licensed under the terms and conditions of the MIT License
# accompanying the software ("License"). This software is distributed "AS IS"
# as set forth in the License.

class RequestMethods(object):
"""Provides interaction with the NetIM REST API.
"""
def __init__(self, session, url):
"""Initialize RequestMethods object with auth parameters.
Args:
auth (obj): Requests auth object
url (str): URL of the API service being called
"""

self.auth = auth
self.url = url

def request(self, urlpath, method, headers=None, payload=None):
"""Performs HTTP REST API Call.
Args:
method (str): DELETE, GET, POST, PUT
headers (dict): Use standard or custom header for specific API interaction
payload (str): A formatted string to be sent via POST or PUT REST call
Returns:
result (dict): All data associated with a response.
"""