Пример #1
0
def main():
    fields = dict(node=dict(required=True),
                  user=dict(required=True),
                  password=dict(required=True),
                  name=dict(required=True, type="str"),
                  instance_id=dict(required=True, type="str"),
                  skip_direction=dict(required=True,
                                      type="str",
                                      choices=['in->out', 'out->in']))

    module = AnsibleModule(argument_spec=fields, supports_check_mode=True)

    node = module.params['node']
    user = module.params['user']
    password = module.params['password']
    name = module.params['name']
    instance_id = module.params['instance_id']
    skip_direction = module.params['skip_direction']
    result = {}
    with BmfRest(host=node, user=user, password=password, debug=True) as dev:
        path = dev.bigchain_path() + 'service[name="%s"]/instance[id=%s]' % (
            name, instance_id)
        data = {}
        if skip_direction == "in->out":
            data["in-skip"] = 'true'
        else:
            data["out-skip"] = 'true'
        service_skip = dev.patch(path, data=data)['content']
        result = dict(service_skip=service_skip)

    module.exit_json(**result)
Пример #2
0
def main():
    fields = dict(node             = dict(required=True),
                  user         = dict(required=True),
                  password     = dict(required=True),
                  chain            = dict(required=True, type="str"),
                  service          = dict(required=True, type="str"),
                  service_instance = dict(required=True, type="str"),
                  sequence         = dict(required=True, type="str"))
    
    module = AnsibleModule(
        argument_spec = fields,
        supports_check_mode = True)

    node = module.params['node']
    user = module.params['user']
    password = module.params['password']
    chain = module.params['chain']
    service = module.params['service']
    service_instance = module.params['service_instance']
    sequence = module.params['sequence']
    result = {}
    with BmfRest(host=node, user=user, password=password, debug=True) as dev:
        path = dev.bigchain_path()+'chain[name="%s"]/service[sequence=%s]' % (chain, sequence)
        data = {"service-name": service, "instance": service_instance, "sequence": sequence}
        insert_service_instance = dev.put(path, data=data)['content']

        result = dict(insert_service_instance=insert_service_instance)
    module.exit_json(**result)
Пример #3
0
def main():
    fields = dict(node=dict(required=True),
                  user=dict(required=True),
                  password=dict(required=True),
                  name=dict(required=True, type="str"),
                  switch=dict(required=True, type="str"),
                  endpoint1=dict(required=True, type="str"),
                  endpoint2=dict(required=True, type="str"))

    module = AnsibleModule(argument_spec=fields, supports_check_mode=True)

    node = module.params['node']
    user = module.params['user']
    password = module.params['password']

    name = module.params['name']
    switch = module.params['switch']
    endpoint1 = module.params['endpoint1']
    endpoint2 = module.params['endpoint2']
    result = {}
    with BmfRest(host=node, user=user, password=password, debug=True) as dev:
        path = dev.bigchain_path() + 'chain[name="%s"]' % name
        data = {"name": name}
        chain = dev.put(path, data=data)['content']

        path = dev.bigchain_path() + 'chain[name="%s"]/endpoint-pair' % name
        data = {
            "switch": switch,
            "endpoint1": endpoint1,
            "endpoint2": endpoint2
        }
        endpoints = dev.patch(path, data=data)['content']

        result = dict(chain=chain, endpoints=endpoints)
    module.exit_json(**result)
def main():
    fields = dict(node        = dict(required=True),
                  user         = dict(required=True),
                  password     = dict(required=True),
                  name        = dict(required=True, type="str"),
                  action      = dict(required=True, type="str", choices=['do-service', 'bypass-service', 'drop']))
    
    module = AnsibleModule(
        argument_spec = fields,
        supports_check_mode = True)

    node = module.params['node']
    user = module.params['user']
    password = module.params['password']
    name = module.params['name']
    action = module.params['action']
    result = {}
    with BmfRest(host=node, user=user, password=password, debug=True) as dev:
        path = dev.bigchain_path()+'service[name="%s"]' % name
        data = {"name": name, "type": "custom"}
        service = dev.put(path, data=data)['content']

        path = dev.bigchain_path()+'service[name="%s"]/policy' % name
        data = {"action": action}
        service_bypass_action = dev.patch(path, data=data)['content']

        result = dict(service=service, service_bypass_action=service_bypass_action)
        
    module.exit_json(**result)
