コード例 #1
0
ファイル: cep_utils.py プロジェクト: telefonicaid/iotqatools
    def __init__(self, instance,
                 protocol="http",
                 port="9090",
                 path='/m2m/vrules',
                 cep_version='',
                 verbosity='DEBUG',
                 default_headers={'Accept': 'application/json', 'content-type': 'application/json'}):
        """
        constructor with values by default
        :param protocol: protocol to be used (e.g. http:// or https://)
        :param port: port
        :param path: path
        :param verbosity: level for debugging purposes
        :param default_headers: default headers for CEP requests
        :param instance: cep endpoint
        :param cep_version: cep version
        """
        # initialize logger
        self.log = get_logger('cep_utils', verbosity)

        # Assign the values
        self.default_endpoint = protocol + '://' + instance + ':' + port
        self.default_headers = default_headers
        self.instance = instance
        self.protocol = protocol
        self.port = port
        self.path = path
        self.version = cep_version
コード例 #2
0
ファイル: cep_utils.py プロジェクト: telefonicaid/iotqatools
    def __init__(self,
                 instance,
                 protocol="http",
                 port="9090",
                 path='/m2m/vrules',
                 cep_version='',
                 verbosity='DEBUG',
                 default_headers={'Accept': 'application/json'},
                 verify=False,
                 check_json=True):
        """
        constructor with values by default
        :param protocol: protocol to be used (e.g. http:// or https://)
        :param port: port
        :param path: path
        :param verbosity: level for debugging purposes
        :param default_headers: default headers for CEP requests
        :param instance: cep endpoint
        :param cep_version: cep version
        """
        # initialize logger
        self.log = get_logger('cep_utils', verbosity)

        # Assign the values
        self.default_endpoint = protocol + '://' + instance + ':' + port
        self.default_headers = default_headers
        self.instance = instance
        self.protocol = protocol
        self.port = port
        self.path = path
        self.version = cep_version
        self.headers = default_headers
        self.verify = verify
        self.check_json = check_json
コード例 #3
0
ファイル: ckan_utils.py プロジェクト: enjoygeek/iotqatools
    def __init__(self, instance=DEFAULT_ENDPOINT,
                 apikey=DEFAULT_APIKEY,
                 path=DEFAULT_PATH,
                 port=DEFAULT_PORT,
                 url=DEFAULT_URL,
                 protocol=DEFAULT_PROTOCOL,
                 verbosity='DEBUG',
                 default_headers={"Accept": "application/json", 'content-type': 'application/json'}):
        """
        Method for initialization of CKAN. Basically you can set the endpoint and the apikey of the user you are going
        to use by initializing the class (e.g. ckan = CkanUtils(instance='http://81.45.57.227:8443',
        apikey='7b321ca7-2193-4adf-8039-d550428620fe')
        :param instance: endpoint of the ckan instance (e.g. 192.168.21.194)
        :param apikey: unique identifier of the ckan user
        :param path: ckan path
        :param port: ckan listen port
        :param url: url to include in the resources creation
        :param protocol: ckan protocol (e.g. http, https)
        :param verbosity: verbosity level ('CRITICAL','ERROR', 'WARNING', 'INFO', 'DEBUG')
        :param default_headers: default headers for every requests to be sent to ckan
        """
        # initialize logger
        self.log = get_logger('ckan_utils', verbosity)

        self.instance = instance
        self.apikey = apikey
        self.path = path
        self.protocol = protocol
        self.port = port
        self.url = url
        self.verbosity = verbosity
        self.default_headers = default_headers
