def main(): """Main function""" module = HwcModule( argument_spec=dict(state=dict(default='present', choices=['present', 'absent'], type='str'), name=dict(required=True, type='str'), cidr=dict(required=True, type='str')), supports_check_mode=True, ) config = Config(module, 'vpc') state = module.params['state'] if (not module.params.get("id")) and module.params.get("name"): module.params['id'] = get_id_by_name(config) fetch = None link = self_link(module) # the link will include Nones if required format parameters are missed if not re.search('/None/|/None$', link): client = config.client(get_region(module), "vpc", "project") fetch = fetch_resource(module, client, link) if fetch: fetch = fetch.get('vpc') changed = False if fetch: if state == 'present': expect = _get_editable_properties(module) current_state = response_to_hash(module, fetch) if are_dicts_different(expect, current_state): if not module.check_mode: fetch = update(config, self_link(module)) fetch = response_to_hash(module, fetch.get('vpc')) changed = True else: fetch = current_state else: if not module.check_mode: delete(config, self_link(module)) fetch = {} changed = True else: if state == 'present': if not module.check_mode: fetch = create(config, "vpcs") fetch = response_to_hash(module, fetch.get('vpc')) changed = True else: fetch = {} fetch.update({'changed': changed}) module.exit_json(**fetch)
def main(): """Main function""" module = HwcModule( argument_spec=dict(state=dict(default='present', choices=['present', 'absent'], type='str'), display_name=dict(type='str'), name=dict(required=True, type='str')), supports_check_mode=True, ) session = HwcSession(module, "app") state = module.params['state'] if not module.params.get("id"): module.params['id'] = get_resource_id(session) fetch = None link = self_link(session) # the link will include Nones if required format parameters are missed if not re.search('/None/|/None$', link): fetch = fetch_resource(session, link) changed = False if fetch: if state == 'present': expect = _get_resource_editable_properties(module) current_state = response_to_hash(module, fetch) if are_dicts_different(expect, current_state): if not module.check_mode: fetch = update(session) fetch = response_to_hash(module, fetch) changed = True else: fetch = current_state else: if not module.check_mode: delete(session) fetch = {} changed = True else: if state == 'present': if not module.check_mode: fetch = create(session) fetch = response_to_hash(module, fetch) changed = True else: fetch = {} fetch.update({'changed': changed}) module.exit_json(**fetch)