CloudForms tag_assign base method does not work for all objects

Solution Unverified - Updated -

Issue

The base object method does not work for all objects. Better would be to deprecate in future versions in favor of the add_tag syntax since you really need the category and tag. Maybe add an optional 3rd parameter to create category and/or tag if they don't exist, defaulting to false. Logic similar to below (from sources found in the product):

# Convert to lower case and replace all non-word characters with underscores
category_name = category.downcase.gsub(/\W/, '_')
tag_name = tag.downcase.gsub(/\W/, '_')
$evm.log("info", "Converted category name: <#{category_name}>")
$evm.log("info", "Converted tag name: <#{tag_name}>")
# if the category exists else create it
if $evm.execute('category_exists?', category_name)
  $evm.log("info", "Category <#{category_name}> exists")
else
  $evm.log("info", "Category <#{category_name}> doesn't exist, creating category")
  $evm.execute('category_create', :name => category_name, :single_value => true, :description => "#{category}")
end

# if the tag exists else create it
if $evm.execute('tag_exists?', category_name, tag_name)
  $evm.log("info", "Tag <#{tag_name}> exists")
else
  $evm.log("info", "Adding new tag <#{tag_name}> in Category <#{category_name}>")
  $evm.execute('tag_create', category_name, :name => tag_name, :description => "#{tag}")
end

Environment

  • Red Hat CloudForms 2.0
  • CloudForms Management Engine 5.1

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.