syneto_api 0.2.4__tar.gz → 0.2.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: syneto-api
3
- Version: 0.2.4
3
+ Version: 0.2.6
4
4
  Summary: Syneto Client API library
5
5
  Home-page: https://github.com/SynetoNet/syneto-api
6
6
  License: Proprietary
@@ -33,15 +33,15 @@ $ pip install syneto-api
33
33
  ```
34
34
  from syneto_api import Authentication, Virtualization, Storage, Protection
35
35
 
36
- auth_api = Authentication(base_url="https://syneto-instance-ip-address/api/auth", insecure_ssl=True)
36
+ auth_api = Authentication(url_base="https://syneto-instance-ip-address/api/auth", insecure_ssl=True)
37
37
  response = auth_api.login(username="admin", password="admin")
38
38
  jwt = response['jwt']
39
39
 
40
- virt_api = Virtualization(base_url="https://syneto-instance-ip-address/api/virtualization", insecure_ssl=True)
40
+ virt_api = Virtualization(url_base="https://syneto-instance-ip-address/api/virtualization", insecure_ssl=True)
41
41
  virt_api.set_auth_jwt(jwt)
42
42
  print(virt_api.get_vms())
43
43
 
44
- storage_api = Storage(base_url="https://syneto-instance-ip-address/api/storage", insecure_ssl=True)
44
+ storage_api = Storage(url_base="https://syneto-instance-ip-address/api/storage", insecure_ssl=True)
45
45
  storage_api.set_auth_jwt(jwt)
46
46
  print(storage_api.get_pools())
47
47
  ```
@@ -13,15 +13,15 @@ $ pip install syneto-api
13
13
  ```
14
14
  from syneto_api import Authentication, Virtualization, Storage, Protection
15
15
 
16
- auth_api = Authentication(base_url="https://syneto-instance-ip-address/api/auth", insecure_ssl=True)
16
+ auth_api = Authentication(url_base="https://syneto-instance-ip-address/api/auth", insecure_ssl=True)
17
17
  response = auth_api.login(username="admin", password="admin")
18
18
  jwt = response['jwt']
19
19
 
20
- virt_api = Virtualization(base_url="https://syneto-instance-ip-address/api/virtualization", insecure_ssl=True)
20
+ virt_api = Virtualization(url_base="https://syneto-instance-ip-address/api/virtualization", insecure_ssl=True)
21
21
  virt_api.set_auth_jwt(jwt)
22
22
  print(virt_api.get_vms())
23
23
 
24
- storage_api = Storage(base_url="https://syneto-instance-ip-address/api/storage", insecure_ssl=True)
24
+ storage_api = Storage(url_base="https://syneto-instance-ip-address/api/storage", insecure_ssl=True)
25
25
  storage_api.set_auth_jwt(jwt)
26
26
  print(storage_api.get_pools())
27
27
  ```
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "syneto_api"
3
- version = "0.2.4"
3
+ version = "0.2.6"
4
4
  description = "Syneto Client API library"
5
5
  authors = ["Your Name <you@example.com>"]
6
6
  license = "Proprietary"
@@ -15,9 +15,9 @@ install_requires = \
15
15
 
