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 _system_state_change(module, client): state = module.params.get('state') if state == 'absent': floatingip_id = module.params.get('floatingip_id') floatingip = module.params.get('floatingip') if floatingip_id: return _check_floatingip_exists(client, floatingip_id) if floatingip and c._check_valid_ip(floatingip): return True \ if c.get_floatingip_by_ip(client, floatingip) else False if state == 'present': floatingips = module.params.get('floatingips') project_name = module.params.get('project_name') project_id = module.params.get('floatingip_id') force = module.params.get('force') if not c._check_valid_quantity(floatingips): return False if (project_name or project_id) and floatingips: if not project_id: project = c.get_project_by_name(client, project_name) if not project: return False project_id = project.id parsed_ips = f.parse_floatingips_to_add(floatingips) actual_ips = f.get_project_ips_quantity(client, project_id) to_add, to_del = c.compare_existed_and_needed_objects( actual_ips, parsed_ips, force) return True if to_add or to_del else False return False
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 _system_state_change(module, client): state = module.params.get('state') if state == 'absent': subnet_id = module.params.get('subnet_id') if subnet_id: return _check_subnet_exists(client, subnet_id) if state == 'present': subnets = module.params.get('subnets') project_name = module.params.get('project_name') project_id = module.params.get('project_id') force = module.params.get('force') if not c._check_valid_quantity(subnets): return False if (project_name or project_id) and subnets: if not project_id: project = c.get_project_by_name(client, project_name) if not project: return False project_id = project.id parsed_subnets = s.parse_subnets_to_add(subnets) actual_subnets = s.get_project_subnets_quantity(client, project_id) to_add, to_del = c.compare_existed_and_needed_objects( actual_subnets, parsed_subnets, force) return True if to_add or to_del else False return False