コード例 #4
0
ファイル: ckan_utils.py プロジェクト: telefonicaid/iotqatools
    def __init__(self, instance=DEFAULT_ENDPOINT,
                 apikey=DEFAULT_APIKEY,
                 path=DEFAULT_PATH,
                 port=DEFAULT_PORT,
                 url=DEFAULT_URL,
                 protocol=DEFAULT_PROTOCOL,
                 verbosity='DEBUG',
                 default_headers={"Accept": "application/json", 'content-type': 'application/json'}):
        """
        Method for initialization of CKAN. Basically you can set the endpoint and the apikey of the user you are going
        to use by initializing the class (e.g. ckan = CkanUtils(instance='http://81.45.57.227:8443',
        apikey='7b321ca7-2193-4adf-8039-d550428620fe')
        :param instance: endpoint of the ckan instance (e.g. 192.168.21.194)
        :param apikey: unique identifier of the ckan user
        :param path: ckan path
        :param port: ckan listen port
        :param url: url to include in the resources creation
        :param protocol: ckan protocol (e.g. http, https)
        :param verbosity: verbosity level ('CRITICAL','ERROR', 'WARNING', 'INFO', 'DEBUG', 'NOTSET')
        :param default_headers: default headers for every requests to be sent to ckan
        """
        # initialize logger
        self.log = get_logger('ckan_utils', verbosity)

        self.instance = instance
        self.apikey = apikey
        self.path = path
        self.protocol = protocol
        self.port = port
        self.url = url
        self.verbosity = verbosity
        self.default_headers = default_headers
コード例 #5
0
    def log_requestAndResponse(url='',
                               headers={},
                               params={},
                               data='',
                               comp='',
                               response={},
                               method=''):
        """
        Print the result of a request and the response data provided in a standard view
        :param url: Endpoint where the request was sent
        :param headers: Headers sent to the component (if any)
        :param params: Params sent to the component (if any)
        :param data: Data sent to the component (if any)
        :param comp: IoT component under test (optional)
        :param response: response of a request (optional)
        :param method: http method, it can be POST, GET, PUT, DELETE (optional)
        :return: Nan
        """
        log = get_logger('iot_tools')

        log_msg = '>>>>>>>>>>>>>\t Data sent:     \t>>>>>>>>>>>>> \n'
        if comp:
            log_msg += "\t> Comp: {} \n".format(comp)
        if method:
            log_msg += "\t> Method: {} \n".format(method)
        if url:
            log_msg += "\t> Url: {} \n".format(url)
        if headers:
            log_msg += '\t> Headers: {}\n'.format(str(dict(headers)))
            # log_msg += "\t> Headers: {} \n".format(pprint.pformat(headers, width=20))
        if params:
            log_msg += "\t> Params: {} \n".format(
                pprint.pformat(params, width=20))
        if data is not '':
            log_msg += "\t> Payload sent: {}\n".format(
                pprint.pformat(data, width=20))
        else:
            log_msg += "\t> SENT REQUEST DATA SEEMS TO BE EMPTY \n"
        log.debug(log_msg)

        if isinstance(response, object) and hasattr(response, "status_code"):
            log_msg = '<<<<<<<<<<<<<<\t Data responded:\t<<<<<<<<<<<<<<\n'
            if isinstance(response, object) and hasattr(
                    response, "status_code"):
                log_msg += '\t< Response code: {}\n'.format(
                    str(response.status_code))
            log_msg += '\t< Headers: {}\n'.format(str(dict(response.headers)))
            try:
                if response.content:
                    log_msg += '\t< Payload received: {}\n'.format(
                        response.content)
                else:
                    log_msg += '\t< Empty Payload \n'
            except ValueError:
                log_msg += '\t< Payload received:\n %s' % response.content

        # Log responded data
        log.debug(log_msg)
