cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
cFSPlib.python_api_client.swagger_client.rest.RESTClientObject Class Reference
Inheritance diagram for cFSPlib.python_api_client.swagger_client.rest.RESTClientObject:
[legend]
Collaboration diagram for cFSPlib.python_api_client.swagger_client.rest.RESTClientObject:
[legend]

Public Member Functions

def __init__ (self, configuration, pools_size=4, maxsize=None)
 
def request (self, method, url, query_params=None, headers=None, body=None, post_params=None, _preload_content=True, _request_timeout=None)
 
def GET (self, url, headers=None, query_params=None, _preload_content=True, _request_timeout=None)
 
def HEAD (self, url, headers=None, query_params=None, _preload_content=True, _request_timeout=None)
 
def OPTIONS (self, url, headers=None, query_params=None, post_params=None, body=None, _preload_content=True, _request_timeout=None)
 
def DELETE (self, url, headers=None, query_params=None, body=None, _preload_content=True, _request_timeout=None)
 
def POST (self, url, headers=None, query_params=None, post_params=None, body=None, _preload_content=True, _request_timeout=None)
 
def PUT (self, url, headers=None, query_params=None, post_params=None, body=None, _preload_content=True, _request_timeout=None)
 
def PATCH (self, url, headers=None, query_params=None, post_params=None, body=None, _preload_content=True, _request_timeout=None)
 

Public Attributes

 pool_manager
 

Detailed Description

Definition at line 52 of file rest.py.

Constructor & Destructor Documentation

◆ __init__()

def cFSPlib.python_api_client.swagger_client.rest.RESTClientObject.__init__ (   self,
  configuration,
  pools_size = 4,
  maxsize = None 
)

Definition at line 54 of file rest.py.

54  def __init__(self, configuration, pools_size=4, maxsize=None):
55  # urllib3.PoolManager will pass all kw parameters to connectionpool
56  # https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/poolmanager.py#L75 # noqa: E501
57  # https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/connectionpool.py#L680 # noqa: E501
58  # maxsize is the number of requests to host that are allowed in parallel # noqa: E501
59  # Custom SSL certificates and client certificates: http://urllib3.readthedocs.io/en/latest/advanced-usage.html # noqa: E501
60 
61  # cert_reqs
62  if configuration.verify_ssl:
63  cert_reqs = ssl.CERT_REQUIRED
64  else:
65  cert_reqs = ssl.CERT_NONE
66 
67  # ca_certs
68  if configuration.ssl_ca_cert:
69  ca_certs = configuration.ssl_ca_cert
70  else:
71  # if not set certificate file, use Mozilla's root certificates.
72  ca_certs = certifi.where()
73 
74  addition_pool_args = {}
75  if configuration.assert_hostname is not None:
76  addition_pool_args['assert_hostname'] = configuration.assert_hostname # noqa: E501
77 
78  if maxsize is None:
79  if configuration.connection_pool_maxsize is not None:
80  maxsize = configuration.connection_pool_maxsize
81  else:
82  maxsize = 4
83 
84  # https pool manager
85  if configuration.proxy:
86  self.pool_manager = urllib3.ProxyManager(
87  num_pools=pools_size,
88  maxsize=maxsize,
89  cert_reqs=cert_reqs,
90  ca_certs=ca_certs,
91  cert_file=configuration.cert_file,
92  key_file=configuration.key_file,
93  proxy_url=configuration.proxy,
94  **addition_pool_args
95  )
96  else:
97  self.pool_manager = urllib3.PoolManager(
98  num_pools=pools_size,
99  maxsize=maxsize,
100  cert_reqs=cert_reqs,
101  ca_certs=ca_certs,
102  cert_file=configuration.cert_file,
103  key_file=configuration.key_file,
104  **addition_pool_args
105  )
106 

Member Function Documentation

◆ DELETE()

def cFSPlib.python_api_client.swagger_client.rest.RESTClientObject.DELETE (   self,
  url,
  headers = None,
  query_params = None,
  body = None,
  _preload_content = True,
  _request_timeout = None 
)

Definition at line 252 of file rest.py.

253  _preload_content=True, _request_timeout=None):
254  return self.request("DELETE", url,
255  headers=headers,
256  query_params=query_params,
257  _preload_content=_preload_content,
258  _request_timeout=_request_timeout,
259  body=body)
260 
Here is the call graph for this function:

