def _init_clients(self): """Convenience method to initialize ClientsService client""" if hasattr(self, 'clients'): return self.clients = ApiClient(jsonapi_clients, self.username, self.password, self.debug) self._d(self.clients)
def _init_common(self): """Convenience method to initialize CommonService client""" if hasattr(self, 'common'): return self.common = ApiClient(jsonapi_common, self.username, self.password, self.debug) self._d(self.common)
def __init__(self, name, cached_data): """Creates a new object representing an *existing* deploy key :param name: The name of the deploy key you want to load :type name: str :param cached_data: Cached data to instantiate the master :type cached_data: dict :Example: >>> ppaas.DeployKey('thomas') <Deploy Key thomas> >>> ppaas.DeployKey('thomas').fingerprint u'52:35:1c:6c:12:57:5f:64:48:3b:ef:89:4c:c5:08:f9' >>> ppaas.DeployKey('Idontexist').fingerprint Traceback (most recent call last): File "<stdin>", line 1, in <module> File "ppaas/deploy_key.py", line 36, in __init__ self.cached_data, _ = self.client.get('/deploy-keys/%s' % (self.name)) File "ppaas/client.py", line 72, in get return self.call('GET', self.endpoint + url, params=params) File "ppaas/client.py", line 112, in call raise ResourceNotFoundError(result) ppaas.client.ResourceNotFoundError: {u'message': u'The requested resource could not be found.'} .. seealso:: get_deploy_keys(), create_deploy_key() """ self.client = ApiClient() self.name = name self.reload_data(cached_data)
def __init__(self, master, hostname, cached_data=None): """Creates a new object representing an *existing* agent certificate :param master: The Master the wanted certificate is attached to :type master: ppaas.Master :param hostname: The hostname of the agent :type hostname: str :param cached_data: Cached data to instantiate the master :type cached_data: dict :Example: >>> ppaas.Master.get_masters() [<Puppet Master 0e85b81f-5a29-4e2b-a46c-e024049acb07>] >>> master = _[0] >>> ppaas.Certificate(master, 'machine.maurice.fr') <Agent Certificate machine.maurice.fr@0e85b81f-5a29-4e2b-a46c-e024049acb07> .. note:: You will probably never call this directly and instead use the ppaas.Master.certificate() method instead .. seealso:: get_certificates(), ppaas.Master.certificate() """ self.client = ApiClient() self.hostname = hostname self.master = master self.reload_data(cached_data)
def get_certificates(master, client=None): """Returns all the agent certificates for a Master :param master: The master in question :param client: The ApiClient to use :type master: ppaas.Master :type client: ppaas.ApiClient :Example: >>> ppaas.Master.get_masters() [<Puppet Master 0e85b81f-5a29-4e2b-a46c-e024049acb07>] >>> master = _[0] >>> ppaas.Certificate.get_certificates(master) [<Agent Certificate machine.maurice.fr@0e85b81f-5a29-4e2b-a46c-e024049acb07>] .. note:: You will probably never use this method neither and use the one shipped with the Master class I guess. """ if not client: client = ApiClient() result, status = client.get('/masters/%s/certs' % master.uuid) certificates = [] for certificate in result['certs']: certificates.append(Certificate(master, certificate['hostname'])) return certificates
def create_master(name, source, deploy_key, vars={}, nb=1, type=None, hierarchy=[], hieras=[], client=None): """ Creates a Pupper master :param name: Name of the puppet master :type name: str :param source: Source git repository of the puppet master :type source: str :param deploy_key: Deploy key to link with your puppet master :type deploy_key: ppaas.DeployKey :param nb: Number of servers for the master :type nb: int :param type: Kind of server to use :type type: str :param hierarchy: Array of hierarchies :type hierarchy: list :param hieras: Array of hiera backend :type hieras: list :param client: A client object you want to pass, if empty a new one will be created :type client: ppaas.ApiClient :return: The newly created puppet master :rtype: Master :Example: >>> ppaas.Master.create_master("master1", "[email protected]:puppet/puppet.git", "github") <Puppet Master 0e85b81f-5a29-4e2b-a46c-e024049acb07> >>> master.name 'master1' """ payload = { "name": name, "source": source, "deploy_key": deploy_key, "nb": nb, "hierarchy": hierarchy, "hieras": hieras, "vars": vars } if type: payload["type"] = type if not client: client = ApiClient() result, _ = client.post("/masters", data=payload) return Master(result["id"], result)
def run(): try: client = ApiClient('YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET') result = client.get( 'v2/astrology/kundli/advanced', { 'ayanamsa': 1, 'coordinates': '23.1765,75.7885', 'datetime': '2020-10-19T12:31:14+00:00', }) print json.dumps(result, indent=4) except ValidationError as e: for msg in e.getValidationMessages(): print(msg['detail']) except AuthenticationError as e: print(e.message)
def __init__(self, merlin_url: str, use_google_oauth: bool = True): self._merlin_url = merlin_url config = Configuration() config.host = self._merlin_url + "/v1" self._api_client = ApiClient(config) if use_google_oauth: credentials, project = google.auth.default(scopes=OAUTH_SCOPES) autorized_http = AuthorizedHttp(credentials, urllib3.PoolManager()) self._api_client.rest_client.pool_manager = autorized_http self._project_api = ProjectApi(self._api_client) self._model_api = ModelsApi(self._api_client) self._version_api = VersionApi(self._api_client) self._endpoint_api = EndpointApi(self._api_client) self._env_api = EnvironmentApi(self._api_client)
def __init__(self, uuid): """Creates a new object representing an *existing* puppet master :param uuid: UUID of the master :type uuid: str :Example: >>> ppaas.Master('0e85b81f-5a29-4e2b-a46c-e024049acb07') <Puppet Master 0e85b81f-5a29-4e2b-a46c-e024049acb07> >>> master.name 'thomas' .. seealso:: get_masters() """ self.client = ApiClient() self.uuid = uuid self.cached_data, _ = self.client.get('/masters/%s' % self.uuid)
def create_deploy_key(name, client=None): """Creates a new deployment key with a given name. :param name: Name of the new key :type name: str :return: The newly created key :rtype: DeployKey :Example: >>> ppaas.DeployKey.create_deploy_key('fookey') <Deploy Key fookey> """ if not client: client = ApiClient() result, status = client.post('/deploy-keys', data={'name': name}) return DeployKey(name, result)
def run(): try: client = ApiClient('a995b0ff-2269-45bf-a96e-07233c2aa03c', 'iqxjWqVzDUObnVTMgVdUGKVPhdFhE6qCRIF6oG8u') result = client.get( 'v2/astrology/planet-position', { 'ayanamsa': 1, 'coordinates': '23.1765,75.7885', 'datetime': '1975-04-25T14:10:00+00:00', 'chart_type': 'lagna', 'chart_style': 'north-indian' }) # print json.dumps(result, indent=4) print(result) except ValidationError as e: for msg in e.getValidationMessages(): print(msg['detail']) except AuthenticationError as e: print(e.message)
def __init__(self, uuid, cached_data=None): """Creates a new object representing an *existing* puppet master :param uuid: UUID of the master :type uuid: str :param cached_data: Cached data to instantiate the master :type cached_data: dict :Example: >>> ppaas.Master('0e85b81f-5a29-4e2b-a46c-e024049acb07') <Puppet Master 0e85b81f-5a29-4e2b-a46c-e024049acb07> >>> master.name 'thomas' .. seealso:: get_masters() """ self.client = ApiClient() self.uuid = uuid self.reload_data(cached_data)
def get_deploy_keys(client=None): """Retrieves all your deployment keys. :param client: A client object you want to pass, if empty a new one will be created :type client: ApiClient :return: The list of your deployment keys :rtype: List of DeployKey objects :Example: >>> ppaas.DeployKey.get_deploy_keys() [<Deploy Key github>, <Deploy Key thomas>] """ if not client: client = ApiClient() result, status = client.get('/deploy-keys') keys = [] for key in result['deploy_keys']: keys.append(DeployKey(key['name'], key)) return keys
def get_masters(client=None): """Retrieves all your puppet masters :param client: A client object you want to pass, if empty a new one will be created :type client: ppaas.ApiClient :return: The list of your puppet masters :rtype: List of Master objects :Example: >>> ppaas.Master.get_deploy_keys() [<Puppet Master 0e85b81f-5a29-4e2b-a46c-e024049acb07>] """ if not client: client = ApiClient() result, status = client.get('/masters') masters = [] for master in result['masters']: masters.append(Master(master['id'])) return masters
def get_master(name, client=None): """Gets a master by name, because who the hell can remember uuids ? :param name: Name of the Puppet Master you want to retrieve :param client: A client object you want to pass, if empty a new one will be created :type name: str :type client: ppaas.ApiClient :return: A Master object, or None if no matching master was found :rtype: ppaas.Master, or None :Example: >>> ppaas.Master.get_master('thomas') <Puppet Master 0e85b81f-5a29-4e2b-a46c-e024049acb07> """ if not client: client = ApiClient() masters = Master.get_masters(client) for master in masters: if master.cached_data['name'] == name: return master return None
import os import sched import time from client import ApiClient from processing import resolve_all launch_hour = int(os.environ['LAUNCH_HOUR']) launch_minute = int(os.environ['LAUNCH_MINUTE']) days_frequency = int(os.environ['DAYS_FREQUENCY']) scheduler = sched.scheduler(time.time, time.sleep) host = os.environ['API_HOST'] username = os.environ['API_USERNAME'] password = os.environ['API_PASSWORD'] client = ApiClient(host, username, password) thread_count = int(os.environ['THREAD_COUNT']) retry_timeout = 5 def first_login(): while True: try: client.login() return except Exception as e: print(f"cant connect to the API: {str(e)}") print(f"retrying in {retry_timeout} seconds...") time.sleep(retry_timeout)
# -*- coding: UTF-8 -*- __author__ = 'mcxiaoke' """ 数据抓取流程: 1. 使用帐号密码XAuth登录豆瓣,保存AccessToken,如果已经有Token,直接使用,初始化API 2. 读取种子用户ID列表,逐个取User信息写入actions数据表(只执行一次) 3. 读取actions的数据库数据,按以下流程循环: 1. 检查action_following标志,读取followings列表,写入actions(包括ID和action_user),写入users 2. 检查action_followers标志,读取followers列表,写入actions(包括ID和action_user),写入users 4. 读取actions的数据库数据,按以下流程循环: 1. 检查action_user标志,读取user信息,写入actions,写入users """ import config from client import ApiClient if __name__ == "__main__": client = ApiClient(config.API_KEY_SHUO_ANDROID, config.API_SECRET_SHUO_ANDROID) if not client.token_code: username = raw_input("please input username:"******"please input password:") client.auth_with_password(username, password) client.save_token() print client.token_code # print client.me().body # print client.user(1376127).body
from configuration import * from client import ApiClient from common import Logger from traffic import TrafficPointDownloader # Configuración y dependencias configuration: Configuration = Configuration.load_from_file( 'configuration.development.json') #Cliente de la API api_client: ApiClient = ApiClient(configuration.api) #Logger logger: Logger = Logger() traffic: TrafficPointDownloader = TrafficPointDownloader()
def api_client(url): config = Configuration() config.host = url + "/v1" return ApiClient(config)