oc-cdtapi 3.12.0__py3-none-any.whl → 3.13.3__py3-none-any.whl
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.
- oc_cdtapi/Dbsm2API.py +233 -0
- oc_cdtapi/DmsGetverAPI.py +3 -5
- {oc_cdtapi-3.12.0.dist-info → oc_cdtapi-3.13.3.dist-info}/METADATA +1 -1
- {oc_cdtapi-3.12.0.dist-info → oc_cdtapi-3.13.3.dist-info}/RECORD +8 -7
- {oc_cdtapi-3.12.0.data → oc_cdtapi-3.13.3.data}/scripts/nexus.py +0 -0
- {oc_cdtapi-3.12.0.dist-info → oc_cdtapi-3.13.3.dist-info}/LICENSE +0 -0
- {oc_cdtapi-3.12.0.dist-info → oc_cdtapi-3.13.3.dist-info}/WHEEL +0 -0
- {oc_cdtapi-3.12.0.dist-info → oc_cdtapi-3.13.3.dist-info}/top_level.txt +0 -0
oc_cdtapi/Dbsm2API.py
ADDED
@@ -0,0 +1,233 @@
|
|
1
|
+
import json
|
2
|
+
import logging
|
3
|
+
import os
|
4
|
+
import tempfile
|
5
|
+
import time
|
6
|
+
|
7
|
+
from . import API
|
8
|
+
import posixpath
|
9
|
+
|
10
|
+
|
11
|
+
class Dbsm2API (API.HttpAPI):
|
12
|
+
_env_prefix = 'DBSM2'
|
13
|
+
|
14
|
+
def __init__(self, *args, **argv):
|
15
|
+
logging.debug('Reached __init__')
|
16
|
+
logging.debug('Calling base class constructor for availability of HttpAPI methods')
|
17
|
+
|
18
|
+
# TODO: re-factor when Python2 support will be deprecated
|
19
|
+
super(Dbsm2API, self).__init__(*args, **argv)
|
20
|
+
|
21
|
+
# auth token
|
22
|
+
self.auth_token = None
|
23
|
+
|
24
|
+
# delivery states or images in process
|
25
|
+
self.waiting_states = ['UNKNOWN']
|
26
|
+
|
27
|
+
# delivery states or images finished
|
28
|
+
self.exit_states = ['FAILED', 'SUCCESS']
|
29
|
+
|
30
|
+
# wait for state timeout
|
31
|
+
self.wait_state_timeout = 1000
|
32
|
+
|
33
|
+
# wait for state request interval
|
34
|
+
self.wait_state_sleep = 30
|
35
|
+
|
36
|
+
# oracle version
|
37
|
+
self.oracle_version = '19.16.0.0.0'
|
38
|
+
|
39
|
+
# oracle encoding
|
40
|
+
self.oracle_encoding = 'AL32UTF8'
|
41
|
+
|
42
|
+
# oracle edition
|
43
|
+
self.oracle_edition = 'EE'
|
44
|
+
|
45
|
+
# remove auth to stop requests overriding headers, do not raise exceptions on minor http errors
|
46
|
+
self.web.auth = None
|
47
|
+
self.raise_exception_high = 499
|
48
|
+
|
49
|
+
def create_custom_image(self, version=None, distr_type=None, client_filter=None, client_code=None):
|
50
|
+
"""
|
51
|
+
Sends request to create custom image
|
52
|
+
:param str version: version of product
|
53
|
+
:param str distr_type: type of product
|
54
|
+
:param str client_filter: client specific filter list
|
55
|
+
:param str client_code: client code
|
56
|
+
"""
|
57
|
+
logging.debug('Reached create_custom_image')
|
58
|
+
logging.debug('version: [%s]' % version)
|
59
|
+
logging.debug('distr_type: [%s]' % distr_type)
|
60
|
+
logging.debug('client_filter: [%s]' % client_filter)
|
61
|
+
logging.debug('client_code: [%s]' % client_code)
|
62
|
+
|
63
|
+
url = posixpath.join('api', 'v1', 'images', 'custom-cdt')
|
64
|
+
headers = self.get_headers()
|
65
|
+
params = {
|
66
|
+
'image_type': 'CUSTOM',
|
67
|
+
'product_type': distr_type.lower(),
|
68
|
+
'product_version': version,
|
69
|
+
'custom_attribute': client_code,
|
70
|
+
'getver_filter': client_filter,
|
71
|
+
'oracle_encoding': self.oracle_encoding,
|
72
|
+
'oracle_version': self.oracle_version,
|
73
|
+
'oracle_edition': self.oracle_edition,
|
74
|
+
'remap_tablespaces': 'true'
|
75
|
+
}
|
76
|
+
r = self.post(url, headers=headers, json=params)
|
77
|
+
return self.json_or_none(r)
|
78
|
+
|
79
|
+
def download_file(self, image_id):
|
80
|
+
"""
|
81
|
+
Downloads specified image to file
|
82
|
+
:param str image_id: id of image to download
|
83
|
+
:return: path to downloaded file
|
84
|
+
"""
|
85
|
+
logging.debug('Reached download_file')
|
86
|
+
logging.debug('image_id: [%s]' % image_id)
|
87
|
+
logging.debug('Unsetting auth')
|
88
|
+
headers = self.get_headers()
|
89
|
+
url = posixpath.join('api', 'v1', 'images', image_id, 'download')
|
90
|
+
logging.debug('url: [%s]' % url)
|
91
|
+
tf = tempfile.NamedTemporaryFile()
|
92
|
+
logging.debug('tf: [%s]' % tf)
|
93
|
+
r = self.get(url, headers=headers, stream=True)
|
94
|
+
for chunk in r.iter_content(chunk_size=8192):
|
95
|
+
tf.write(chunk)
|
96
|
+
tf.seek(0)
|
97
|
+
return tf
|
98
|
+
|
99
|
+
def get_audit(self, audit_id):
|
100
|
+
"""
|
101
|
+
Requests audit record by record id
|
102
|
+
:param str audit_id: id of audit record
|
103
|
+
:return: audit record
|
104
|
+
"""
|
105
|
+
logging.debug('Reached get_audit')
|
106
|
+
logging.debug('audit_id: [%s]' % audit_id)
|
107
|
+
headers = self.get_headers()
|
108
|
+
url = posixpath.join('api', 'v1', 'audit', audit_id)
|
109
|
+
r = self.get(url, headers=headers)
|
110
|
+
return self.json_or_none(r)
|
111
|
+
|
112
|
+
def get_headers(self):
|
113
|
+
"""
|
114
|
+
"""
|
115
|
+
logging.debug('Reached get_headers')
|
116
|
+
logging.debug('auth_token length: [%s]' % len(self.auth_token))
|
117
|
+
headers = {'Accept': 'application/json; charset=utf-8', 'Authorization': f'Bearer {self.auth_token}'}
|
118
|
+
return headers
|
119
|
+
|
120
|
+
def search_image(self, version=None, distr_type=None):
|
121
|
+
"""
|
122
|
+
searches for images, calls download
|
123
|
+
:return: path to temp file, image data
|
124
|
+
"""
|
125
|
+
logging.debug('Reached download_image')
|
126
|
+
logging.debug('Unsetting auth')
|
127
|
+
logging.debug('version = [%s]' % version)
|
128
|
+
logging.debug('distr_type = [%s]' % distr_type)
|
129
|
+
|
130
|
+
url = posixpath.join('api', 'v1', 'images')
|
131
|
+
headers = self.get_headers()
|
132
|
+
params = {
|
133
|
+
'strict_filters': 'true',
|
134
|
+
'product_type': distr_type.lower(),
|
135
|
+
'product_version': version,
|
136
|
+
'product_release_stage': 'release',
|
137
|
+
'remap_tablespaces': 'true'
|
138
|
+
}
|
139
|
+
resp = self.get(url, headers=headers, params=params)
|
140
|
+
if not resp.status_code == 200:
|
141
|
+
logging.error('Server returned an error [%s] [%s]' % (resp.status_code, resp.text))
|
142
|
+
return None
|
143
|
+
images = resp.json()['items']
|
144
|
+
logging.debug('found [%s] images' % len(images))
|
145
|
+
logging.debug('Dumping images data')
|
146
|
+
logging.debug(json.dumps(images, indent=4))
|
147
|
+
for image in images:
|
148
|
+
image_id = image['id']
|
149
|
+
image_name = image['name']
|
150
|
+
oracle_version = image.get('oracle_version')
|
151
|
+
customisation = image.get('customisation')
|
152
|
+
logging.debug('checking images [%s]' % image_name)
|
153
|
+
if oracle_version['oracle_edition'] == self.oracle_edition and customisation is None:
|
154
|
+
logging.debug('image is enterprise edition')
|
155
|
+
return image
|
156
|
+
logging.error('No images found')
|
157
|
+
return None
|
158
|
+
|
159
|
+
def json_or_none(self, resp):
|
160
|
+
"""
|
161
|
+
Returns requests response's json if status code is 200-299 or logs error and returns None
|
162
|
+
:param requests.response resp: requests' response
|
163
|
+
:return: requests.response.json or None
|
164
|
+
"""
|
165
|
+
logging.debug('Reached json_or_none')
|
166
|
+
status_code = resp.status_code
|
167
|
+
if 200 <= status_code <= 299:
|
168
|
+
logging.debug('[%s] status code received, trying to return json' % status_code)
|
169
|
+
return resp.json()
|
170
|
+
else:
|
171
|
+
logging.error('[%s] status code received, assuming an error, returning None' % status_code)
|
172
|
+
return None
|
173
|
+
|
174
|
+
def login(self):
|
175
|
+
"""
|
176
|
+
Obtain auth token
|
177
|
+
"""
|
178
|
+
logging.debug('Reached login')
|
179
|
+
username = os.getenv('DBSM2_USER')
|
180
|
+
password = os.getenv('DBSM2_PASSWORD')
|
181
|
+
login_data = {
|
182
|
+
'grant_type': '',
|
183
|
+
'username': username,
|
184
|
+
'password': password,
|
185
|
+
'scope': '',
|
186
|
+
'client_id': '',
|
187
|
+
'client_secret': ''
|
188
|
+
}
|
189
|
+
url = posixpath.join('api', 'v1', 'auth', 'access-token')
|
190
|
+
resp = self.post(url, data=login_data)
|
191
|
+
resp_data = resp.json()
|
192
|
+
if resp.status_code == 200:
|
193
|
+
token_type = resp_data['token_type']
|
194
|
+
access_token = resp_data['access_token']
|
195
|
+
else:
|
196
|
+
logging.debug('Server returned an error [%s] [%s]' % (resp.status_code, resp.text))
|
197
|
+
return None
|
198
|
+
logging.debug('token_type: [%s]' % token_type)
|
199
|
+
logging.debug('access_token: [%s]' % access_token)
|
200
|
+
self.auth_token = access_token
|
201
|
+
return token_type, access_token
|
202
|
+
|
203
|
+
def wait_for_image(self, audit_id):
|
204
|
+
"""
|
205
|
+
Performs periodic requests for audit record.
|
206
|
+
Returns audit record when it is in exit state.
|
207
|
+
:param str audit_id: id of audit record
|
208
|
+
:return: audit record
|
209
|
+
"""
|
210
|
+
logging.debug('Reached wait_for_image')
|
211
|
+
logging.debug('audit_id: [%s]' % audit_id)
|
212
|
+
ela = 0
|
213
|
+
st = int(time.time())
|
214
|
+
audit = None
|
215
|
+
|
216
|
+
while ela < self.wait_state_timeout:
|
217
|
+
ela = int(time.time()) - st
|
218
|
+
|
219
|
+
audit = self.get_audit(audit_id)
|
220
|
+
|
221
|
+
if not audit:
|
222
|
+
logging.error('get_audit returned None')
|
223
|
+
return None
|
224
|
+
|
225
|
+
status = audit['status']
|
226
|
+
logging.debug('received audit object in status [%s]' % status)
|
227
|
+
|
228
|
+
if status in self.exit_states:
|
229
|
+
logging.debug('audit is in exit state, returning')
|
230
|
+
return audit
|
231
|
+
|
232
|
+
return None
|
233
|
+
|
oc_cdtapi/DmsGetverAPI.py
CHANGED
@@ -32,11 +32,9 @@ class DmsGetverAPI (API.HttpAPI):
|
|
32
32
|
def create_distr_request(self, version=None, source_version=None, distr_type=None, client_filter=None):
|
33
33
|
"""
|
34
34
|
Creates a new distribution request
|
35
|
-
:param str version: required version
|
36
|
-
:param str distr_type: distribution type
|
37
|
-
:param client_filter: a set of software components
|
38
|
-
if not provided an attempt to fetch it from svn will be performed
|
39
|
-
filter fetching is defined in separate class
|
35
|
+
:param str version: required version
|
36
|
+
:param str distr_type: distribution type
|
37
|
+
:param client_filter: a set of software components
|
40
38
|
:return: distribution state info as returned by dms
|
41
39
|
"""
|
42
40
|
logging.debug('Reached create_distr_request')
|
@@ -1,16 +1,17 @@
|
|
1
1
|
oc_cdtapi/API.py,sha256=hpdnzyirYT_wISeznRmoqr-umYRT6uqKVwhmCXyj8Nk,12398
|
2
|
+
oc_cdtapi/Dbsm2API.py,sha256=40aBWuMxtCVzplJ9GRMlpwv4TMdI8tdCAU87lVH221w,8262
|
2
3
|
oc_cdtapi/DevPIAPI.py,sha256=Nn63Ob0kA5XXuRZ3OIWG2rcnSsztKq9yPI6Lu2zX3Gk,1836
|
3
4
|
oc_cdtapi/DmsAPI.py,sha256=eNFdwQLhCbPvHB5SUtP4QcZZtSdjkgt_Cxn3oQ3iJ5s,15605
|
4
|
-
oc_cdtapi/DmsGetverAPI.py,sha256=
|
5
|
+
oc_cdtapi/DmsGetverAPI.py,sha256=UD096EW8IErIKMCnRGab7XK_bQ5hp5MX9cVU_3W1e6g,15519
|
5
6
|
oc_cdtapi/ForemanAPI.py,sha256=Ep6cr0LZ-CwdUncqhFMthOo4klFjTR81hdNhVpAMCCk,42819
|
6
7
|
oc_cdtapi/JenkinsAPI.py,sha256=lZ8pe3a4eb_6h53JE7QLuzOSlu7Sqatc9PQwWhio9Vg,15748
|
7
8
|
oc_cdtapi/NexusAPI.py,sha256=uU12GtHvKlWorFaPAnFcQ5AGEc94MZ5SdmfM2Pw3F7A,26122
|
8
9
|
oc_cdtapi/RundeckAPI.py,sha256=O3LmcFaHSz8UqeUyIHTTEMJncDD191Utd-iZaeJay2s,24243
|
9
10
|
oc_cdtapi/TestServer.py,sha256=HV97UWg2IK4gOYAp9yaMdwFUWsw9v66MxyZdI3qQctA,2715
|
10
11
|
oc_cdtapi/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
11
|
-
oc_cdtapi-3.
|
12
|
-
oc_cdtapi-3.
|
13
|
-
oc_cdtapi-3.
|
14
|
-
oc_cdtapi-3.
|
15
|
-
oc_cdtapi-3.
|
16
|
-
oc_cdtapi-3.
|
12
|
+
oc_cdtapi-3.13.3.data/scripts/nexus.py,sha256=4teqZ_KtCSrwHDJVgA7lkreteod4Xt5XJFZNbwb7E6E,6858
|
13
|
+
oc_cdtapi-3.13.3.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
14
|
+
oc_cdtapi-3.13.3.dist-info/METADATA,sha256=2pC3N_e6dmdyojNF1xcsuqOk64vCYESWKfOCFqMI084,254
|
15
|
+
oc_cdtapi-3.13.3.dist-info/WHEEL,sha256=Xo9-1PvkuimrydujYJAjF7pCkriuXBpUPEjma1nZyJ0,92
|
16
|
+
oc_cdtapi-3.13.3.dist-info/top_level.txt,sha256=d4-5-D-0CSeSXYuLCP7-nIFCpjkfmJr-Y_muzds8iVU,10
|
17
|
+
oc_cdtapi-3.13.3.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|