def main():
    argument_spec = openstack_full_argument_spec(
        name=dict(type='str', required=True))

    module_kwargs = openstack_module_kwargs()
    module = AnsibleModule(argument_spec,
                           supports_check_mode=False,
                           **module_kwargs)

    clustername_id = module.params['name']

    cloud = connect_from_ansible(module)
    try:
        # temporary fix for the fact that the new RDS service is not yet in catalog
        cloud.add_service(cce_service.CceService("ccev2.0", aliases=["cce2"]))

        cluster = cloud.cce2.find_cluster(clustername_id)

        if cluster:
            cert_info = cloud.cce2.get_cluster_certs(cluster)
            if cert_info:
                module.exit_json(changed=False,
                                 ansible_facts=dict(cluster_certs=cert_info))

        module.exit_json(changed=False, ansible_facts={})
    except exceptions.OpenStackCloudException as e:
        module.fail_json(msg=str(e))
def main():
    argument_spec = openstack_full_argument_spec(
        peering=dict(type='str',
                     required=True,
                     aliases=['peering_id', "nexthop"]),
        state=dict(default='accept', choices=['present', 'absent']),
        destination=dict(type='str', required=True),
        vpc=dict(type='str', required=True, aliases=['vpc_id']),
    )

    module_kwargs = openstack_module_kwargs()
    module = AnsibleModule(argument_spec, **module_kwargs)

    state = module.params['state']
    peering_name = module.params['peering']
    vpc_name = module.params['vpc']

    cloud = connect_from_ansible(module)
    try:
        cloud.add_service(vpc_service.VpcService("vpc", aliases=['vpc1']))
        # need to use the artificial endpoint without project-id
        cloud.add_service(vpc_service.VpcService("peervpc"))

        peering = cloud.peervpc.find_peering(peering_name,
                                             ignore_missing=False)
        vpc = cloud.vpc.find_vpc(vpc_name, ignore_missing=False)

        routes = cloud.peervpc.routes(nexthop=peering.id,
                                      destination=module.params['destination'],
                                      vpc_id=vpc.id)

        if state == 'present':
            try:
                route = next(routes)
                changed = False
            except StopIteration:
                route = cloud.peervpc.create_route(
                    nexthop=peering.id,
                    destination=module.params['destination'],
                    vpc_id=vpc.id)
                changed = True
            module.exit_json(changed=changed, route=route.copy(), id=route.id)

        elif state == 'absent':
            try:
                cloud.peervpc.delete_route(next(routes).id)
                module.exit_json(changed=True)
            except StopIteration:
                module.exit_json(changed=False)

    except exceptions.OpenStackCloudException as e:
        module.fail_json(msg=str(e))
def main():
    argument_spec = openstack_full_argument_spec(
        cluster=dict(type='str', required=True),
        node_ids=dict(type=list),
        wait_status=dict(type='str', choices=['active', 'deleted']))
    # redefine wait default behavior, wait must be enabled expicitly here
    argument_spec['wait']['default'] = False

    module_kwargs = openstack_module_kwargs()
    module = AnsibleModule(argument_spec,
                           supports_check_mode=False,
                           **module_kwargs)

    clustername_id = module.params['cluster']

    cloud = connect_from_ansible(module)
    try:
        # temporary fix for the fact that the new RDS service is not yet in catalog
        cloud.add_service(cce_service.CceService("ccev2.0", aliases=["cce2"]))

        cluster = cloud.cce2.find_cluster(clustername_id)

        if cluster:
            if not module.params['wait']:
                if 'node_ids' in module.params:
                    nodes = filter(
                        lambda res: res.id in module.params['node_ids'],
                        cloud.cce2.cluster_nodes(cluster.id))
                else:
                    nodes = cloud.cce2.cluster_nodes(cluster.id)
                module.exit_json(changed=False,
                                 ansible_facts=dict(cluster_nodes=list(nodes)))
            elif module.params['wait_status'] == 'active':
                nodes = cloud.cce2.wait_for_status_nodes(
                    cluster.id, module.params['node_ids'])
                module.exit_json(changed=False,
                                 ansible_facts=dict(cluster_nodes=list(nodes)))
            elif module.params['wait_status'] == 'deleted':
                nodes = cloud.cce2.wait_for_delete_nodes(
                    cluster.id, module.params['node_ids'])
                module.exit_json(changed=False,
                                 ansible_facts=dict(cluster_nodes=list(nodes)))

        module.exit_json(changed=False, ansible_facts={})

    except exceptions.OpenStackCloudException as e:
        module.fail_json(msg=str(e))
