Skip to content

Commit 0a31600

Browse files
committed
modified DelphixClient.py
0 parents  commit 0a31600

File tree

11 files changed

+438
-0
lines changed

11 files changed

+438
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#
2+
# Copyright 2018 XEBIALABS + MSA (Mouhssine SAIDI COE DELPHIX)
3+
#
4+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5+
#
6+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7+
#
8+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9+
#
10+
if __name__ == '__main__':
11+
import sys
12+
13+
# sys.path.append('/Users/bmoussaud/Workspace/xebialabs-community/xlr-delphix-plugin/src/main/resources')
14+
sys.path.append('/u02/app/xebialabs/xlr-delphix-plugin/src/main/resources')
15+
# server = {'url': 'http://ba5b5824.ngrok.io', 'username': 'delphix_admin', 'password': 'landshark'}
16+
server = {'url': 'http://192.168.247.132', 'username': 'delphix_admin', 'password': 'landshark'}
17+
vdb = 'tst'
18+
19+
from delphix.DelphixClient import DelphixClient
20+
21+
client = DelphixClient(server)
22+
output = client.delete(vdb)
23+
job = output['job']
24+
action = output['action']
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
#
2+
# Copyright 2018 XEBIALABS
3+
#
4+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5+
#
6+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7+
#
8+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9+
#
10+
11+
import requests
12+
import json
13+
14+
15+
class DelphixClient:
16+
17+
def __init__(self, server):
18+
self.server = server
19+
self.cookies = self.get_session()
20+
21+
def get_session(self):
22+
print('- open session on {0}'.format(self.server['url']))
23+
headers = {'Content-type': 'application/json'}
24+
data = {
25+
"type": "APISession",
26+
"version": {
27+
"type": "APIVersion",
28+
"major": 1,
29+
"minor": 8,
30+
"micro": 2
31+
}
32+
}
33+
34+
r = requests.post('{0}/resources/json/delphix/session'.format(self.server['url']),
35+
headers=headers,
36+
data=json.dumps(data))
37+
return r.cookies
38+
39+
def _login(self):
40+
print('- login')
41+
headers = {'Content-type': 'application/json'}
42+
data = {
43+
"type": "LoginRequest",
44+
"username": self.server['username'],
45+
"password": self.server['password'],
46+
}
47+
r = requests.post('{0}/resources/json/delphix/login'.format(self.server['url']),
48+
headers=headers,
49+
cookies=self.cookies,
50+
data=json.dumps(data))
51+
52+
if self._response_ok(r):
53+
print("- Authenticated ! ")
54+
else:
55+
raise self._response_error(r)
56+
return r.text
57+
58+
def _logout(self):
59+
print('- logout')
60+
headers = {'Content-type': 'application/json'}
61+
requests.post('{0}/resources/json/delphix/logout'.format(self.server['url']),
62+
headers=headers,
63+
cookies=self.cookies)
64+
65+
def _get_params(self, vdb):
66+
result = {'ref': 'XXXX', 'cont': 'YYYY', 'vsrc': 'ZZZZ'}
67+
print('- get params')
68+
headers = {'Content-type': 'application/json'}
69+
70+
r = requests.get('{0}/resources/json/delphix/database'.format(self.server['url']),
71+
headers=headers,
72+
cookies=self.cookies)
73+
74+
for db in r.json()['result']:
75+
if db['name'] == vdb:
76+
result['ref'] = db['reference']
77+
result['cont'] = db['provisionContainer']
78+
79+
r = requests.get('{0}/resources/json/delphix/source'.format(self.server['url']),
80+
headers=headers,
81+
cookies=self.cookies)
82+
83+
for db in r.json()['result']:
84+
if db['name'] == vdb:
85+
result['vsrc'] = db['reference']
86+
87+
print('- database reference {ref}'.format(**result))
88+
print('- database provisionContainer {cont}'.format(**result))
89+
print('- source reference {vsrc}'.format(**result))
90+
return result
91+
92+
def _refresh(self, vdb):
93+
parameters = self._get_params(vdb=vdb)
94+
print("- refresh ")
95+
headers = {'Content-type': 'application/json'}
96+
data = {
97+
"type": "OracleRefreshParameters",
98+
"timeflowPointParameters": {
99+
"type": "TimeflowPointSemantic",
100+
"container": parameters['cont'],
101+
"location": "LATEST_SNAPSHOT"
102+
}
103+
}
104+
105+
r = requests.post(
106+
'{0}/resources/json/delphix/database/{1}/refresh'.format(self.server['url'], parameters['ref']),
107+
headers=headers,
108+
cookies=self.cookies,
109+
data=json.dumps(data))
110+
if self._response_ok(r):
111+
print("- Job {0}".format(r.json()['job']))
112+
print("- Action {0}".format(r.json()['action']))
113+
return {'job': r.json()['job'], 'action': r.json()['action']}
114+
else:
115+
raise self._response_error(r)
116+
117+
def _rewind(self, vdb):
118+
parameters = self._get_params(vdb=vdb)
119+
print("- rewind ")
120+
headers = {'Content-type': 'application/json'}
121+
data = {
122+
"type": "OracleRollbackParameters",
123+
"timeflowPointParameters": {
124+
"type": "TimeflowPointSemantic",
125+
"container": parameters['cont'],
126+
"location": "LATEST_SNAPSHOT"
127+
}
128+
}
129+
130+
r = requests.post(
131+
'{0}/resources/json/delphix/database/{1}/rollback'.format(self.server['url'], parameters['ref']),
132+
headers=headers,
133+
cookies=self.cookies,
134+
data=json.dumps(data))
135+
if self._response_ok(r):
136+
print("- Job {0}".format(r.json()['job']))
137+
print("- Action {0}".format(r.json()['action']))
138+
return {'job': r.json()['job'], 'action': r.json()['action']}
139+
else:
140+
raise self._response_error(r)
141+
142+
def _snapshot(self, vdb):
143+
parameters = self._get_params(vdb=vdb)
144+
print("- snapshot ")
145+
headers = {'Content-type': 'application/json'}
146+
data = {
147+
"type": "OracleSyncParameters"
148+
}
149+
150+
r = requests.post(
151+
'{0}/resources/json/delphix/database/{1}/sync'.format(self.server['url'], parameters['ref']),
152+
headers=headers,
153+
cookies=self.cookies,
154+
data=json.dumps(data))
155+
156+
if self._response_ok(r):
157+
print("- Job {0}".format(r.json()['job']))
158+
print("- Action {0}".format(r.json()['action']))
159+
return {'job': r.json()['job'], 'action': r.json()['action']}
160+
else:
161+
raise self._response_error(r)
162+
163+
def _response_ok(self, r):
164+
return r.status_code == 200 and r.json()['type'] == 'OKResult'
165+
166+
def _response_error(self, r):
167+
return Exception(r.text)
168+
169+
def refresh(self, vdb):
170+
self._login()
171+
print("- Refresh {0} with Delphix".format(vdb))
172+
result = self._refresh(vdb)
173+
self._logout()
174+
return result
175+
176+
def snapshot(self, vdb):
177+
self._login()
178+
print("- Snapshot {0} with Delphix".format(vdb))
179+
result = self._snapshot(vdb)
180+
self._logout()
181+
return result
182+
183+
def rewind(self, vdb):
184+
self._login()
185+
print("- Rewind {0} with Delphix".format(vdb))
186+
result = self._rewind(vdb)
187+
self._logout()
188+
return result
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#
2+
# Copyright 2018 XEBIALABS + MSA (Mouhssine SAIDI COE DELPHIX)
3+
#
4+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5+
#
6+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7+
#
8+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9+
#
10+
if __name__ == '__main__':
11+
import sys
12+
13+
# sys.path.append('/Users/bmoussaud/Workspace/xebialabs-community/xlr-delphix-plugin/src/main/resources')
14+
sys.path.append('/u02/app/xebialabs/xlr-delphix-plugin/src/main/resources')
15+
# server = {'url': 'http://ba5b5824.ngrok.io', 'username': 'delphix_admin', 'password': 'landshark'}
16+
server = {'url': 'http://192.168.247.132', 'username': 'delphix_admin', 'password': 'landshark'}
17+
vdb = 'XEBIA'
18+
19+
from delphix.DelphixClient import DelphixClient
20+
21+
client = DelphixClient(server)
22+
output = client.disable(vdb)
23+
job = output['job']
24+
action = output['action']
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#
2+
# Copyright 2018 XEBIALABS + MSA (Mouhssine SAIDI COE DELPHIX)
3+
#
4+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5+
#
6+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7+
#
8+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9+
#
10+
if __name__ == '__main__':
11+
import sys
12+
13+
# sys.path.append('/Users/bmoussaud/Workspace/xebialabs-community/xlr-delphix-plugin/src/main/resources')
14+
sys.path.append('/u02/app/xebialabs/xlr-delphix-plugin/src/main/resources')
15+
# server = {'url': 'http://ba5b5824.ngrok.io', 'username': 'delphix_admin', 'password': 'landshark'}
16+
server = {'url': 'http://192.168.247.132', 'username': 'delphix_admin', 'password': 'landshark'}
17+
vdb = 'XEBIA'
18+
19+
from delphix.DelphixClient import DelphixClient
20+
21+
client = DelphixClient(server)
22+
output = client.enable(vdb)
23+
job = output['job']
24+
action = output['action']
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#
2+
# Copyright 2018 XEBIALABS
3+
#
4+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5+
#
6+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7+
#
8+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9+
#
10+
if __name__ == '__main__':
11+
import sys
12+
13+
sys.path.append('/Users/bmoussaud/Workspace/xebialabs-community/xlr-delphix-plugin/src/main/resources')
14+
server = {'url': 'http://ba5b5824.ngrok.io', 'username': 'delphix_admin', 'password': 'landshark'}
15+
vdb = 'ITIM'
16+
17+
from delphix.DelphixClient import DelphixClient
18+
19+
client = DelphixClient(server)
20+
output = client.refresh(vdb)
21+
job = output['job']
22+
action = output['action']
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#
2+
# Copyright 2018 XEBIALABS
3+
#
4+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5+
#
6+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7+
#
8+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9+
#
10+
if __name__ == '__main__':
11+
import sys
12+
13+
sys.path.append('/Users/bmoussaud/Workspace/xebialabs-community/xlr-delphix-plugin/src/main/resources')
14+
server = {'url': 'http://ba5b5824.ngrok.io', 'username': 'delphix_admin', 'password': 'landshark'}
15+
vdb = 'ITIM'
16+
17+
from delphix.DelphixClient import DelphixClient
18+
19+
client = DelphixClient(server)
20+
client.rewind(vdb)
21+
job = output['job']
22+
action = output['action']
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#
2+
# Copyright 2018 XEBIALABS
3+
#
4+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5+
#
6+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7+
#
8+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9+
#
10+
if __name__ == '__main__':
11+
import sys
12+
13+
sys.path.append('/Users/bmoussaud/Workspace/xebialabs-community/xlr-delphix-plugin/src/main/resources')
14+
server = {'url': 'http://ba5b5824.ngrok.io', 'username': 'delphix_admin', 'password': 'landshark'}
15+
vdb = 'ITIM'
16+
17+
from delphix.DelphixClient import DelphixClient
18+
19+
client = DelphixClient(server)
20+
client.snapshot(vdb)
21+
job = output['job']
22+
action = output['action']
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#
2+
# Copyright 2018 XEBIALABS + MSA (Mouhssine SAIDI COE DELPHIX)
3+
#
4+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5+
#
6+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7+
#
8+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9+
#
10+
if __name__ == '__main__':
11+
import sys
12+
13+
# sys.path.append('/Users/bmoussaud/Workspace/xebialabs-community/xlr-delphix-plugin/src/main/resources')
14+
sys.path.append('/u02/app/xebialabs/xlr-delphix-plugin/src/main/resources')
15+
# server = {'url': 'http://ba5b5824.ngrok.io', 'username': 'delphix_admin', 'password': 'landshark'}
16+
server = {'url': 'http://192.168.247.132', 'username': 'delphix_admin', 'password': 'landshark'}
17+
vdb = 'XEBIA'
18+
19+
from delphix.DelphixClient import DelphixClient
20+
21+
client = DelphixClient(server)
22+
output = client.start(vdb)
23+
job = output['job']
24+
action = output['action']

0 commit comments

Comments
 (0)