コード例 #1
0
ファイル: utils.py プロジェクト: Fiware/cloud.Cloto
def create_subscription(api_utils, server_id=None, headers=HEADERS, tenant_id=TENANT_ID, rule_name=None,
                        rule_condition=None, rule_action=None):

    """Method to subscribe a server to a specific rule not created.
    :param server_id: Server unique identifier
    :param headers: HTTP headers for the requests including authentication
    :param tenant_id: Tenant unique identifier
    :param rule_name: Name of the rule to be created
    :param rule_condition: Condition of the rule to be created
    :param rule_action: Action of the rule to be created
    :returns subscription_id: Subscription unique identifier
    """

    example_rule = {'action': {'actionName': 'notify-scale', 'operation': 'scaleUp'}, 'name': 'aSbKDLIHx', 'condition':
        {'mem': {'operand': 'greater equal', 'value': '98'},
         'net': {'operand': 'greater equal', 'value': '98'},
         'hdd': {'operand': 'greater equal', 'value': '98'},
         'cpu': {'operand': 'greater', 'value': '90'}}}
    rule_id = RestUtils.create_rule(api_utils, tenant_id=tenant_id, server_id=server_id, rule_name=rule_name,
                                    body=example_rule, headers=headers)
    req = api_utils.create_subscription(tenant_id=tenant_id, server_id=server_id,
                                        rule_id=rule_id.json()[RULE_ID], url=RULE_URL_DEFAULT, headers=headers)

    assert_equals(req.status_code, RESPONSE_OK_CODE)
    subscription_id = req.json()[SUBSCRIPTION_ID]
    return subscription_id
コード例 #2
0
def create_subscription(api_utils,
                        server_id=None,
                        headers=HEADERS,
                        tenant_id=TENANT_ID,
                        rule_name=None,
                        rule_condition=None,
                        rule_action=None):
    """Method to subscribe a server to a specific rule not created.
    :param server_id: Server unique identifier
    :param headers: HTTP headers for the requests including authentication
    :param tenant_id: Tenant unique identifier
    :param rule_name: Name of the rule to be created
    :param rule_condition: Condition of the rule to be created
    :param rule_action: Action of the rule to be created
    :returns subscription_id: Subscription unique identifier
    """
    rule_id = RestUtils.create_rule(api_utils, tenant_id, server_id, rule_name,
                                    rule_condition, rule_action, headers)

    req = api_utils.create_subscription(tenant_id=tenant_id,
                                        server_id=server_id,
                                        rule_id=rule_id,
                                        url=RULE_URL_DEFAULT,
                                        headers=headers)

    assert_true(req.ok, HTTP_CODE_NOT_OK.format(req.status_code))
    subscription_id = req.json()[SUBSCRIPTION_ID]
    return subscription_id
コード例 #3
0
ファイル: utils.py プロジェクト: cgc951/fiware-cloto
def create_subscription(api_utils,
                        server_id=None,
                        headers=HEADERS,
                        tenant_id=TENANT_ID,
                        rule_name=None,
                        rule_condition=None,
                        rule_action=None):
    """Method to subscribe a server to a specific rule not created.
    :param server_id: Server unique identifier
    :param headers: HTTP headers for the requests including authentication
    :param tenant_id: Tenant unique identifier
    :param rule_name: Name of the rule to be created
    :param rule_condition: Condition of the rule to be created
    :param rule_action: Action of the rule to be created
    :returns subscription_id: Subscription unique identifier
    """

    example_rule = {
        'action': {
            'actionName': 'notify-scale',
            'operation': 'scaleUp'
        },
        'name': 'aSbKDLIHx',
        'condition': {
            'mem': {
                'operand': 'greater equal',
                'value': '98'
            },
            'net': {
                'operand': 'greater equal',
                'value': '98'
            },
            'hdd': {
                'operand': 'greater equal',
                'value': '98'
            },
            'cpu': {
                'operand': 'greater',
                'value': '90'
            }
        }
    }
    rule_id = RestUtils.create_rule(api_utils,
                                    tenant_id=tenant_id,
                                    server_id=server_id,
                                    rule_name=rule_name,
                                    body=example_rule,
                                    headers=headers)
    req = api_utils.create_subscription(tenant_id=tenant_id,
                                        server_id=server_id,
                                        rule_id=rule_id.json()[RULE_ID],
                                        url=RULE_URL_DEFAULT,
                                        headers=headers)

    assert_equals(req.status_code, RESPONSE_OK_CODE)
    subscription_id = req.json()[SUBSCRIPTION_ID]
    return subscription_id