コード例 #6
0
ファイル: iot_tools.py プロジェクト: telefonicaid/iotqatools
    def log_requestAndResponse(url='', headers={}, params={}, data='', comp='', response={}, method=''):
        """
        Print the result of a request and the response data provided in a standard view
        :param url: Endpoint where the request was sent
        :param headers: Headers sent to the component (if any)
        :param params: Params sent to the component (if any)
        :param data: Data sent to the component (if any)
        :param comp: IoT component under test (optional)
        :param response: response of a request (optional)
        :param method: http method, it can be POST, GET, PUT, DELETE (optional)
        :return: Nan
        """
        log = get_logger('iot_tools')

        log_msg = '>>>>>>>>>>>>>\t Data sent:     \t>>>>>>>>>>>>> \n'
        if comp:
            log_msg += "\t> Comp: {} \n".format(comp)
        if method:
            log_msg += "\t> Method: {} \n".format(method)
        if url:
            log_msg += "\t> Url: {} \n".format(url)
        if headers:
            log_msg += '\t> Headers: {}\n'.format(str(dict(headers)))
            # log_msg += "\t> Headers: {} \n".format(pprint.pformat(headers, width=20))
        if params:
            log_msg += "\t> Params: {} \n".format(pprint.pformat(params, width=20))
        if data is not '':
            log_msg += "\t> Payload sent: {}\n".format(pprint.pformat(data, width=20))
        else:
            log_msg += "\t> SENT REQUEST DATA SEEMS TO BE EMPTY \n"
        log.debug(log_msg)

        if isinstance(response, object) and hasattr(response, "status_code"):
            log_msg = '<<<<<<<<<<<<<<\t Data responded:\t<<<<<<<<<<<<<<\n'
            if isinstance(response, object) and hasattr(response, "status_code"):
                log_msg += '\t< Response code: {}\n'.format(str(response.status_code))
            log_msg += '\t< Headers: {}\n'.format(str(dict(response.headers)))
            try:
                if response.content:
                    log_msg += '\t< Payload received: {}\n'.format(response.content)
                else:
                    log_msg += '\t< Empty Payload \n'
            except ValueError:
                log_msg += '\t< Payload received:\n %s' % response.content

        # Log responded data
        log.debug(log_msg)
コード例 #7
0
ファイル: sth_utils.py プロジェクト: telefonicaid/iotqatools
    def __init__(self,
                 instance,
                 service=None,
                 subservice=None,
                 protocol="http",
                 port="8666",
                 path_raw_data="/STH/v2/entities",
                 path_version="/version",
                 log_instance=None,
                 log_verbosity='DEBUG',
                 default_headers={"Accept": "application/json"},
                 check_json=True,
                 verify=False,
                 path_notify="/notify"):
        """
        STH Utils constructor
        :param instance:
        :param service:
        :param subservice:
        :param protocol:
        :param port:
        :param path_raw_data:
        :param path_version:
        :param log_instance:
        :param log_verbosity:
        :param default_headers:
        :param check_json:
        :param verify:        
        :param path_notify:
        """
        # initialize logger
        if log_instance is not None:
            self.log = log_instance
        else:
            self.log = get_logger('SthUtils', log_verbosity)

        # Assign the values
        self.default_endpoint = protocol + '://' + instance + ':' + port
        self.headers = self.__set_headers(default_headers, service, subservice)
        self.path_raw_data = self.default_endpoint + path_raw_data
        self.path_version = path_version
        self.check_json = check_json
        self.verify = verify
        self.path_notify = path_notify
コード例 #8
0
ファイル: sth_utils.py プロジェクト: telefonicaid/iotqatools
    def __init__(
        self,
        instance,
        service=None,
        subservice=None,
        protocol="http",
        port="8666",
        path_raw_data="/STH/v1/contextEntities",
        path_version="/version",
        log_instance=None,
        log_verbosity="DEBUG",
        default_headers={"Accept": "application/json", "content-type": "application/json"},
        check_json=True,
        path_notify="/notify",
    ):
        """
        STH Utils constructor
        :param instance:
        :param service:
        :param subservice:
        :param protocol:
        :param port:
        :param path_raw_data:
        :param path_version:
        :param log_instance:
        :param log_verbosity:
        :param default_headers:
        :param check_json:
        :param path_notify:
        """
        # initialize logger
        if log_instance is not None:
            self.log = log_instance
        else:
            self.log = get_logger("SthUtils", log_verbosity)

        # Assign the values
        self.default_endpoint = protocol + "://" + instance + ":" + port
        self.headers = self.__set_headers(default_headers, service, subservice)
        self.path_raw_data = self.default_endpoint + path_raw_data
        self.path_version = path_version
        self.check_json = check_json
        self.path_notify = path_notify