16
16
  setup_kwargs = {
17
17
  'name': 'syneto-api',
18
- 'version': '0.2.4',
18
+ 'version': '0.2.6',
19
19
  'description': 'Syneto Client API library',
20
- 'long_description': '# Syneto API\n\nSyneto Client API library: authentication, storage, virtualization and protection\n\n# Installation\n\n```\n$ pip install syneto-api\n```\n\n# Basic Usage\n\n```\nfrom syneto_api import Authentication, Virtualization, Storage, Protection\n\nauth_api = Authentication(base_url="https://syneto-instance-ip-address/api/auth", insecure_ssl=True)\nresponse = auth_api.login(username="admin", password="admin")\njwt = response[\'jwt\']\n\nvirt_api = Virtualization(base_url="https://syneto-instance-ip-address/api/virtualization", insecure_ssl=True)\nvirt_api.set_auth_jwt(jwt)\nprint(virt_api.get_vms())\n\nstorage_api = Storage(base_url="https://syneto-instance-ip-address/api/storage", insecure_ssl=True)\nstorage_api.set_auth_jwt(jwt)\nprint(storage_api.get_pools())\n```\n\n# Environment Variables\n\nFor conveninence, the base urls for the api endpoints are also accepted as environment variables, please see below.\n\n```\nAUTH_SERVICE=https://syneto-instance-ip-address/api/auth\nVIRTUALIZATION_SERVICE=https://syneto-instance-ip-address/api/virtualization\nSTORAGE_SERVICE=https://syneto-instance-ip-address/api/storage\nPROTECTION_SERVICE=https://syneto-instance-ip-address/api/protection\n```\n\nIf you are using self-signed SSL certificates, set the following env. so that the http request library does not perform ssl verification. \n\n```\nALLOW_INSECURE_SSL=True\n```\n',
20
+ 'long_description': '# Syneto API\n\nSyneto Client API library: authentication, storage, virtualization and protection\n\n# Installation\n\n```\n$ pip install syneto-api\n```\n\n# Basic Usage\n\n```\nfrom syneto_api import Authentication, Virtualization, Storage, Protection\n\nauth_api = Authentication(url_base="https://syneto-instance-ip-address/api/auth", insecure_ssl=True)\nresponse = auth_api.login(username="admin", password="admin")\njwt = response[\'jwt\']\n\nvirt_api = Virtualization(url_base="https://syneto-instance-ip-address/api/virtualization", insecure_ssl=True)\nvirt_api.set_auth_jwt(jwt)\nprint(virt_api.get_vms())\n\nstorage_api = Storage(url_base="https://syneto-instance-ip-address/api/storage", insecure_ssl=True)\nstorage_api.set_auth_jwt(jwt)\nprint(storage_api.get_pools())\n```\n\n# Environment Variables\n\nFor conveninence, the base urls for the api endpoints are also accepted as environment variables, please see below.\n\n```\nAUTH_SERVICE=https://syneto-instance-ip-address/api/auth\nVIRTUALIZATION_SERVICE=https://syneto-instance-ip-address/api/virtualization\nSTORAGE_SERVICE=https://syneto-instance-ip-address/api/storage\nPROTECTION_SERVICE=https://syneto-instance-ip-address/api/protection\n```\n\nIf you are using self-signed SSL certificates, set the following env. so that the http request library does not perform ssl verification. \n\n```\nALLOW_INSECURE_SSL=True\n```\n',
21
21
  'author': 'Your Name',
22
22
  'author_email': 'you@example.com',
23
23
  'maintainer': None,
@@ -1,4 +1,6 @@
1
+ from .api_client import APIException
1
2
  from .auth_api import Authentication
2
3
  from .virt_api import Virtualization
3
4
  from .storage_api import Storage
4
5
  from .protection_api import Protection
6
+ from .jobs_api import Jobs
@@ -43,7 +43,7 @@ class APIClientBase:
43
43
  "POST": [200, 201, 202],
44
44
  "PUT": [200, 202],
45
45
  "PATCH": [200, 202],
46
- "DELETE": [200, 204],
46
+ "DELETE": [200, 202, 204],
47
47
  }
48
48
 
49
49
  def __init__(self, url_base=None, default_protocol="http", insecure_ssl=None):
@@ -91,10 +91,10 @@ class APIClientBase:
91
91
  try:
92
92
  response = method_func(url, timeout=20, **method_args)
93
93
  if response.status_code in success_codes:
94
- logger.debug("Received {response.status_code} from {method} {url}")
94
+ logger.debug(f"Received {response.status_code} from {method} {url}")
95
95
  return response.json()
96
96
 
