Skip to content

Commit 59f15b4

Browse files
committedMay 30, 2018
release 0.0.1
1 parent 82f2cc4 commit 59f15b4

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed
 

‎setup.cfg

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[pep8]
2+
max-line-length = 160

‎setup.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# pylint: disable=C0111
2+
from setuptools import setup
3+
4+
with open("README.md", "r") as fh:
5+
README = fh.read()
6+
7+
setup(
8+
name='spectrum-client',
9+
version='0.0.1',
10+
description='CA Spectrum Web Services API wrapper',
11+
long_description=README,
12+
long_description_content_type="text/markdown",
13+
author='Renato Orgito',
14+
author_email='orgito@gmail.com',
15+
maintainer='Renato Orgito',
16+
maintainer_email='orgito@gmail.com',
17+
url='https://github.com/orgito/spectrum-client',
18+
license='MIT',
19+
classifiers=[
20+
'Development Status :: 3 - Alpha',
21+
'Intended Audience :: Developers',
22+
'Intended Audience :: System Administrators',
23+
'License :: OSI Approved :: MIT License',
24+
'Operating System :: OS Independent',
25+
'Programming Language :: Python :: 3.6',
26+
'Topic :: Software Development :: Libraries',
27+
'Topic :: System :: Monitoring',
28+
'Topic :: System :: Networking :: Monitoring',
29+
],
30+
keywords='spectrum-client network monitoring spectrum',
31+
packages=['spectrum_client'],
32+
install_requires=[],
33+
python_requires='>=3.6',
34+
project_urls={
35+
'Bug Reports': 'https://github.com/orgito/spectrum-client/issues',
36+
'Source': 'https://github.com/orgito/spectrum-client',
37+
},
38+
)

‎spectrum_client/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .spectrum import Spectrum

‎spectrum_client/spectrum.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import os
2+
3+
import requests
4+
from requests.auth import HTTPBasicAuth
5+
6+
SPECTRUM_URL = os.environ.get('SPECTRUM_URL')
7+
SPECTRUM_USERNAME = os.environ.get('SPECTRUM_USERNAME')
8+
SPECTRUM_PASSWORD = os.environ.get('SPECTRUM_PASSSWORD')
9+
10+
11+
class Spectrum(object):
12+
13+
def __init__(self, url=SPECTRUM_URL, username=SPECTRUM_USERNAME, password=SPECTRUM_PASSWORD):
14+
if url is None:
15+
raise ValueError('Spectrum (OneClick) url must be provided either in the constructor or as an environment variable')
16+
self.url = url if not url.endswith('/') else url[:-1]
17+
self.auth = HTTPBasicAuth(username, password)
18+
19+
def update_attribute(self, model_handle, attr_id, value):
20+
url = f'{self.url}/spectrum/restful/model/{model_handle}'
21+
params = {'attr': attr_id, 'val': value}
22+
res = requests.put(url, params=params, auth=self.auth)
23+
res.raise_for_status()
24+
return res.ok

0 commit comments

Comments
 (0)
Please sign in to comment.