コード例 #9
0
ファイル: pep_utils.py プロジェクト: telefonicaid/iotqatools
class Pep(object):
    """
    Class to manage the Pep
    """

    log = get_logger('Pep')

    def __init__(self, ip, port='1026', protocol='http'):
        self.url = '%s://%s:%s' % (protocol, ip, port)
        self.port = port
        self.protocol = protocol
        self.ip = ip

    def request_cb_operation(self, username, password, service, subservice,
                             cb_method, cb_method_kwargs):
        self.log.info('Getting token')
        token = KeystoneUtils.get_token(username,
                                        password,
                                        service,
                                        ip=self.ip).headers
        self.log.debug('The token is: %s' % token)
        self.log.info('Creating the headers')

        headers = {
            "Accept": "application/json",
            'content-type': 'application/json',
            'Fiware-Servicepath': '/' + str(subservice),
            'X-Auth-Token': token['x-subject-token']
        }
        self.log.debug('The headers are: %s' % headers)
        self.log.info('Executing the method %s of \'cbUtils\'' % cb_method)
        self.log.debug('The info of the \'cbUtils\' arguments are: %s' %
                       cb_method_kwargs)
        cb = CBUtils(self.ip,
                     port=self.port,
                     default_headers=headers,
                     verbosity=2)
        cb_func = getattr(cb, cb_method)
        return cb_func(**cb_method_kwargs)
コード例 #10
0
    def log_fullRequest(comp='', response='', params=dict()):
        # initialize logger
        log = get_logger('iot_tools')

        # Introduce info in log text
        log_msg = '>>>>>>>>>>>>>\t Data sent:     \t>>>>>>>>>>>>> \n'
        if 'comp' is not '':
            log_msg += '\t> Comp: %s\n' % comp
        if 'url' in params:
            log_msg += '\t> Url: %s\n' % params['url']
        if 'method' in params:
            log_msg += '\t> Method: %s\n' % params['method']
        if 'headers' in params:
            log_msg += '\t> Headers: {}\n'.format(str(params['headers']))
        if 'data' in params:
            log_msg += '\t> Payload sent: {}\n'.format(
                pprint.pformat(params['data'], width=20))
        if 'params' in params:
            log_msg += '\t> Params sent: {}\n'.format(str(params['params']))
        if 'verify' in params:
            log_msg += '\t> Verify: %s\n' % params['verify']

        # Log sent data
        log.debug(log_msg)

        log_msg = '<<<<<<<<<<<<<<\t Data responded:\t<<<<<<<<<<<<<<\n'
        log_msg += '\t< Response code: {}\n'.format(str(response.status_code))
        log_msg += '\t< Headers: {}\n'.format(str(dict(response.headers)))
        try:
            log_msg += '\t< Payload received:\n {}'.format(response.content)
        except ValueError:
            log_msg += '\t< Payload received:\n %s' % response.content.text

        # Log responded data
        log.debug(log_msg)

        return 0
コード例 #11
0
ファイル: iot_tools.py プロジェクト: telefonicaid/iotqatools
    def log_fullRequest(comp='', response='', params=dict()):
        # initialize logger
        log = get_logger('iot_tools')

        # Introduce info in log text
        log_msg = '>>>>>>>>>>>>>\t Data sent:     \t>>>>>>>>>>>>> \n'
        if 'comp' is not '':
            log_msg += '\t> Comp: %s\n' % comp
        if 'url' in params:
            log_msg += '\t> Url: %s\n' % params['url']
        if 'method' in params:
            log_msg += '\t> Method: %s\n' % params['method']
        if 'headers' in params:
            log_msg += '\t> Headers: {}\n'.format(str(params['headers']))
        if 'data' in params:
            log_msg += '\t> Payload sent: {}\n'.format(pprint.pformat(params['data'], width=20))
        if 'params' in params:
            log_msg += '\t> Params sent: {}\n'.format(str(params['params']))
        if 'verify' in params:
            log_msg += '\t> Verify: %s\n' % params['verify']

        # Log sent data
        log.debug(log_msg)

        log_msg = '<<<<<<<<<<<<<<\t Data responded:\t<<<<<<<<<<<<<<\n'
        log_msg += '\t< Response code: {}\n'.format(str(response.status_code))
        log_msg += '\t< Headers: {}\n'.format(str(dict(response.headers)))
        try:
            log_msg += '\t< Payload received:\n {}'.format(response.content)
        except ValueError:
            log_msg += '\t< Payload received:\n %s' % response.content.text

        # Log responded data
        log.debug(log_msg)

        return 0