예제 #4
0
def main():
    argument_spec = openstack_full_argument_spec(
        name=dict(type='str', required=True),
        cidr=dict(type='str'),
        enable_shared_snat=dict(default=False, type='bool'),
        state=dict(default='present', choices=['absent', 'present']),
    )

    module_kwargs = openstack_module_kwargs()
    module = AnsibleModule(argument_spec, **module_kwargs)

    state = module.params['state']
    name = module.params['name']

    cloud = connect_from_ansible(module)
    try:
        cloud.add_service( vpc_service.VpcService("vpc", aliases=['vpc1'] ))
        cloud.add_service( vpc_service.VpcService("vpc2.0", aliases=['vpc2'] ))

        v = cloud.vpc.find_vpc(name)

        if state == 'present':
            if not v:
                v = cloud.vpc.create_vpc(name=name,
                    cidr=module.params['cidr'],
                    enable_shared_snat=module.params['enable_shared_snat'])
                changed = True
            elif _needs_update(module, cloud, v):
                v = cloud.vpc.update_vpc(vpc=v,
                    name=name,
                    cidr=module.params['cidr'],
                    enable_shared_snat=module.params['enable_shared_snat'])
                changed = True
            else:
                changed = False
            module.exit_json(changed=changed, vpc=v.copy(), id=v.id )

        elif state == 'absent':
            if not v:
                module.exit_json(changed=False)
            else:
                cloud.vpc.delete_vpc(v)
                module.exit_json(changed=True)

    except exceptions.OpenStackCloudException as e:
        module.fail_json(msg=str(e))
def main():
    argument_spec = openstack_full_argument_spec(
        peering=dict(type='str', required=True, aliases=['peering_id']),
        state=dict(default='accept', choices=['accept', 'reject']),
    )

    module_kwargs = openstack_module_kwargs()
    module = AnsibleModule(argument_spec, **module_kwargs)

    state = module.params['state']
    peering_name = module.params['peering']

    cloud = connect_from_ansible(module)
    try:
        cloud.add_service(vpc_service.VpcService("vpc", aliases=['vpc1']))
        # need to use the artificial endpoint without project-id
        cloud.add_service(vpc_service.VpcService("peervpc"))

        v = cloud.peervpc.find_peering(peering_name, ignore_missing=False)
        if state == 'accept':
            if v.status == "PENDING_ACCEPTANCE":
                cloud.peervpc.accept_peering(v)
                if module.params['wait']:
                    v = cloud.peervpc.wait_for_status(v, "ACTIVE")
                changed = True
            elif v.status == "ACTIVE":
                changed = False
            else:
                module.fail_json(msg="Peering in wrong state " + v.status)
        elif state == 'reject':
            if v.status == "PENDING_ACCEPTANCE":
                cloud.peervpc.reject_peering(v)
                if module.params['wait']:
                    v = cloud.peervpc.wait_for_status(v, "REJECTED")
                changed = True
            elif v.status == "REJECTED":
                changed = False
            else:
                module.fail_json(msg="Peering in wrong state " + v.status)
        else:
            changed = False
        module.exit_json(changed=changed, peering=v.copy(), id=v.id)

    except exceptions.OpenStackCloudException as e:
        module.fail_json(msg=str(e))
def main():
    argument_spec = openstack_full_argument_spec(
        name=dict(type='str', required=True),
        queue_id=dict(type='str'),
        state=dict(default='present', choices=['absent', 'present']),
    )

    module_kwargs = openstack_module_kwargs()
    module = AnsibleModule(argument_spec, **module_kwargs)

    state = module.params['state']
    name = module.params['name']
    queue = module.params['queue_id']

    cloud = connect_from_ansible(module)
    try:
        cloud.add_service(dms_service.DmsService("dmsv1", aliases=['dms']))

        qgroup = cloud.dms.find_queue_group(queue=queue, name_or_id=name)

        if state == 'present':
            if not qgroup:
                qgroup = cloud.dms.create_queue_group(queue=queue, name=name)
                changed = True
            else:
                changed = False
            module.exit_json(changed=changed,
                             queue_group=qgroup.copy(),
                             id=qgroup.id)

        elif state == 'absent':
            if not qgroup:
                module.exit_json(changed=False)
            else:
                cloud.dms.delete_queue_group(queue=queue, group=qgroup)
                module.exit_json(changed=True)

    except exceptions.OpenStackCloudException as e:
        module.fail_json(msg=str(e))
