Exemplo n.º 1
0
def create_rule(connection, rule_info):
    """
    Create a new rule.

    rule_info = {
        'vcServer': '10.255.79.10',
        'customerName':'company23-A',
        'objectType':'VM',
        'valueType':'Unique ID',
        'value':'vm-10'
    }

    :param connection:
    :param rule_info:
    :return:
    """
    connection.command_path = 'rule'
    extra_headers = {
        connection.header_key: connection.token,
        'Content-Type': 'text/xml'
    }
    url = connection.build_url()
    rule_data = _build_rule_payload(rule_info)
    verify_ssl = connection.verify_ssl
    res = requests.post(url, headers=extra_headers,
                        data=rule_data,
                        verify=verify_ssl)
    if res.status_code == 201:
        return rules.parse_rule(res.content)
    raise RuleCreationException("Error creating rule: {0} => {0}".format(
        res.status_code, res.content
    ))
Exemplo n.º 2
0
def get_rule(connection, rule_id):
    """
    Get a specific rule based on its id.

    :param connection:
    :param rule_id:
    :return:
    """
    connection.command_path = "rule/{0}".format(rule_id)
    extra_headers = {connection.header_key: connection.token}
    url = connection.build_url()
    verify_ssl = connection.verify_ssl
    res = requests.get(url=url, headers=extra_headers, verify=verify_ssl)
    if res.status_code > 210:
        raise RuleNotFoundException(res.content)
    return rules.parse_rule(res.content)