def main():
    fields = dict(node=dict(required=True),
                  name=dict(required=True, type="str"),
                  ip_proto=dict(required=True, type="int"),
                  src_ip=dict(required=True, type="str"),
                  src_ip_mask=dict(required=True, type="str"),
                  dst_ip=dict(required=True, type="str"),
                  dst_ip_mask=dict(required=True, type="str"),
                  src_port=dict(required=True, type="int"),
                  dst_port=dict(required=True, type="int"))

    module = AnsibleModule(argument_spec=fields, supports_check_mode=True)

    node = module.params['node']
    name = module.params['name']
    ip_proto = module.params['ip_proto']
    src_ip = module.params['src_ip']
    src_ip_mask = module.params['src_ip_mask']
    dst_ip = module.params['dst_ip']
    dst_ip_mask = module.params['dst_ip_mask']
    src_tp_port = module.params['src_port']
    dst_tp_port = module.params['dst_port']

    result = dict(hello="hello")
    with BmfRest(host=node, user='******', password='******', debug=True) as dev:
        rule = {
            "ether-type": 2048,
            "ip-proto": ip_proto,
            "src-ip": src_ip,
            "src-ip-mask": src_ip_mask,
            "dst-ip": dst_ip,
            "dst-ip-mask": dst_ip_mask,
            "src-tp-port": src_tp_port,
            "dst-tp-port": dst_tp_port
        }
        matching_rules = dev.bigchain_find_rule(name, rule)

        if not matching_rules:
            module.exit_json(**result)

        matching_rule = matching_rules[0]
        path = dev.bigchain_path(
        ) + 'service[name="%s"]/policy/rule[sequence=%s]' % (
            name, matching_rule['sequence'])
        filter_rule_deletion = dev.delete(path, data=matching_rule)['content']
        result = dict(filter_rule_deletion=filter_rule_deletion)

    module.exit_json(**result)
Пример #6
0
def main():
    fields = dict(node=dict(required=True),
                  user=dict(required=True),
                  password=dict(required=True),
                  name=dict(required=True, type="str"),
                  ip_proto=dict(required=True, type="int"),
                  src_ip=dict(required=True, type="str"),
                  src_ip_mask=dict(required=True, type="str"),
                  dst_ip=dict(required=True, type="str"),
                  dst_ip_mask=dict(required=True, type="str"),
                  src_port=dict(required=True, type="int"),
                  dst_port=dict(required=True, type="int"))

    module = AnsibleModule(argument_spec=fields, supports_check_mode=True)

    node = module.params['node']
    user = module.params['user']
    password = module.params['password']
    name = module.params['name']
    ip_proto = module.params['ip_proto']
    src_ip = module.params['src_ip']
    src_ip_mask = module.params['src_ip_mask']
    dst_ip = module.params['dst_ip']
    dst_ip_mask = module.params['dst_ip_mask']
    src_tp_port = module.params['src_port']
    dst_tp_port = module.params['dst_port']

    result = {}
    with BmfRest(host=node, user=user, password=password, debug=True) as dev:
        sequence = dev.bigchain_next_service_rule_sequence_number(name)
        path = dev.bigchain_path(
        ) + 'service[name="%s"]/policy/rule[sequence=%s]' % (name, sequence)
        data = {
            "sequence": sequence,
            "ether-type": 2048,
            "ip-proto": ip_proto,
            "src-ip": src_ip,
            "src-ip-mask": src_ip_mask,
            "dst-ip": dst_ip,
            "dst-ip-mask": dst_ip_mask,
            "src-tp-port": src_tp_port,
            "dst-tp-port": dst_tp_port
        }
        filter_rule = dev.put(path, data=data)['content']
        result = dict(filter_rule=filter_rule)

    module.exit_json(**result)
Пример #7
0
def main():
    module = AnsibleModule(
        argument_spec = dict(
            node = dict(required=False)
        ),
        supports_check_mode = True
    )


    node = module.params['node']

    result = None
    with BmfRest(host=node, user='******', password='******', debug=True) as dev:
        content = dev.get('/rest/v1/system/version', data={})['content']
        result = dict(content=content)
        
    module.exit_json(**result)
Пример #8
0
def main():
    fields = dict(node=dict(required=True),
                  user=dict(required=True),
                  password=dict(required=True),
                  name=dict(required=True, type="str"),
                  instance_id=dict(required=True, type="str"),
                  switch=dict(required=True, type="str"),
                  input=dict(required=True, type="str"),
                  output=dict(required=True, type="str"))

    module = AnsibleModule(argument_spec=fields, supports_check_mode=True)

    node = module.params['node']
    user = module.params['user']
    password = module.params['password']
    name = module.params['name']
    instance_id = module.params['instance_id']
    switch = module.params['switch']
    in_interface = module.params['input']
    out_interface = module.params['output']
    result = {}

    with BmfRest(host=node, user=user, password=password, debug=True) as dev:
        path = dev.bigchain_path() + 'service[name="%s"]/instance[id=%s]' % (
            name, instance_id)
        data = {"id": instance_id}
        service_instance = dev.put(path, data=data)['content']

        path = dev.bigchain_path(
        ) + 'service[name="%s"]/instance[id=%s]/interface-pair' % (name,
                                                                   instance_id)
        data = {"switch": switch, "in": in_interface, "out": out_interface}
        service_instance_endpoints = dev.put(path, data=data)['content']

        result = dict(service_instance=service_instance,
                      service_instance_endpoints=service_instance_endpoints)

    module.exit_json(**result)