コード例 #12
0
ファイル: cep_utils.py プロジェクト: telefonicaid/iotqatools
For those usages not covered by the GNU Affero General Public License
please contact with::[[email protected]]
"""

import yaml
import pystache
import requests
import json

from iotqatools.iot_logger import get_logger
from iotqatools.templates.cep_templates import *
from iotqatools.helpers_utils import *

from iotqatools.iot_logger import get_logger

__logger__ = get_logger("cep_steps", 'DEBUG', True)

class CEP:
    """
    Manage Perseo requests / responses.
    """

    def __init__(self, instance,
                 protocol="http",
                 port="9090",
                 path='/m2m/vrules',
                 cep_version='',
                 verbosity='DEBUG',
                 default_headers={'Accept': 'application/json', 'content-type': 'application/json'}):
        """
        constructor with values by default
コード例 #13
0
 def remember(place, key, value):
     """The 'selection' parameters management """
     log = get_logger('iot_tools')
     place[key] = value
     log.debug("#>> {0} AS {1} in {2}".format(value, key, place))
コード例 #14
0
ファイル: ks_utils.py プロジェクト: telefonicaid/iotqatools
You should have received a copy of the GNU Affero General Public
License along with iotqatools.
If not, seehttp://www.gnu.org/licenses/.

For those usages not covered by the GNU Affero General Public License
please contact with::[[email protected]]
"""

import json
import re
import requests
from iotqatools.iot_tools import PqaTools

from iotqatools.iot_logger import get_logger

log = get_logger('keystone', 'ERROR')

URL_BASE = '/v3'
URL_BASE_SCIM = '/v3/OS-SCIM'

ENDPOINTS = {
    'tokens': URL_BASE + '/auth/tokens',
    'domains': URL_BASE + '/domains',
    'roles': URL_BASE + '/roles',
    'roles_assignments': URL_BASE + '/role_assignments',
    'users': URL_BASE + '/users',
    'projects': URL_BASE + '/projects',
    'users_scim': URL_BASE_SCIM + '/Users',
    'roles_scim': URL_BASE_SCIM + '/Roles',
    'set_roles': URL_BASE + '/domains/${ID_DOM1}/users/${ID_ADM1}/roles/${ROLE_ID}',
    'set_roles_project': URL_BASE + '/projects/${ID_PROJECT}/users/${ID_ADM1}/roles/${ROLE_ID}'
コード例 #15
0
ファイル: ac_utils.py プロジェクト: telefonicaid/iotqatools
class AC(object):
    """
    Class to manage AccessControl
    Estructura de las "entities"
    fiware:<nombreDelComponente>:<Servicio>:<Subservicio>:<cualquier número de subdivisiones separadas por ':'>
    """
    BASE_PATH_MANAGE = '/pap/v1/'
    BASE_PATH_EVALUATE = '/pdp/v3/'

    log = get_logger('AccessControl', 'ERROR')

    def __init__(self, host, port='8080', protocol='http'):
        self.url = '%s://%s:%s' % (protocol, host, port)

    def send(self, method, url, headers=None, payload=None, query=None):
        """
        Funtion to send requests printing data to send by log
        :param method: get, post, delete, patch, update...
        :param url:
        :param headers:
        :param payload:
        :param query:
        :return: response object
        """
        self.log.debug('Request: -->')
        self.log.debug('Method: %s' % method)
        self.log.debug('Url: %s' % url)
        self.log.debug('headers: %s' % headers)
        self.log.debug('query: %s' % query)
        self.log.debug('payload: %s' % payload)
        self.log.debug('--------------')
        request_parms = {}
        if headers is not None:
            request_parms.update({'headers': headers})
        if payload is not None:
            request_parms.update({'data': payload})
        if query is not None:
            request_parms.update({'params': query})
        response = requests.request(method, url, **request_parms)
        PqaTools.log_fullRequest(comp='ORC',
                                 response=response,
                                 params=request_parms)

        return response

    def create_policy(self, tenant, role, policy_name, entity, action):
        """
        Create a new policy in AC
        :param tenant:
        :param role:
        :param policy_name:
        :param entity:
        :param action:
        :return:
        """
        xml = pystache.render(template_ac_create_policy, {
            'policy': policy_name,
            'entity': entity,
            'action': action
        })
        headers = {
            'Content-type': 'application/xml',
            'Accept': 'application/xml',
            'Fiware-Service': str(tenant)
        }
        url_to_send = self.url + self.BASE_PATH_MANAGE + 'subject/%s' % role
        response = self.send('post', url_to_send, headers=headers, payload=xml)
        return response

    def get_policy(self, tenant, role, policy_name):
        """
        Get a specific policy
        :param tenant:
        :param role:
        :param policy_name:
        :return:
        """
        headers = {
            'Content-type': 'application/xml',
            'Accept': 'application/xml',
            'Fiware-Service': str(tenant)
        }
        url_to_send = self.url + self.BASE_PATH_MANAGE + 'subject/%s/policy/%s' % (
            role, policy_name)
        response = self.send('get', url_to_send, headers=headers)
        return response

    def get_subject_policy(self, tenant, role):
        """
        Get all policies of a subject (Rol)
        :param tenant:
        :param role:
        :return:
        """
        headers = {
            'Content-type': 'application/xml',
            'Accept': 'application/xml',
            'Fiware-Service': str(tenant)
        }
        url_to_send = self.url + self.BASE_PATH_MANAGE + 'subject/%s' % role
        response = self.send('get', url_to_send, headers=headers)
        return response

    def delete_policy(self, tenant, role, policy):
        """
        Delete a specific policy
        :param tenant:
        :param role:
        :param policy:
        :return:
        """
        headers = {
            'Content-type': 'application/xml',
            'Accept': 'application/xml',
            'Fiware-Service': str(tenant)
        }
        url_to_send = self.url + self.BASE_PATH_MANAGE + 'subject/%s/policy/%s' % (
            role, policy)
        response = self.send('delete', url_to_send, headers=headers)
        return response

    def delete_subject_policies(self, tenant, role):
        """
        Delete all policies of a subject (Rol)
        :param tenant:
        :param role:
        :return:
        """
        headers = {
            'Content-type': 'application/xml',
            'Accept': 'application/xml',
            'Fiware-Service': str(tenant)
        }
        url_to_send = self.url + self.BASE_PATH_MANAGE + 'subject/%s' % role
        response = self.send('delete', url_to_send, headers=headers)
        return response

    def delete_tenant_policies(self, tenant):
        """
        Delete all policies of a tenent
        :param tenant:
        :return:
        """
        headers = {
            'Content-type': 'application/xml',
            'Accept': 'application/xml',
            'Fiware-Service': str(tenant)
        }
        url_to_send = self.url + self.BASE_PATH_MANAGE
        response = self.send('delete', url_to_send, headers=headers)
        return response

    def evaluate(self, tenant, role, entity, action):
        """
        Evaluate a policy
        :param tenant:
        :param role:
        :param entity:
        :param action:
        :return:
        """
        xml = pystache.render(template_ac_evaluate, {
            'role': role,
            'entity': entity,
            'action': action
        })
        headers = {
            'Content-type': 'application/xml',
            'Accept': 'application/xml',
            'Fiware-Service': str(tenant)
        }
        url_to_send = self.url + self.BASE_PATH_EVALUATE
        response = self.send('post', url_to_send, headers=headers, payload=xml)
        return response
コード例 #16
0
ファイル: iot_tools.py プロジェクト: telefonicaid/iotqatools
 def remember(place, key, value):
     """The 'selection' parameters management """
     log = get_logger('iot_tools')
     place[key] = value
     log.debug("#>> {0} AS {1} in {2}".format(value, key, place))
コード例 #17
0
ファイル: cep_utils.py プロジェクト: telefonicaid/iotqatools
For those usages not covered by the GNU Affero General Public License
please contact with::[[email protected]]
"""