97
- logger.info("Received {response.status_code} from {method} {url}")
97
+ logger.info(f"Received {response.status_code} from {method} {url}")
98
98
  raise APIException(
99
99
  url=url,
100
100
  status_code=response.status_code,
@@ -0,0 +1,23 @@
1
+ import os
2
+ from .api_client import APIClientBase
3
+
4
+
5
+ class Jobs(APIClientBase):
6
+ def __init__(self, url_base=None, **kwargs):
7
+ super().__init__(url_base or os.environ.get("PROTECTION_SERVICE", ""), **kwargs)
8
+
9
+ def get_jobs(self):
10
+ return self.get_request("/jobs")
11
+
12
+ def get_job(self, id: str):
13
+ return self.get_request("/jobs/{}", id)
14
+
15
+ def create_job(self, config: dict, job_type: str):
16
+ body = {"config": config, "type": job_type}
17
+ return self.post_request("/jobs", body=body)
18
+
19
+ def patch_job(self, id: str, body: dict):
20
+ return self.patch_request("/jobs", query_args={"id": id}, body=body)
21
+
22
+ def remove_job(self, id: str):
23
+ return self.delete_request("/jobs", query_args={"id": id})
@@ -18,8 +18,8 @@ class Protection(APIClientBase):
18
18
  def get_job(self, id):
19
19
  return self.get_request("/jobs/{}", id)
20
20
 
21
- def patch_job(self, id, payload):
22
- return self.patch_request("/jobs", query_args={"id": id}, body=payload)
21
+ def patch_job(self, id, body):
22
+ return self.patch_request("/jobs", query_args={"id": id}, body=body)
23
23
 
24
24
  def remove_job(self, id):
25
25
  return self.delete_request("/jobs", query_args={"id": id})
@@ -50,3 +50,11 @@ class Protection(APIClientBase):
50
50
 
51
51
  def patch_replication_host(self, id, payload):
52
52
  return self.patch_request("/hosts", query_args={"id": id}, body=payload)
53
+
54
+ def get_protected_vm(self, vm_syn_id: str):
55
+ return self.get_request("/vms/{vm_syn_id}", vm_syn_id=vm_syn_id)
56
+
57
+ def post_vm_recovery_point(self, vm_syn_id: str, job_id: str):
58
+ return self.post_request(
59
+ "/vms/recovery-points", body={"synId": vm_syn_id, "jobId": job_id}
60
+ )
@@ -66,9 +66,7 @@ class Storage(APIClientBase):
66
66
  return self.get_request("/volumes/{volume_id}", volume_id=volume_id,)
67
67
 
68
68
  def delete_volume(self, volume_id: str):
69
- return self.delete_request(
70
- "/volumes/{volume_id}", query_args={"volume_id": volume_id},
71
- )
69
+ return self.delete_request("/volumes", query_args={"volume_id": volume_id},)
72
70
 
73
71
  def promote_volume(self, volume_id: str):
74
72
  return self.put_request("/volumes/{volume_id}/promote", volume_id=volume_id)
@@ -130,23 +128,22 @@ class Storage(APIClientBase):
130
128
  )
131
129
 
132
130
  def get_volume_files(self, volume_id: str):
133
- return self.get_request(
134
- "/volumes/{volume_id}/files",
135
- volume_id=volume_id
136
- )
131
+ return self.get_request("/volumes/{volume_id}/files", volume_id=volume_id)
137
132
 
138
- def delete_volume_files(self, volume_id: str, file_path: str = None, pattern: str = None):
133
+ def delete_volume_files(
134
+ self, volume_id: str, file_path: str = None, pattern: str = None
135
+ ):
139
136
  return self.delete_request(
140
137
  "/volumes/{volume_id}/files",
141
138
  volume_id=volume_id,
142
- query_args={"file_path": file_path, "pattern": pattern}
139
+ query_args={"file_path": file_path, "pattern": pattern},
143
140
  )
144
141
 
145
142
  def get_volume_file_content(self, volume_id: str, file_path: str):
146
143
  return self.get_request(
147
144
  "/volumes/{volume_id}/files/content",
148
145
  volume_id=volume_id,
149
- query_args={"file_path": file_path}
146
+ query_args={"file_path": file_path},
150
147
  )
151
148
 
152
149
  def set_volume_file_content(self, volume_id: str, file_path: str, content: str):
@@ -154,19 +151,19 @@ class Storage(APIClientBase):
154
151
  "/volumes/{volume_id}/files/content",
155
152
  volume_id=volume_id,
156
153
  query_args={"file_path": file_path},
157
- body={'content': content}
154
+ body={"content": content},
158
155
  )
159
156
 
160
157
  def create_directory_in_volume(self, volume_id: str, dir_path: str):
161
158
  return self.post_request(
162
159
  "/volumes/{volume_id}/folder",
163
160
  volume_id=volume_id,
164
- query_args={"dir_path": dir_path}
161
+ query_args={"dir_path": dir_path},
165
162
  )
166
163
 
167
164
  def delete_directory_in_volume(self, volume_id: str, dir_path: str):
168
165
  return self.delete_request(
169
166
  "/volumes/{volume_id}/folder",
170
167
  volume_id=volume_id,
171
- query_args={"dir_path": dir_path}
168
+ query_args={"dir_path": dir_path},
172
169
  )
