Exemplo n.º 1
0
    def update_or_create(self):
        # Check if main object exists
        config = NitroResourceConfig(
            module=self.module,
            resource=self.main_nitro_class,
            attribute_values_dict=self.module.params,
            attributes_list=self.attibute_config[self.main_nitro_class]['attributes_list'],
            transforms=self.attibute_config[self.main_nitro_class]['transforms'],
        )

        # Create or update main object
        try:
            appfw_policy_exists = config.exists(get_id_attributes=self.attibute_config[self.main_nitro_class]['get_id_attributes'])
        except NitroException as e:
            # This is the no such policy label exists exception
            if e.errorcode == 3087:
                appfw_policy_exists = False
            else:
                raise

        if not appfw_policy_exists:
            self.module_result['changed'] = True
            if not self.module.check_mode:
                config.create()
        else:
            if not config.values_subgroup_of_actual():
                self.module_result['changed'] = True
                if not self.module.check_mode:
                    config.update(id_attribute='name')
    def delete(self):
        # Check if main object exists
        config = NitroResourceConfig(
            module=self.module,
            resource=self.main_nitro_class,
            attribute_values_dict=self.module.params,
            attributes_list=self.attibute_config[
                self.main_nitro_class]['attributes_list'],
            transforms=self.attibute_config[self.main_nitro_class]
            ['transforms'],
        )

        try:
            appfw_policy_exists = config.exists(
                get_id_attributes=self.attibute_config[
                    self.main_nitro_class]['get_id_attributes'])
        except NitroException as e:
            # This is the no such policy exists exception
            if e.errorcode == 2054:
                appfw_policy_exists = False
            else:
                raise
        if appfw_policy_exists:
            self.module_result['changed'] = True
            if not self.module.check_mode:
                config.delete(delete_id_attributes=self.attibute_config[
                    self.main_nitro_class]['delete_id_attributes'])