Skip to main content

An abstraction utility for actifio appliances

Project description

# actappliance #

### Use case ###
This repo abstracts the type of connection you are making to an actifio appliance. You can write a test or use case one
way ane execute over SSH or RESTful connections.

The primary idea being that all sent commands can look like CLI as it is shorter and more people are familiar with it,
while the responses look like the RESTful API's JSON returns as they are easier to parse.
It also allows direct commands using either connection with the same contract of CLI like requests and RESTful like
responses for the case where the call is unreliable unusable for whatever reason (CLI permissions, arbitrary outputs).

# Functionality of Library #

First create your appliance/sky/uds object:

> a = Appliance(ip_address=<sky or cds ip>, hostname=<sky or cds dns name>) # hostname or ip_address required
> ex. a = Appliance(ip_address=8.8.8.8)

With default settings it will try to send RESTful calls for all cmd methods.

```
>>> a.a.cmd('udsinfo lsversion')
{u'status': 0, u'result': [{u'version': u'7.0.0.68595', u'component': u'CDS', u'installed': u'2016-03-07 12:14:37'}, {u'version': u'7.0.0.68595', u'component': u'psrv-revision', u'installed': u'2016-03-07 12:14:37'}]}
```
Note: You will likely see debug messages if your log levels aren't set!

If you store the return the object has additional methods like parse and raise_for_error.
```
>>> act_response = a.a.cmd('udsinfo lsversion')
>>> act_response.parse()
{u'version': u'7.0.0.68595', u'component': u'CDS', u'installed': u'2016-03-07 12:14:37'}
```

### Parse ###
The parse method tries to simplify interactions with our RESTful responses. It only returns dictionaries and strings. It
will never return a list! In the case above you can see it returned the first relevant dictionary it found. If the info
you desire was the version of the psrv-revision component you would use m_k='component' (search key is component),
m_v='psrv-revision' (matching value is psrv-revision). Those two inputs in action:
```
>>> act_response.parse(m_k='component', m_v='psrv-revision')
{u'version': u'7.0.0.68595', u'component': u'psrv-revision', u'installed': u'2016-03-07 12:14:37'}
```
However we wanted the version not the whole dicitonary so we would add k='version' (search for key version in the dict
and return the corresponding value).
The full command and result:
```
>>> act_response
{u'status': 0, 'errorcode': 8675309, 'errormessage': 'Something went wrong', u'result': [{u'version': u'7.0.0.68595', u'component': u'CDS', u'installed': u'2016-03-07 12:14:37'}, {u'version': u'7.0.0.68595', u'component': u'psrv-revision', u'installed': u'2016-03-07 12:14:37'}]}
>>> act_response.parse(m_k='component', m_v='psrv-revision', k='version')
u'7.0.0.68595'
```
Here we can see the use of parse is to simplify basic parsing of appliance responses.

* Advanced example
If you have used parse for a while, you probably have come to understand how it functions. Overreliance on parse may
lead to writing code like the following:

`ids = [act_response.parse(backups, k='id', index=backup) for backup in range(len(backups))]`

The above is considered ugly. When doing something like the above rewriting it to avoid using parse, but instead perform
it's action. The following has an identical result to the above line:

`ids = [data['id'] for data in backups['result']]`

If you want to avoid list comprehensions you could do the following

```
ids = []
for data in backup['results']:
ids.append(data['id'])
```

### Raise_for_error ###
The raise_for_error method does self inspection of the dictionary to determine if an Actifio related error occurred.
These errors do not include connection errors like failing to authenticate and get a valid REST sessionid. These are
specifically for errors that are bubbled up to the user when interacting with an Actifio appliance. The response objects
have two attributes "errormessage" and "errorcode" which you can use to handle errors that should not end the test.

* Basic example
```
>>> r = self.a.cmd('udsinfo lsversion -l')
>>> r.raise_for_status()
Response: {u'errorcode': 10010, u'errormessage': u'invalid option: l'}
```

This raised an error because -l is not a valid option for "udsinfo lsversion". The error object itself has direct access
to errorcode and errormessage. You can handle these exceptions as needed:
```
>>> from actappliance.act_errors import ACTError
>>> try:
... r.raise_for_error()
... except ACTError as e:
... if e.errorcode == 10010:
... # handle or allow this error
... print("I am allowing this error")
... else:
... raise
```

An alternative way to handle this would be to catch the specific error:
```
>>> from actappliance.act_errors import act_errors
>>> try:
... r.raise_for_error()
... except act_errors[10010]:
... # handle or allow this error
... print("I am allowing this error")
```


Note: If your command needs to specifically be rest OR ssh and cannot function or is an inaccurate test if sent the
other way use the specific methods instead of cmd.

### Have fun!
![Lots of fun](http://i.imgur.com/fzhEnP0.png)


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

actappliance-0.7.2.tar.gz (22.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

actappliance-0.7.2-py3-none-any.whl (28.3 kB view details)

Uploaded Python 3

File details

Details for the file actappliance-0.7.2.tar.gz.

File metadata

  • Download URL: actappliance-0.7.2.tar.gz
  • Upload date:
  • Size: 22.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for actappliance-0.7.2.tar.gz
Algorithm Hash digest
SHA256 dd266be2e1d4d81582b85e5b351fe7f7c7c08b551e7cb071a572d132cccdb1f7
MD5 0b88514750af8cd00c7290b032bc96dc
BLAKE2b-256 bf46c230770fe458e3a674f5fd1170b9bfd3c25867a9770564ff90e1149f136b

See more details on using hashes here.

File details

Details for the file actappliance-0.7.2-py3-none-any.whl.

File metadata

File hashes

Hashes for actappliance-0.7.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bf6580c66f12009ae6a263527e9443535bde35e248266e867cc5fa41b6a29159
MD5 9993a53916fceebd77dbd4db1a055f95
BLAKE2b-256 3dd97fe9e0050871c18a3e7468a95820ad6cecea6fc723898eb1c60975bbf069

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