@@ -0,0 +1,86 @@
1
+ import os
2
+ from .api_client import APIClientBase
3
+
4
+
5
+ class Virtualization(APIClientBase):
6
+ def __init__(self, url_base=None, **kwargs):
7
+ super().__init__(
8
+ url_base or os.environ.get("VIRTUALIZATION_SERVICE", ""), **kwargs
9
+ )
10
+
11
+ def wait_for_task(self, task_syn_id):
12
+ while True:
13
+ try:
14
+ result = self.get_request(
15
+ "/vmware/tasks/{task_syn_id}", task_syn_id=task_syn_id
16
+ )
17
+ if result["state"] in ["success"]:
18
+ return
19
+ except APIException as e:
20
+ raise
21
+
22
+ def get_hypervisors(self):
23
+ return self.get_request("/hypervisors")
24
+
25
+ def get_vms(self):
26
+ return self.get_request("/vms")
27
+
28
+ def get_vmware_hosts(self):
29
+ return self.get_request("/vmware/hosts")
30
+
31
+ def get_vmware_datastores(self):
32
+ return self.get_request("/vmware/datastores")
33
+
34
+ def get_vm_snapshot(self, vm_syn_id: str, snapshot_name: str):
35
+ snapshots = self.get_request("/vms/{vm_syn_id}/snapshots", vm_syn_id=vm_syn_id)
36
+ return next((snap for snap in snapshots if snap["name"] == snapshot_name), None)
37
+
38
+ def create_vm_snapshot(
39
+ self,
40
+ vm_syn_id: str,
41
+ snapshot_name: str,
42
+ quiesce: bool = True,
43
+ dumpmem: bool = False,
44
+ ):
45
+ body = {
46
+ "name": snapshot_name,
47
+ "description": snapshot_name,
48
+ "quiesce": quiesce,
49
+ "dumpmem": dumpmem,
50
+ }
51
+ task = self.post_request(
52
+ "/vms/{vm_syn_id}/snapshots",
53
+ vm_syn_id=vm_syn_id,
54
+ query_args={"wait_for_task": "false"},
55
+ body=body,
56
+ )
57
+ self.wait_for_task(task["synId"])
58
+ return self.get_vm_snapshot(vm_syn_id, snapshot_name)
59
+
60
+ def delete_vm_snapshot(self, vm_syn_id, snapshot_ref_id):
61
+ task = self.delete_request(
62
+ "/vms/{vm_syn_id}/snapshots",
63
+ vm_syn_id=vm_syn_id,
64
+ query_args={"snapshot_ref_id": snapshot_ref_id, "wait_for_task": "true"},
65
+ success_codes=[200, 202, 204],
66
+ )
67
+ self.wait_for_task(task["synId"])
68
+
69
+ def get_image_repository(self):
70
+ return self.get_request("/image-repository")
71
+
72
+ def create_nas_datastore(self, server: str, mountpoint: str, hosts_syn_ids=None):
73
+ return self.post_request(
74
+ "/vmware/datastores",
75
+ body={
76
+ "server": server,
77
+ "mountpoint": mountpoint,
78
+ "hosts_syn_ids": hosts_syn_ids if hosts_syn_ids else [],
79
+ },
80
+ )
81
+
82
+ def delete_nas_datastore(self, syn_id: str = None, mountpoint: str = None):
83
+ return self.delete_request(
84
+ "/vmware/datastores",
85
+ query_args={"datastore_syn_id": syn_id, "datastore_mountpoint": mountpoint},
86
+ )
@@ -1,40 +0,0 @@
1
- import os
2
- from .api_client import APIClientBase
3
-
4
-
5
- class Virtualization(APIClientBase):
6
- def __init__(self, url_base=None, **kwargs):
7
- super().__init__(
8
- url_base or os.environ.get("VIRTUALIZATION_SERVICE", ""), **kwargs
9
- )
10
-
11
- def get_hypervisors(self):
12
- return self.get_request("/hypervisors")
13
-
14
- def get_vms(self):
15
- return self.get_request("/vms")
16
-
17
- def get_vmware_hosts(self):
18
- return self.get_request("/vmware/hosts")
19
-
20
- def get_vmware_datastores(self):
21
- return self.get_request("/vmware/datastores")
22
-
23
- def get_image_repository(self):
24
- return self.get_request("/image-repository")
25
-
26
- def create_nas_datastore(self, server: str, mountpoint: str, hosts_syn_ids=None):
27
- return self.post_request(
28
- "/vmware/datastores",
29
- body={
30
- "server": server,
31
- "mountpoint": mountpoint,
32
- "hosts_syn_ids": hosts_syn_ids if hosts_syn_ids else [],
33
- },
34
- )
35
-
36
- def delete_nas_datastore(self, syn_id: str = None, mountpoint: str = None):
37
- return self.delete_request(
38
- "/vmware/datastores",
39
- query_args={"datastore_syn_id": syn_id, "datastore_mountpoint": mountpoint},
40
- )