-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathisilon.py
79 lines (58 loc) · 2.51 KB
/
isilon.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import urllib3
from urllib3.exceptions import MaxRetryError, LocationValueError
import isi_sdk_8_2_1 as isi_sdk
from settings import Settings
class IsilonConnectionException(Exception):
pass
class IsilonNoHostException(Exception):
pass
class IsilonInvalidClassException(Exception):
pass
class IsilonInvalidArgumentException(Exception):
pass
class IsilonInvalidMethodException(Exception):
pass
class Isilon:
def __init__(self, api_class=None, settings_file=None):
self.config = Settings(settings_file)
urllib3.disable_warnings()
# Configuration Settings
url = f"https://{self.config.ip}:{self.config.port}"
configuration = isi_sdk.Configuration()
configuration.host = url
configuration.username = self.config.username
configuration.password = self.config.password
configuration.verify_ssl = self.config.verify_ssl
self.create_client(api_class=api_class, configuration=configuration)
def create_client(self, api_class=None, configuration=None):
# Create an instance of the API class
client = isi_sdk.ApiClient(configuration)
try:
api_class = getattr(isi_sdk, api_class)
except AttributeError:
raise IsilonInvalidClassException(f"There is no class called '{api_class}' in the Isilon SDK")
except Exception:
raise
self.api_client = api_class(client)
def call_method(self, method=None, **kwargs):
# This allows the calling of Class Methods using a variable
try:
to_call = getattr(self.api_client, method)
except AttributeError:
raise IsilonInvalidMethodException(f"The method `{method}` does not exist on the Class Object.")
except Exception:
print("An unknown error occured when trying to access the Instance Method")
raise
try:
# Calling the function and passing in all the args
output = to_call(**kwargs)
except MaxRetryError:
raise IsilonConnectionException(f"Unable to connect to the the host {self.config.ip}")
except LocationValueError:
raise IsilonNoHostException("No host is defined in the settings file")
except TypeError:
raise IsilonInvalidArgumentException(f"One of the arguements you passed in is invalid. Arguments are: {kwargs}")
except Exception:
print("An unknown error occured when trying to call the method")
raise
return output