"hammer content-view remove" - cannot delete version while it is in environment Library

Latest response

The following CLI command :

hammer content-view remove --content-view-version-ids $VID --name "$CONTENT_V_NAME" $ORG

tells :
Could not remove objects from content view:
Cannot delete version while it is in environment Library
If I try the same through web console, I have the following option
**Completely remove version? **
and permit the deletion.

What’s the way to get this option with hammer CLI ?

Responses

Sure you can!You need to remove the Library environment from the content view. Just check your organization ID first, here I use for example 3, you can use

hammer organization list

1)List all your content view

hammer content-view version list

2)Remove it from the Library

hammer content-view remove-from-environment --id "CV ID" --lifecycle-environment Library --organization-id 3

3)Now you can delete the content view

hammer content-view delete --id "CV ID" --organization-id 3

Hi Gabriel, this is not working on my side :

#hammer content-view version list|grep "RHEL7.4 x86_64 security per month"
213 | RHEL7.4 x86_64 security per month 11.0  | 11.0    | Library
196 | RHEL7.4 x86_64 security per month 9.0   | 9.0     |
193 | RHEL7.4 x86_64 security per month 7.0   | 7.0     |
192 | RHEL7.4 x86_64 security per month 6.0   | 6.0     |

#hammer content-view remove-from-environment --id 213 --lifecycle-environment Library --organization-id 1
Could not remove the content view from environment:
  Couldn't find Katello::ContentView with 'id'=213

And notice the following works, but might be dangerous, right ?

hammer content-view remove-from-environment --name "RHEL7.4 x86_64 security per month" --lifecycle-environment Library  --organization-id 1

Thanks

Pascal,

Can you please clarify what it is you are trying to do? From the discussion so far I am unsure if you are trying to delete the entire content view from the Library environment, or only delete a specific version of a content view.

In your most recent comment you listed the available versions of the content view RHEL7.4 x86_64 security per month, but in the next command you provide the version's ID, not the content view's ID. I believe that is why hammer responded with the following message:

Couldn't find Katello::ContentView with 'id'=213

This message indicates that there is no content view with an ID of 213. In your last example command, where you mention the content view by --name, hammer knows to which content view you are referring. However, that will remove the entire content view from the Library environment. It's not dangerous to do so, if that is what you are trying to do.

If you can clarify what it is you are trying to do, I'm sure we can find a solution.

how to delete specific content view version instead of deleting the entire content view?

Hello, se the below example within hammer shell:

hammer> content-view version list --content-view cv_all --organization-id 1
----|-------------|---------|-------------|-----------------------
ID  | NAME        | VERSION | DESCRIPTION | LIFECYCLE ENVIRONMENTS
----|-------------|---------|-------------|-----------------------
..
25  | cv_all 4.0  | 4.0     |             |                       
19  | cv_all 3.0  | 3.0     |             |                       
16  | cv_all 2.0  | 2.0     |             |                       
12  | cv_all 1.0  | 1.0     |             |                       
----|-------------|---------|-------------|-----------------------
hammer> content-view version delete --organization-id 1 --content-view cv_all --id 12
[.....................................................................................................................................................................................] [100%]
hammer> content-view version delete --organization-id 1 --content-view cv_all --version 2.0
[.....................................................................................................................................................................................] [100%]
hammer> content-view version list --content-view cv_all --organization-id 1
..
30  | cv_all 5.0  | 5.0     |             |                       
25  | cv_all 4.0  | 4.0     |             |                       
19  | cv_all 3.0  | 3.0     |             |                       

Optionally, to delete oldest CV versions in a bulk action, see hammer content-view purge --help.