def main():

    argument_spec = openstack_full_argument_spec(name=dict(required=False,
                                                           default=None,
                                                           aliases=['subnet']),
                                                 filters=dict(required=False,
                                                              type='dict',
                                                              default={}))
    module = AnsibleModule(argument_spec)

    cloud = connect_from_ansible(module)
    try:
        cloud.add_service(vpc_service.VpcService("vpc", aliases=['vpc1']))
        cloud.add_service(vpc_service.VpcService("vpc2.0", aliases=['vpc2']))

        subnets = cloud.vpc.find_subnet(name_or_id=module.params['name'],
                                        **module.params['filters'])
        if subnets:
            module.exit_json(changed=False, subnet=subnets.copy())
        else:
            module.fail_json(msg="Subnet %s not found" % module.params['name'])

    except exceptions.OpenStackCloudException as e:
        module.fail_json(msg=str(e))
예제 #8
0
def main():
    argument_spec = openstack_full_argument_spec(
        name=dict(type='str', required=True),
        queue_mode=dict(type='str',
                        choices=["NORMAL", "FIFO", "KAFKA_HA", "KAFKA_HT"]),
        description=dict(type='str'),
        redrive_policy=dict(default='enable', choices=['enable', 'disable']),
        max_consume_count=dict(type='int'),
        retention_hours=dict(type='int'),
        state=dict(default='present', choices=['absent', 'present']),
    )

    module_kwargs = openstack_module_kwargs()
    module = AnsibleModule(argument_spec, **module_kwargs)

    state = module.params['state']
    name = module.params['name']
    mode = module.params['queue_mode']

    cloud = connect_from_ansible(module)
    try:
        cloud.add_service(dms_service.DmsService("dmsv1", aliases=['dms']))

        q = cloud.dms.find_queue(name)

        if state == 'present':
            if not q:
                if mode == "NORMAL" or mode == "FIFO":
                    params = {
                        "name": name,
                        "description": module.params['description'],
                        "queue_mode": mode,
                        "redrive_policy": module.params['redrive_policy'],
                    }
                    if module.params[
                            'redrive_policy'] == 'enabled' and module.params[
                                'max_consume_count']:
                        params['max_consume_count'] = module.params[
                            'max_consume_count']
                else:
                    params = {
                        "name": name,
                        "description": module.params['description'],
                        "queue_mode": mode,
                        "retention_hours": module.params['retention_hours'],
                    }
                q = cloud.dms.create_queue(**params)
                changed = True
            else:
                changed = False
            module.exit_json(changed=changed, queue=q.copy(), id=q.id)

        elif state == 'absent':
            if not q:
                module.exit_json(changed=False)
            else:
                cloud.dms.delete_queue(q)
                module.exit_json(changed=True)

    except exceptions.OpenStackCloudException as e:
        module.fail_json(msg=str(e))
def main():
    argument_spec = openstack_full_argument_spec(
        nat_gateway_id=dict(type='str', required=True),
        subnet_id=dict(type='str'),
        cidr=dict(type='str'),
        eip_id=dict(type='str'),
        state=dict(default='present', choices=['absent', 'present']),
    )

    module_kwargs = openstack_module_kwargs(
        mutually_exclusive=[
            ['subnet_id', 'cidr'],
        ]
    )
    module = AnsibleModule(argument_spec,
                           supports_check_mode=False,
                           **module_kwargs)

    state = module.params['state']
    nat_gateway_id = module.params['nat_gateway_id']
    subnet_id = module.params['subnet_id']
    cidr = module.params['cidr']

    cloud = connect_from_ansible(module)
    try:
        cloud.add_service( nat_service.NatService("nat") )
        rule = _find_snatrule(module, cloud, nat_gateway_id, subnet_id, cidr)

        # FIXME
        # if module.check_mode:
        #    module.exit_json(changed=_system_state_change(module, subnet,
        #                                              cloud))

        if state == 'present':
            if not rule:
                if subnet_id is not None:
                    rule = cloud.nat.create_snat_rule(nat_gateway_id=nat_gateway_id,
                                                  eip_id=module.params['eip_id'],
                                                  subnet_id=subnet_id
                                                  )
                else:
                    rule = cloud.nat.create_snat_rule(nat_gateway_id=nat_gateway_id,
                                                  eip_id=module.params['eip_id'],
                                                  cidr=cidr
                                                  )
                changed = True
            else:
                changed = False
            module.exit_json(changed=changed,
                         nat=rule.copy(),
                         id=rule.id)
        elif state == 'absent':
            if not rule:
                changed = False
            else:
                changed = True
                cloud.nat.delete_snat_rule(rule)
            module.exit_json(changed=changed)

    except exceptions.OpenStackCloudException as e:
        module.fail_json(msg=str(e))
예제 #10
0
def main():
    argument_spec = openstack_full_argument_spec(
        state=dict(type='str',
                   default='present',
                   choices=['absent', 'present']),
        name=dict(type='str', required=True),
        cidr=dict(type='str'),
        gateway_ip=dict(type='str'),
        vpc_id=dict(type='str'),
        dhcp_enable=dict(type='bool', default=True),
        dns_nameservers=dict(type='list', default=None),
        availability_zone=dict(type='str'),
        extra_dhcp_opts=dict(type='dict', default=dict()),
    )

    module_kwargs = openstack_module_kwargs()
    module = AnsibleModule(argument_spec,
                           supports_check_mode=False,
                           **module_kwargs)

    state = module.params['state']
    name = module.params['name']
    gateway_ip = module.params['gateway_ip']

    cloud = connect_from_ansible(module)
    try:
        cloud.add_service(vpc_service.VpcService("vpc", aliases=['vpc']))
        cloud.add_service(vpc_service.VpcService("vpc2.0", aliases=['vpc2']))

        subnet = cloud.vpc.find_subnet(name)

        # FIXME
        # if module.check_mode:
        #    module.exit_json(changed=_system_state_change(module, subnet,
        #                                              cloud))

        if state == 'present':
            if not subnet:
                dhcp_extras = _dict_to_opts(module.params['extra_dhcp_opts'])
                if dhcp_extras:
                    subnet = cloud.vpc.create_subnet(
                        name=name,
                        cidr=module.params['cidr'],
                        dhcp_enable=module.params['dhcp_enable'],
                        gateway_ip=gateway_ip,
                        vpc=module.params['vpc_id'],
                        dnsList=module.params['dns_nameservers'],
                        extra_dhcp_opts=dhcp_extras)
                    subnet.extra_dhcp_opts = module.params['extra_dhcp_opts']
                else:
                    subnet = cloud.vpc.create_subnet(
                        name=name,
                        cidr=module.params['cidr'],
                        dhcp_enable=module.params['dhcp_enable'],
                        gateway_ip=gateway_ip,
                        vpc=module.params['vpc_id'],
                        dnsList=module.params['dns_nameservers'])
                changed = True
            elif (_can_update(module, cloud, subnet)
                  and _needs_update(module, cloud, subnet)):
                cloud.vpc.update_subnet(
                    subnet['id'],
                    name=name,
                    cidr=module.params['cidr'],
                    dhcp_enable=module.params['dhcp_enable'],
                    dnsList=module.params['dns_nameservers'],
                    extra_dhcp_opts=_dict_to_opts(
                        module.params['extra_dhcp_opts']))
                changed = True
            else:
                changed = False
            if changed and module.params['wait']:
                cloud.vpc.wait_for_status(subnet)
            module.exit_json(changed=changed,
                             id=subnet.id,
                             subnet=subnet.copy())

        elif state == 'absent':
            if not subnet:
                changed = False
            else:
                changed = True
                cloud.vpc.delete_subnet(subnet)
                if module.params['wait']:
                    cloud.vpc.wait_for_delete(subnet)
            module.exit_json(changed=changed)

    except exceptions.OpenStackCloudException as e:
        module.fail_json(msg=str(e))
예제 #11
0
def main():
    argument_spec = openstack_full_argument_spec(
        reuse=dict(type='bool', default=True),
        state=dict(default='present', choices=['absent', 'present']),
        eip_id=dict(type='str'))

    module_kwargs = openstack_module_kwargs()
    module = AnsibleModule(argument_spec, **module_kwargs)

    state = module.params['state']

    cloud = connect_from_ansible(module)
    try:
        if state == 'present':

            # find the external network the EIP belongs to
            external_networks = list(
                cloud.network.networks(
                    is_router_external=True,
                    project_id=cloud.session.get_project_id()))
            if not external_networks:
                module.fail_json(msg="No external network for project.")
            external_network = external_networks[0]

            # try to find a free eip first
            eip = None
            if module.params['reuse']:
                eips = cloud.network.ips(
                    floating_network_id=external_network.id,
                    project_id=cloud.session.get_project_id())
                eips = list(filter(lambda ip: ip.port_id is None, eips))
                if eips:
                    eip = eips[0]
                changed = False
            if not eip:
                # if none found: allocate a new EIP
                eip = cloud.network.create_ip(
                    floating_network_id=external_network.id)
                changed = True
            module.exit_json(changed=changed, eip=eip.copy(), id=eip.id)

        elif state == 'absent':
            eip_id = module.params['eip_id']
            eip = cloud.network.get_ip(eip_id)
            if not eip:
                module.exit_json(changed=False)
            else:
                cloud.network.delete_ip(eip_id)
                module.exit_json(changed=True)

        elif state == 'unbind':
            eip_id = module.params['eip_id']
            eip = cloud.network.get_ip(eip_id)
            if not eip:
                module.exit_json(changed=False)
            else:
                cloud.network.delete_port(eip.port_id)
                module.exit_json(changed=True)

    except exceptions.OpenStackCloudException as e:
        module.fail_json(msg=str(e))
예제 #12
0
def main():
    argument_spec = openstack_full_argument_spec(
        state=dict(type='str',
                   default='present',
                   choices=['absent', 'present']),
        cluster=dict(type='str', alias='cluster_id', required=True),
        name=dict(type='str'),
        flavor=dict(type='str'),
        availability_zone=dict(type='str', default="eu-de-01"),
        key_name=dict(type='str'),
        count=dict(type='int'),
        root_volume=dict(type='dict'),
        data_volumes=dict(type='list'),
        public_ip=dict(type='dict'),
    )

    # FIXME: define some more constraints like mutual exclusives
    module_kwargs = openstack_module_kwargs()
    module = AnsibleModule(argument_spec,
                           supports_check_mode=False,
                           **module_kwargs)

    state = module.params['state']
    clustername_id = module.params['cluster']

    cloud = connect_from_ansible(module)
    try:
        # temporary fix for the fact that the new RDS service is not yet in catalog
        cloud.add_service(cce_service.CceService("ccev2.0", aliases=["cce2"]))

        # search for cluster by name or id
        cluster = cloud.cce2.find_cluster(clustername_id)
        if cluster:
            if state == 'present':
                # filter existing nodes with given spec
                existing_nodes, existing_ids = _current_spec_nodes(
                    cloud, cluster.id, **module.params)
                new_count = int(module.params['count']) - len(existing_nodes)

                if new_count > 0:
                    _add_nodes(cloud, cluster.id, new_count, **module.params)
                    changed = True
                    if module.params['wait']:
                        new_nodes = _new_nodes(cloud, cluster.id, existing_ids,
                                               **module.params)
                        cloud.cce2.wait_for_status_nodes(cluster.id, new_nodes)
                    existing_nodes, existing_ids = _current_spec_nodes(
                        cloud, cluster.id, **module.params)

                elif new_count < 0:
                    nodes_to_delete = existing_nodes[new_count:]
                    if nodes_to_delete:
                        for node in nodes_to_delete:
                            cloud.cce2.delete_cluster_node(cluster.id, node)
                        changed = True
                        if module.params['wait']:
                            cloud.cce2.wait_for_delete_nodes(
                                cluster.id, nodes_to_delete)
                        existing_nodes, existing_ids = _current_spec_nodes(
                            cloud, cluster.id, **module.params)
                else:
                    changed = False
                module.exit_json(changed=changed,
                                 ids=existing_ids,
                                 nodes=existing_nodes)

            elif state == 'absent':
                nodes_to_delete = _filter_for_delete(cloud, cluster.id,
                                                     **module.params)
                if nodes_to_delete:
                    for node in nodes_to_delete:
                        cloud.cce2.delete_cluster_node(cluster.id, node)
                    changed = True
                    if module.params['wait']:
                        cloud.cce2.wait_for_delete_nodes(
                            cluster.id, nodes_to_delete)
                else:
                    changed = False
                module.exit_json(changed=changed)

        else:
            module.fail_json(msg=str("Cluster " + clustername_id +
                                     " not found"))

    except exceptions.OpenStackCloudException as e:
        module.fail_json(msg=str(e))
예제 #13
0
def main():
    argument_spec = openstack_full_argument_spec(state=dict(
        type='str', default='present', choices=['absent', 'present']),
                                                 name=dict(type='str',
                                                           required=True),
                                                 description=dict(type='str'),
                                                 spec=dict(type='str',
                                                           default="1"),
                                                 vpc_id=dict(type='str'),
                                                 subnet_id=dict(type='str'))

    module_kwargs = openstack_module_kwargs()
    module = AnsibleModule(argument_spec,
                           supports_check_mode=False,
                           **module_kwargs)

    state = module.params['state']
    name = module.params['name']

    cloud = connect_from_ansible(module)
    try:
        cloud.add_service(nat_service.NatService("nat"))
        natgw = cloud.nat.find_nat(name)

        # FIXME
        # if module.check_mode:
        #    module.exit_json(changed=_system_state_change(module, subnet,
        #                                              cloud))

        if state == 'present':
            if not natgw:
                natgw = cloud.nat.create_nat(
                    name=name,
                    description=module.params['description'],
                    spec=module.params['spec'],
                    vpc_id=module.params['vpc_id'],
                    subnet_id=module.params['subnet_id'],
                )
                changed = True
            elif (_can_update(module, cloud, natgw)
                  and _needs_update(module, cloud, natgw)):
                cloud.nat.update_nat(name=name,
                                     description=module.params['description'],
                                     spec=module.params['spec'])
                changed = True
            else:
                changed = False

            if changed and module.params['wait']:
                cloud.nat.wait_for_status(natgw)
            module.exit_json(changed=changed, nat=natgw.copy(), id=natgw.id)

        elif state == 'absent':
            if not natgw:
                changed = False
            else:
                changed = True
                cloud.nat.delete_nat(natgw)
                if module.params['wait']:
                    cloud.nat.wait_for_delete(natgw)
            module.exit_json(changed=changed)

    except exceptions.OpenStackCloudException as e:
        module.fail_json(msg=str(e))
예제 #14
0
def main():
    argument_spec = openstack_full_argument_spec(
        state=dict(type='str',
                   default='present',
                   choices=['absent', 'present']),
        name=dict(type='str', required=True),
        datastore_type=dict(type='str', default="elasticsearch"),
        datastore_version=dict(type='str', default="6.2.3"),
        instances=dict(type='int', alias="instanceNum"),
        flavor_ref=dict(type='str', alias="flavorRef"),
        volume_type=dict(type='str'),
        volume_size=dict(type='int'),
        vpc_id=dict(type='str'),
        subnet_id=dict(type='str'),
        security_group_id=dict(type='str', alias="securityGroupId"),
        httpsEnable=dict(type='str'),
        disk_encryption_id=dict(type='str', default=None))

    # FIXME: define some more constraints like mutual exclusives
    module_kwargs = openstack_module_kwargs()
    module = AnsibleModule(argument_spec,
                           supports_check_mode=False,
                           **module_kwargs)

    state = module.params['state']
    name = module.params['name']

    cloud = connect_from_ansible(module)
    try:
        # temporary fix for the fact that the new RDS service is not yet in catalog
        cloud.add_service(css_service.CssService("css"))

        cluster = cloud.css.find_cluster(name)

        # FIXME
        # if module.check_mode:
        #    module.exit_json(changed=_system_state_change(module, subnet,
        #                                              cloud))

        if state == 'present':
            if not cluster:
                cluster = _create_cluster(module, cloud)
                changed = True
            else:
                changed = False
            if changed and module.params['wait']:
                cloud.css.wait_for_status(cluster)
            module.exit_json(changed=changed,
                             id=cluster.id,
                             css=cluster.copy())

        elif state == 'absent':
            if not cluster:
                changed = False
            else:
                changed = True
                cloud.css.delete_cluster(cluster)
                if module.params['wait']:
                    cloud.css.wait_for_delete(cluster)
            module.exit_json(changed=changed)

    except exceptions.OpenStackCloudException as e:
        module.fail_json(msg=str(e))
예제 #15
0
def main():
    argument_spec = openstack_full_argument_spec(
        state=dict(type='str',
                   default='present',
                   choices=['absent', 'present']),
        name=dict(type='str', required=True),
        datastore_type=dict(type='str'),
        datastore_version=dict(type='str'),
        replication_mode=dict(type='str', default=None),
        replica_of_id=dict(type='str', default=None),
        parameter_group_id=dict(type='str', default=None),
        port=dict(type='str', default=None),
        password=dict(type='str', no_log=True),
        backup_start_time=dict(type='str', default=None),
        backup_keep_days=dict(type='int', default=None),
        disk_encryption_id=dict(type='str', default=None),
        flavor_ref=dict(type='str'),
        volume_type=dict(type='str'),
        volume_size=dict(type='int'),
        region=dict(type='str'),
        availability_zone=dict(type='str'),
        vpc_id=dict(type='str'),
        subnet_id=dict(type='str'),
        security_group_id=dict(type='str'))

    # FIXME: define some more constraints like mutual exclusives
    module_kwargs = openstack_module_kwargs()
    module = AnsibleModule(argument_spec,
                           supports_check_mode=False,
                           **module_kwargs)

    state = module.params['state']
    name = module.params['name']

    cloud = connect_from_ansible(module)
    try:
        # temporary fix for the fact that the new RDS service is not yet in catalog
        cloud.add_service(rds_service.Rds3Service("rdsv3"))

        db = cloud.rdsv3.find_db(name)

        # FIXME
        # if module.check_mode:
        #    module.exit_json(changed=_system_state_change(module, subnet,
        #                                              cloud))

        if state == 'present':
            if not db:
                db = _create_db(module, cloud)
                changed = True
            else:
                changed = False
            if changed and module.params['wait']:
                cloud.rdsv3.wait_for_status(db)
            module.exit_json(changed=changed, id=db.id, rds=db.copy())

        elif state == 'absent':
            if not db:
                changed = False
            else:
                changed = True
                cloud.rdsv3.delete_db(db)
                if module.params['wait']:
                    cloud.rdsv3.wait_for_delete(db)
            module.exit_json(changed=changed)

    except exceptions.OpenStackCloudException as e:
        module.fail_json(msg=str(e))
def main():
    argument_spec = openstack_full_argument_spec(
        name=dict(type='str', required=True),
        vpc=dict(type='str', aliases=['vpc_id']),
        peervpc=dict(type='str', aliases=['peervpc_id']),
        peerproject_id=dict(type='str'),
        description=dict(type='str'),
        state=dict(default='present', choices=['absent', 'present']),
    )

    module_kwargs = openstack_module_kwargs()
    module = AnsibleModule(argument_spec, **module_kwargs)

    state = module.params['state']
    name = module.params['name']
    description = module.params['description']

    cloud = connect_from_ansible(module)
    try:
        cloud.add_service(vpc_service.VpcService("vpc", aliases=['vpc1']))
        # need to use the artificial endpoint without project-id
        cloud.add_service(vpc_service.VpcService("peervpc"))

        peering = cloud.peervpc.find_peering(name)

        if state == 'present':
            if not peering:
                vpc = cloud.vpc.find_vpc(module.params['vpc'],
                                         ignore_missing=False)
                peerproject_id = module.params['peerproject_id']

                if not peerproject_id:
                    peervpc = cloud.vpc.find_vpc(module.params['peervpc'],
                                                 ignore_missing=False)
                else:
                    # FIXME: remote peerings work only with ids at the moment
                    # so we build an empty resource to use the same followup code
                    peervpc = Vpc(id=module.params['peervpc'])

                new_peer = Peering(
                    name=name,
                    request_vpc_info=VpcInfoSpec(vpc_id=vpc.id, ),
                    accept_vpc_info=VpcInfoSpec(vpc_id=peervpc.id, ))
                if peerproject_id:
                    new_peer.accept_vpc_info.tenant_id = peerproject_id
                if description:
                    new_peer.description = description

                peering = cloud.peervpc.create_peering(**new_peer.to_dict(
                    ignore_none=True))
                changed = True
            elif _needs_update(module, cloud, peering):
                if description:
                    peering.description = description
                peering = cloud.peervpc.update_peering(**peering.to_dict(
                    ignore_none=True))
                changed = True
            else:
                changed = False
            module.exit_json(changed=changed,
                             vpc=peering.copy(),
                             id=peering.id)

        elif state == 'absent':
            if not peering:
                module.exit_json(changed=False)
            else:
                cloud.peervpc.delete_peering(peering)
                module.exit_json(changed=True)

    except exceptions.OpenStackCloudException as e:
        module.fail_json(msg=str(e))