◆ GET()

def cFSPlib.python_api_client.swagger_client.rest.RESTClientObject.GET (   self,
  url,
  headers = None,
  query_params = None,
  _preload_content = True,
  _request_timeout = None 
)

Definition at line 226 of file rest.py.

227  _request_timeout=None):
228  return self.request("GET", url,
229  headers=headers,
230  _preload_content=_preload_content,
231  _request_timeout=_request_timeout,
232  query_params=query_params)
233 
Here is the call graph for this function:

◆ HEAD()

def cFSPlib.python_api_client.swagger_client.rest.RESTClientObject.HEAD (   self,
  url,
  headers = None,
  query_params = None,
  _preload_content = True,
  _request_timeout = None 
)

Definition at line 234 of file rest.py.

235  _request_timeout=None):
236  return self.request("HEAD", url,
237  headers=headers,
238  _preload_content=_preload_content,
239  _request_timeout=_request_timeout,
240  query_params=query_params)
241 
Here is the call graph for this function:

◆ OPTIONS()

def cFSPlib.python_api_client.swagger_client.rest.RESTClientObject.OPTIONS (   self,
  url,
  headers = None,
  query_params = None,
  post_params = None,
  body = None,
  _preload_content = True,
  _request_timeout = None 
)

Definition at line 242 of file rest.py.

243  body=None, _preload_content=True, _request_timeout=None):
244  return self.request("OPTIONS", url,
245  headers=headers,
246  query_params=query_params,
247  post_params=post_params,
248  _preload_content=_preload_content,
249  _request_timeout=_request_timeout,
250  body=body)
251 
Here is the call graph for this function:

◆ PATCH()

def cFSPlib.python_api_client.swagger_client.rest.RESTClientObject.PATCH (   self,
  url,
  headers = None,
  query_params = None,
  post_params = None,
  body = None,
  _preload_content = True,
  _request_timeout = None 
)

Definition at line 281 of file rest.py.

282  body=None, _preload_content=True, _request_timeout=None):
283  return self.request("PATCH", url,
284  headers=headers,
285  query_params=query_params,
286  post_params=post_params,
287  _preload_content=_preload_content,
288  _request_timeout=_request_timeout,
289  body=body)
290 
291 
Here is the call graph for this function:

◆ POST()

def cFSPlib.python_api_client.swagger_client.rest.RESTClientObject.POST (   self,
  url,
  headers = None,
  query_params = None,
  post_params = None,
  body = None,
  _preload_content = True,
  _request_timeout = None 
)

Definition at line 261 of file rest.py.

262  body=None, _preload_content=True, _request_timeout=None):
263  return self.request("POST", url,
264  headers=headers,
265  query_params=query_params,
266  post_params=post_params,
267  _preload_content=_preload_content,
268  _request_timeout=_request_timeout,
269  body=body)
270 
Here is the call graph for this function:

◆ PUT()

def cFSPlib.python_api_client.swagger_client.rest.RESTClientObject.PUT (   self,
  url,
  headers = None,
  query_params = None,
  post_params = None,
  body = None,
  _preload_content = True,
  _request_timeout = None 
)

Definition at line 271 of file rest.py.

272  body=None, _preload_content=True, _request_timeout=None):
273  return self.request("PUT", url,
274  headers=headers,
275  query_params=query_params,
276  post_params=post_params,
277  _preload_content=_preload_content,
278  _request_timeout=_request_timeout,
279  body=body)
280 
Here is the call graph for this function:

◆ request()

def cFSPlib.python_api_client.swagger_client.rest.RESTClientObject.request (   self,
  method,
  url,
  query_params = None,
  headers = None,
  body = None,
  post_params = None,
  _preload_content = True,
  _request_timeout = None 
)
Perform requests.

:param method: http request method
:param url: http request url
:param query_params: query parameters in the url
:param headers: http request headers
:param body: request json body, for `application/json`
:param post_params: request post parameters,
                    `application/x-www-form-urlencoded`
                    and `multipart/form-data`
:param _preload_content: if False, the urllib3.HTTPResponse object will
                         be returned without reading/decoding response
                         data. Default is True.
:param _request_timeout: timeout setting for this request. If one
                         number provided, it will be total request
                         timeout. It can also be a pair (tuple) of
                         (connection, read) timeouts.

