cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
configuration.py
Go to the documentation of this file.
1 # coding: utf-8
2 
3 """
4  cloudFPGA Resource Manager API
5 
6  No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) # noqa: E501
7 
8  OpenAPI spec version: 0.8
9 
10  Generated by: https://github.com/swagger-api/swagger-codegen.git
11 """
12 
13 from __future__ import absolute_import
14 
15 import copy
16 import logging
17 import multiprocessing
18 import sys
19 import urllib3
20 
21 import six
22 from six.moves import http_client as httplib
23 
24 
26  def __init__(cls, name, bases, dct):
27  super(TypeWithDefault, cls).__init__(name, bases, dct)
28  cls._default_default = None
29 
30  def __call__(cls):
31  if cls._default_default is None:
32  cls._default_default = type.__call__(cls)
33  return copy.copy(cls._default_default)
34 
35  def set_default(cls, default):
36  cls._default_default = copy.copy(default)
37 
38 
39 class Configuration(six.with_metaclass(TypeWithDefault, object)):
40  """NOTE: This class is auto generated by the swagger code generator program.
41 
42  Ref: https://github.com/swagger-api/swagger-codegen
43  Do not edit the class manually.
44  """
45 
46  def __init__(self):
47  """Constructor"""
48  # Default Base url
49  self.hosthost = "/"
50  # Temp file folder for downloading files
51  self.temp_folder_pathtemp_folder_path = None
52 
53  # Authentication Settings
54  # dict to store API key(s)
55  self.api_keyapi_key = {}
56  # dict to store API prefix (e.g. Bearer)
57  self.api_key_prefixapi_key_prefix = {}
58  # function to refresh API key if expired
59  self.refresh_api_key_hookrefresh_api_key_hook = None
60  # Username for HTTP basic authentication
61  self.usernameusername = ""
62  # Password for HTTP basic authentication
63  self.passwordpassword = ""
64  # Logging Settings
65  self.loggerlogger = {}
66  self.loggerlogger["package_logger"] = logging.getLogger("swagger_client")
67  self.loggerlogger["urllib3_logger"] = logging.getLogger("urllib3")
68  # Log format
69  self.logger_formatlogger_formatlogger_formatlogger_format = '%(asctime)s %(levelname)s %(message)s'
70  # Log stream handler
71  self.logger_stream_handlerlogger_stream_handler = None
72  # Log file handler
73  self.logger_file_handlerlogger_file_handler = None
74  # Debug file location
75  self.logger_filelogger_filelogger_filelogger_file = None
76  # Debug switch
77  self.debugdebugdebugdebug = False
78 
79  # SSL/TLS verification
80  # Set this to false to skip verifying SSL certificate when calling API
81  # from https server.
82  self.verify_sslverify_ssl = True
83  # Set this to customize the certificate file to verify the peer.
84  self.ssl_ca_certssl_ca_cert = None
85  # client certificate file
86  self.cert_filecert_file = None
87  # client key file
88  self.key_filekey_file = None
89  # Set this to True/False to enable/disable SSL hostname verification.
90  self.assert_hostnameassert_hostname = None
91 
92  # urllib3 connection pool's maximum number of connections saved
93  # per pool. urllib3 uses 1 connection as default value, but this is
94  # not the best value when you are making a lot of possibly parallel
95  # requests to the same host, which is often the case here.
96  # cpu_count * 5 is used as default value to increase performance.
97  self.connection_pool_maxsizeconnection_pool_maxsize = multiprocessing.cpu_count() * 5
98 
99  # Proxy URL
100  self.proxyproxy = None
101  # Safe chars for path_param
102  self.safe_chars_for_path_paramsafe_chars_for_path_param = ''
103 
104  @property
105  def logger_file(self):
106  """The logger file.
107 
108  If the logger_file is None, then add stream handler and remove file
109  handler. Otherwise, add file handler and remove stream handler.
110 
111  :param value: The logger_file path.
112  :type: str
113  """
114  return self.__logger_file__logger_file
115 
116  @logger_file.setter
117  def logger_file(self, value):
118  """The logger file.
119 
120  If the logger_file is None, then add stream handler and remove file
121  handler. Otherwise, add file handler and remove stream handler.
122 
123  :param value: The logger_file path.
124  :type: str
125  """
126  self.__logger_file__logger_file = value
127  if self.__logger_file__logger_file:
128  # If set logging file,
129  # then add file handler and remove stream handler.
130  self.logger_file_handlerlogger_file_handler = logging.FileHandler(self.__logger_file__logger_file)
131  self.logger_file_handlerlogger_file_handler.setFormatter(self.logger_formatterlogger_formatter)
132  for _, logger in six.iteritems(self.loggerlogger):
133  logger.addHandler(self.logger_file_handlerlogger_file_handler)
134  if self.logger_stream_handlerlogger_stream_handler:
135  logger.removeHandler(self.logger_stream_handlerlogger_stream_handler)
136  else:
137  # If not set logging file,
138  # then add stream handler and remove file handler.
139  self.logger_stream_handlerlogger_stream_handler = logging.StreamHandler()
140  self.logger_stream_handlerlogger_stream_handler.setFormatter(self.logger_formatterlogger_formatter)
141  for _, logger in six.iteritems(self.loggerlogger):
142  logger.addHandler(self.logger_stream_handlerlogger_stream_handler)
143  if self.logger_file_handlerlogger_file_handler:
144  logger.removeHandler(self.logger_file_handlerlogger_file_handler)
145 
146  @property
147  def debug(self):
148  """Debug status
149 
150  :param value: The debug status, True or False.
151  :type: bool
152  """
153  return self.__debug__debug
154 
155  @debug.setter
156  def debug(self, value):
157  """Debug status
158 
159  :param value: The debug status, True or False.
160  :type: bool
161  """
162  self.__debug__debug = value
163  if self.__debug__debug:
164  # if debug status is True, turn on debug logging
165  for _, logger in six.iteritems(self.loggerlogger):
166  logger.setLevel(logging.DEBUG)
167  # turn on httplib debug
168  httplib.HTTPConnection.debuglevel = 1
169  else:
170  # if debug status is False, turn off debug logging,
171  # setting log level to default `logging.WARNING`
172  for _, logger in six.iteritems(self.loggerlogger):
173  logger.setLevel(logging.WARNING)
174  # turn off httplib debug
175  httplib.HTTPConnection.debuglevel = 0
176 
177  @property
178  def logger_format(self):
179  """The logger format.
180 
181  The logger_formatter will be updated when sets logger_format.
182 
183  :param value: The format string.
184  :type: str
185  """
186  return self.__logger_format__logger_format
187 
188  @logger_format.setter
189  def logger_format(self, value):
190  """The logger format.
191 
192  The logger_formatter will be updated when sets logger_format.
193 
194  :param value: The format string.
195  :type: str
196  """
197  self.__logger_format__logger_format = value
198  self.logger_formatterlogger_formatter = logging.Formatter(self.__logger_format__logger_format)
199 
200  def get_api_key_with_prefix(self, identifier):
201  """Gets API key (with prefix if set).
202 
203  :param identifier: The identifier of apiKey.
204  :return: The token for api key authentication.
205  """
206  if self.refresh_api_key_hookrefresh_api_key_hook:
207  self.refresh_api_key_hookrefresh_api_key_hook(self)
208 
209  key = self.api_keyapi_key.get(identifier)
210  if key:
211  prefix = self.api_key_prefixapi_key_prefix.get(identifier)
212  if prefix:
213  return "%s %s" % (prefix, key)
214  else:
215  return key
216 
218  """Gets HTTP basic authentication header (string).
219 
220  :return: The token for basic HTTP authentication.
221  """
222  return urllib3.util.make_headers(
223  basic_auth=self.usernameusername + ':' + self.passwordpassword
224  ).get('authorization')
225 
226  def auth_settings(self):
227  """Gets Auth Settings dict for api client.
228 
229  :return: The Auth Settings information dict.
230  """
231  return {
232  }
233 
234  def to_debug_report(self):
235  """Gets the essential information for debugging.
236 
237  :return: The report for debugging.
238  """
239  return "Python SDK Debug Report:\n"\
240  "OS: {env}\n"\
241  "Python Version: {pyversion}\n"\
242  "Version of the API: 0.8\n"\
243  "SDK Package Version: 1.0.0".\
244  format(env=sys.platform, pyversion=sys.version)