Skip to main content

Simple library to use Spectrum OneClick API.

Project description

oneclick-client

This is a simple library for working with the Spectrum OneClick API. The basic working methods are implemented, the response can be returned in json, like a python dict, or in xml, like a bs4 object. You can also use xml or json in requests, passing them as text.


Installation

pip install oneclick-client

Launch examples

See example.py for more working examples.

# import
from py_spectrum import spectrum as sp

# initialization
api = sp.SpectrumClient(server='https://192.168.0.1:8888',
                        user='spectrum',
                        password='spectrum',
                        verify=False,
                        timeout=5)

# get devices, output in json (python dict)
devices = api.get(out_format='json',
                    app='devices',
                    params={
                        'throttlesize': 10000,
                        'landscape': '0x1000000',
                        'attr': ['0x129e7', '0x129fa', '0x1006e']
                    })

# create service
model = api.post(out_format='json',
                    app='model',
                    params={
                        'landscapeid': '0x1000000',
                        'mtypeid': '0x1046f',
                        'attr': ['0x12a51', '0x1006e'],
                        'val': ['7', 'test_srv'],
                    })
mh = model['create-model-response']['model']['@mh']

# update service name, output in xml (bs4 obj)
update = api.put(app=f"model/{mh}",
                    params={
                        'attr': '0x1006e',
                        'val': 'test_srv_update',
                    })

# request with data in xml and output in json (python dict)
xml_request = """<!-- xml body request GET ALL ASA MODELS -->
<rs:model-request throttlesize="10000"
xmlns:rs="http://www.ca.com/spectrum/restful/schema/request"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.ca.com/spectrum/restful/schema/request ../../../xsd/Request.xsd ">
<rs:target-models>
    <rs:models-search>
        <rs:search-criteria
            xmlns="http://www.ca.com/spectrum/restful/schema/filter">
        <filtered-models>
        <is-derived-from>
            <attribute id="AttributeID.MTYPE_HANDLE">
            <value>0x2101ea</value> <!-- CiscoASA -->
            </attribute>
        </is-derived-from>
        </filtered-models>
    </rs:search-criteria>
    </rs:models-search>
</rs:target-models>
    <rs:requested-attribute id="0x1006e" /> <!-- Device Name -->
    <rs:requested-attribute id="0x10000" /> <!-- Model Type Name -->
    <rs:requested-attribute id="0x10032" /> <!-- Manufacturer -->
    <rs:requested-attribute id="0x129fa" /> <!-- Model Handle -->
    <rs:requested-attribute id="0x1027f" /> <!-- IP Address -->
    <rs:requested-attribute id="0x10004" /> <!-- Contact status -->
    <rs:requested-attribute id="0x110df" /> <!-- MAC Address -->
    <rs:requested-attribute id="0x82002d" /> <!-- Last verified unix timestamp  -->
</rs:model-request>"""

asa_models = api.post(out_format='json', app='models', data=xml_request)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

oneclick_client-1.0.0.tar.gz (3.6 kB view details)

Uploaded Source

File details

Details for the file oneclick_client-1.0.0.tar.gz.

File metadata

  • Download URL: oneclick_client-1.0.0.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for oneclick_client-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ddc4d4abf47465475b634655c331babae4f77825b4d7e473714a626b5ea949ef
MD5 101410240d40c8c4e3a55270ead95d7a
BLAKE2b-256 46bc9d98e80c3edceeeb87bfd693dc9a9deb8def95b871332774ec2afa7ad941

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page