import yaml
import pystache
import requests

from iotqatools.templates.cep_templates import *
from iotqatools.helpers_utils import *
from iotqatools.iot_logger import get_logger
from iotqatools.iot_tools import PqaTools
from requests.exceptions import RequestException

__logger__ = get_logger("cep_steps", 'DEBUG', True)


class CEP:
    """
    Manage Perseo requests / responses.
    """
    def __init__(self,
                 instance,
                 protocol="http",
                 port="9090",
                 path='/m2m/vrules',
                 cep_version='',
                 verbosity='DEBUG',
                 default_headers={'Accept': 'application/json'},
                 verify=False,
コード例 #18
0
    def __init__(self, instance,
                 protocol="http",
                 port="1026",
                 path_list_entities="/v2/entities",
                 path_create_entity="/v2/entities",
                 path_retrieve_entity_by_id="/v2/entities/entityId",
                 path_retrieve_entity_attributes="/v2/entities/entityId/attrs",
                 path_update_or_append_entity_attributes="/v2/entities/entityId/attrs",
                 path_update_existing_entity_attributes="/v2/entities/entityId/attrs",
                 path_replace_all_entity_attributes="/v2/entities/entityId/attrs",
                 path_remove_entity="/v2/entities",
                 path_get_attribute_data="/v2/entities/entityId/attrs/attrName",
                 path_update_attribute_data="/v2/entities/entityId/attrs/attrName",
                 path_remove_a_single_attribute="/v2/entities/entityId/attrs/attrName",
                 path_get_attribute_value="/v2/entities/entityId/attrs/attrName/value",
                 path_attribute_value_update="/v2/entities/entityId/attrs/attrName/value",
                 path_retrieve_entity_types="/v2/types",
                 path_retrieve_emtity_type="/v2/types/entityType",
                 path_retrieve_subscriptions="/v2/subscriptions",
                 path_retrieve_subscription_by_id="/v2/subscriptions/subscriptionId",
                 path_update_subscription="/v2/subscriptions/subscriptionId",
                 path_delete_subscription="/v2/subscriptions/subscriptionId",
                 path_statistics="/statistics",
                 path_version="/version",
                 log_instance=None,
                 log_verbosity='DEBUG',
                 default_headers={'Accept': 'application/json'},
                 check_json=True):
        """
        CB Utils constructor
        :param instance:
        :param protocol:
        :param port:
        :param path_list_entities:
        :param path_create_entity:
        :param path_retrieve_entity_by_id:
        :param path_retrieve_entity_attributes:
        :param path_update_or_append_entity_attributes:
        :param path_update_existing_entity_attributes:
        :param path_replace_all_entity_attributes:
        :param path_remove_entity:
        :param path_get_attribute_data:
        :param path_update_attribute_data:
        :param path_remove_a_single_attribute:
        :param path_get_attribute_value:
        :param path_attribute_value_update:
        :param path_retrieve_entity_types:
        :param path_retrieve_emtity_type:
        :param path_retrieve_subscriptions:
        :param path_retrieve_subscription_by_id:
        :param path_update_subscription:
        :param path_delete_subscription:
        :param path_statistics:
        :param path_version:
        :param log_instance:
        :param log_verbosity:
        :param default_headers:
        :param check_json:
        """
        # initialize logger
        if log_instance is not None:
            self.log = log_instance
        else:
            self.log = get_logger('CbNgsi10Utilsv2', log_verbosity)

        # Assign the values
        self.default_endpoint = "{}://{}:{}".format(protocol, instance, port)
        self.headers = default_headers
        self.path_list_entities = "{}{}".format(self.default_endpoint, path_list_entities)
        self.path_get_attribute_data = "{}{}".format(self.default_endpoint, path_update_attribute_data)
        self.path_statistics = path_statistics
        self.path_create_entity = "{}{}".format(self.default_endpoint, path_create_entity)
        self.path_context_subscriptions = "{}{}".format(self.default_endpoint, path_retrieve_subscriptions)
        self.path_context_subscriptions_by_id = "{}{}".format(self.default_endpoint, path_retrieve_subscription_by_id)
        self.path_version = path_version
        self.check_json = check_json
コード例 #19
0
    def __init__(
            self,
            instance,
            protocol="http",
            port="1026",
            path_list_entities="/v2/entities",
            path_create_entity="/v2/entities",
            path_retrieve_entity_by_id="/v2/entities/entityId",
            path_retrieve_entity_attributes="/v2/entities/entityId/attrs",
            path_update_or_append_entity_attributes="/v2/entities/entityId/attrs",
            path_update_existing_entity_attributes="/v2/entities/entityId/attrs",
            path_replace_all_entity_attributes="/v2/entities/entityId/attrs",
            path_remove_entity="/v2/entities",
            path_get_attribute_data="/v2/entities/entityId/attrs/attrName",
            path_update_attribute_data="/v2/entities/entityId/attrs/attrName",
            path_remove_a_single_attribute="/v2/entities/entityId/attrs/attrName",
            path_get_attribute_value="/v2/entities/entityId/attrs/attrName/value",
            path_attribute_value_update="/v2/entities/entityId/attrs/attrName/value",
            path_retrieve_entity_types="/v2/types",
            path_retrieve_emtity_type="/v2/types/entityType",
            path_retrieve_subscriptions="/v2/subscriptions",
            path_retrieve_subscription_by_id="/v2/subscriptions/subscriptionId",
            path_update_subscription="/v2/subscriptions/subscriptionId",
            path_delete_subscription="/v2/subscriptions/subscriptionId",
            path_statistics="/statistics",
            path_version="/version",
            log_instance=None,
            log_verbosity='DEBUG',
            default_headers={'Accept': 'application/json'},
            verify=False,
            check_json=True):
        """
        CB Utils constructor
        :param instance:
        :param protocol:
        :param port:
        :param path_list_entities:
        :param path_create_entity:
        :param path_retrieve_entity_by_id:
        :param path_retrieve_entity_attributes:
        :param path_update_or_append_entity_attributes:
        :param path_update_existing_entity_attributes:
        :param path_replace_all_entity_attributes:
        :param path_remove_entity:
        :param path_get_attribute_data:
        :param path_update_attribute_data:
        :param path_remove_a_single_attribute:
        :param path_get_attribute_value:
        :param path_attribute_value_update:
        :param path_retrieve_entity_types:
        :param path_retrieve_emtity_type:
        :param path_retrieve_subscriptions:
        :param path_retrieve_subscription_by_id:
        :param path_update_subscription:
        :param path_delete_subscription:
        :param path_statistics:
        :param path_version:
        :param log_instance:
        :param log_verbosity:
        :param default_headers:
        :param verify: ssl check
        :param check_json:
        """
        # initialize logger
        if log_instance is not None:
            self.log = log_instance
        else:
            self.log = get_logger('CbNgsi10Utilsv2', log_verbosity)

        # Assign the values
        self.default_endpoint = "{}://{}:{}".format(protocol, instance, port)
        self.headers = default_headers
        self.path_list_entities = "{}{}".format(self.default_endpoint,
                                                path_list_entities)
        self.path_get_attribute_data = "{}{}".format(
            self.default_endpoint, path_update_attribute_data)
        self.path_statistics = path_statistics
        self.path_create_entity = "{}{}".format(self.default_endpoint,
                                                path_create_entity)
        self.path_context_subscriptions = "{}{}".format(
            self.default_endpoint, path_retrieve_subscriptions)
        self.path_context_subscriptions_by_id = "{}{}".format(
            self.default_endpoint, path_retrieve_subscription_by_id)
        self.path_version = path_version
        self.verify = verify
        self.check_json = check_json