Definition at line 107 of file rest.py.

109  _request_timeout=None):
110  """Perform requests.
111 
112  :param method: http request method
113  :param url: http request url
114  :param query_params: query parameters in the url
115  :param headers: http request headers
116  :param body: request json body, for `application/json`
117  :param post_params: request post parameters,
118  `application/x-www-form-urlencoded`
119  and `multipart/form-data`
120  :param _preload_content: if False, the urllib3.HTTPResponse object will
121  be returned without reading/decoding response
122  data. Default is True.
123  :param _request_timeout: timeout setting for this request. If one
124  number provided, it will be total request
125  timeout. It can also be a pair (tuple) of
126  (connection, read) timeouts.
127  """
128  method = method.upper()
129  assert method in ['GET', 'HEAD', 'DELETE', 'POST', 'PUT',
130  'PATCH', 'OPTIONS']
131 
132  if post_params and body:
133  raise ValueError(
134  "body parameter cannot be used with post_params parameter."
135  )
136 
137  post_params = post_params or {}
138  headers = headers or {}
139 
140  timeout = None
141  if _request_timeout:
142  if isinstance(_request_timeout, (int, ) if six.PY3 else (int, long)): # noqa: E501,F821
143  timeout = urllib3.Timeout(total=_request_timeout)
144  elif (isinstance(_request_timeout, tuple) and
145  len(_request_timeout) == 2):
146  timeout = urllib3.Timeout(
147  connect=_request_timeout[0], read=_request_timeout[1])
148 
149  if 'Content-Type' not in headers:
150  headers['Content-Type'] = 'application/json'
151 
152  try:
153  # For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE`
154  if method in ['POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE']:
155  if query_params:
156  url += '?' + urlencode(query_params)
157  if re.search('json', headers['Content-Type'], re.IGNORECASE):
158  request_body = '{}'
159  if body is not None:
160  request_body = json.dumps(body)
161  r = self.pool_manager.request(
162  method, url,
163  body=request_body,
164  preload_content=_preload_content,
165  timeout=timeout,
166  headers=headers)
167  elif headers['Content-Type'] == 'application/x-www-form-urlencoded': # noqa: E501
168  r = self.pool_manager.request(
169  method, url,
170  fields=post_params,
171  encode_multipart=False,
172  preload_content=_preload_content,
173  timeout=timeout,
174  headers=headers)
175  elif headers['Content-Type'] == 'multipart/form-data':
176  # must del headers['Content-Type'], or the correct
177  # Content-Type which generated by urllib3 will be
178  # overwritten.
179  del headers['Content-Type']
180  r = self.pool_manager.request(
181  method, url,
182  fields=post_params,
183  encode_multipart=True,
184  preload_content=_preload_content,
185  timeout=timeout,
186  headers=headers)
187  # Pass a `string` parameter directly in the body to support
188  # other content types than Json when `body` argument is
189  # provided in serialized form
190  elif isinstance(body, str):
191  request_body = body
192  r = self.pool_manager.request(
193  method, url,
194  body=request_body,
195  preload_content=_preload_content,
196  timeout=timeout,
197  headers=headers)
198  else:
199  # Cannot generate the request from given parameters
200  msg = """Cannot prepare a request message for provided
201  arguments. Please check that your arguments match
202  declared content type."""
203  raise ApiException(status=0, reason=msg)
204  # For `GET`, `HEAD`
205  else:
206  r = self.pool_manager.request(method, url,
207  fields=query_params,
208  preload_content=_preload_content,
209  timeout=timeout,
210  headers=headers)
211  except urllib3.exceptions.SSLError as e:
212  msg = "{0}\n{1}".format(type(e).__name__, str(e))
213  raise ApiException(status=0, reason=msg)
214 
215  if _preload_content:
216  r = RESTResponse(r)
217 
218  # log response body
219  logger.debug("response body: %s", r.data)
220 
221  if not 200 <= r.status <= 299:
222  raise ApiException(http_resp=r)
223 
224  return r
225 
Here is the caller graph for this function:

Member Data Documentation

◆ pool_manager

cFSPlib.python_api_client.swagger_client.rest.RESTClientObject.pool_manager

Definition at line 86 of file rest.py.


The documentation for this class was generated from the following file: