def add_floatingips(module, client, project_id, project_name, floatingips, force): jsonifed_result, changed, msg = {}, False, [] if not common._check_valid_quantity(floatingips): module.fail_json(msg="Wrong 'quantity'") parsed_ips = parse_floatingips_to_add(floatingips) actual_ips = get_project_ips_quantity(client, project_id) to_create, to_delete = common.compare_existed_and_needed_objects( actual_ips, parsed_ips, force) to_create = [{ 'region': region, 'quantity': quantity } for region, quantity in to_create.items() if quantity] if to_create: result = client.floatingips.add(project_id, {"floatingips": to_create}) if isinstance(result, ParticleResponse): common.abort_particle_response_task(module, client, result) changed = True msg.append("floating ips have been added") jsonifed_result.update({"added": result}) if to_delete: result = delete_useless_ips(client, to_delete, project_id) changed = True msg.append("some ips have been deleted") jsonifed_result.update({"deleted": result}) return jsonifed_result, changed, common.generate_result_msg(msg)
def add_subnets(module, client, project_id, project_name, subnets, force): jsonifed_result, changed, msg = {}, False, [] if not common._check_valid_quantity(subnets): module.fail_json(msg="Wrong 'quantity'") parsed_subs = parse_subnets_to_add(subnets) actual_subs = get_project_subnets_quantity(client, project_id) to_create, to_delete = common.compare_existed_and_needed_objects( actual_subs, parsed_subs, force) to_create = [{'region': params[0], 'type': params[1], 'prefix_length': params[2], 'quantity': quantity} for params, quantity in to_create.items() if quantity] if to_create: result = client.subnets.add(project_id, {"subnets": to_create}) if isinstance(result, ParticleResponse): common.abort_particle_response_task(module, client, result) changed = True msg.append("subnets have been added") jsonifed_result.update({"added": result}) if to_delete: result = delete_useless_subnets( client, to_delete, project_id) changed = True msg.append("some subnets have been deleted") jsonifed_result.update({"deleted": result}) return jsonifed_result, changed, common.generate_result_msg(msg)
def set_quotas(module, client, project_id, project_name, quotas): result, changed, msg = None, False, "Project has already had such quotas" if common._check_quotas_changes(client, quotas, project_id): result = client.quotas.update(project_id, {"quotas": quotas}) if isinstance(result, PartialResponse): common.abort_particle_response_task(module, client, result, project_id, is_quotas=True) changed, msg = True, "Quotas are set successfully" return result, changed, msg