Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversion script for mapped tags/classification from remote regions to global #17971

Merged
merged 1 commit into from
Oct 9, 2018

Conversation

lpichler
Copy link
Contributor

@lpichler lpichler commented Sep 11, 2018

What we need

In global region, create and filter report according to tags from remote regions.

How

Create tag/categories in global regions:

  1. Find mapped categories (Classifications) in remote regions
  2. If categories don't exist in global then create them.
  3. Create Tags of these categories in remotes regions.

Usage

USAGE:  ./tools/convert_mapped_tags.rb -c|--commit
Example (Commit):  ./tools/convert_mapped_tags.rb --commit
Example (Dry Run): ./tools/convert_mapped_tags.rb         
  -c, --commit    Commit to database. The default behavior is to do a dry run
  -h, --help      Show this message
  • we created MyNewCategory category for mapping

read only mode:
./tools/convert_mapped_tags.rb
will output (just tag 'bronagh1213' doesn't exist):

READ ONLY MODE

Using...parent category `MyNewCategory` with tag: /managed/amazon:vm:name - from region 0 to region 99
Using....entry category smartstate of MyNewCategory - from region 0 to region 99
Using....entry category mslemr of MyNewCategory - from region 0 to region 99
Using....entry category hsong-centos of MyNewCategory - from region 0 to region 99
Using....entry category bronagh of MyNewCategory - from region 0 to region 99
Using....entry category ssa-docker of MyNewCategory - from region 0 to region 99
Using....entry category EmsRefreshSpec-PoweredOn-VPC of MyNewCategory - from region 0 to region 99
Using....entry category EmsRefreshSpecStack of MyNewCategory - from region 0 to region 99
Using....entry category EmsRefreshSpec-PoweredOff of MyNewCategory - from region 0 to region 99
Using....entry category ladas_ansible_test_2__1 of MyNewCategory - from region 0 to region 99
Using....entry category ladas_ansible_test_2__0 of MyNewCategory - from region 0 to region 99
Using....entry category mslemr-test4 of MyNewCategory - from region 0 to region 99
Using....entry category ladas-test-foreman.ec2.internal of MyNewCategory - from region 0 to region 99
Using....entry category EmsRefreshSpec-PoweredOn-Basic3 of MyNewCategory - from region 0 to region 99
Using....entry category ladas_ansible_test_2 of MyNewCategory - from region 0 to region 99
Using....entry category julian_le_noir of MyNewCategory - from region 0 to region 99
Creating...entry category bronagh1213 of MyNewCategory - from region 0 to region 99
Using....entry category stomsa of MyNewCategory - from region 0 to region 99
Using....entry category EmsRefreshSpec-PoweredOn-VPC1 of MyNewCategory - from region 0 to region 99
Using....entry category james of MyNewCategory - from region 0 to region 99

READ ONLY MODE - no changes have been applied

USAGE:  ./tools/convert_mapped_tags.rb -c|--commit
Example (Commit):  ./tools/convert_mapped_tags.rb --commit
Example (Dry Run): ./tools/convert_mapped_tags.rb         
  -c, --commit    Commit to database. The default behavior is to do a dry run
  -h, --help      Show this message

write mode:
./tools/convert_mapped_tags.rb WRITE


COMMIT MODE

Using...parent category MyNewCategory with tag: /managed/amazon:vm:name - from region 0 to region 99
Using....entry category smartstate of MyNewCategory - from region 0 to region 99
Using....entry category mslemr of MyNewCategory - from region 0 to region 99
Using....entry category hsong-centos of MyNewCategory - from region 0 to region 99
Using....entry category bronagh of MyNewCategory - from region 0 to region 99
Using....entry category ssa-docker of MyNewCategory - from region 0 to region 99
Using....entry category EmsRefreshSpec-PoweredOn-VPC of MyNewCategory - from region 0 to region 99
Using....entry category EmsRefreshSpecStack of MyNewCategory - from region 0 to region 99
Using....entry category EmsRefreshSpec-PoweredOff of MyNewCategory - from region 0 to region 99
Using....entry category ladas_ansible_test_2__1 of MyNewCategory - from region 0 to region 99
Using....entry category ladas_ansible_test_2__0 of MyNewCategory - from region 0 to region 99
Using....entry category mslemr-test4 of MyNewCategory - from region 0 to region 99
Using....entry category ladas-test-foreman.ec2.internal of MyNewCategory - from region 0 to region 99
Using....entry category EmsRefreshSpec-PoweredOn-Basic3 of MyNewCategory - from region 0 to region 99
Using....entry category ladas_ansible_test_2 of MyNewCategory - from region 0 to region 99
Using....entry category julian_le_noir of MyNewCategory - from region 0 to region 99
Creating...entry category bronagh1213 of MyNewCategory - from region 0 to region 99
Using....entry category stomsa of MyNewCategory - from region 0 to region 99
Using....entry category EmsRefreshSpec-PoweredOn-VPC1 of MyNewCategory - from region 0 to region 99
Using....entry category james of MyNewCategory - from region 0 to region 99

COMMIT MODE - change have been applied

Note

This script is not enabling tags to be able assign them in Tag Control. - To reach behaviour we need also this PRs:
#18046
ManageIQ/manageiq-ui-classic#4723

Links

https://bugzilla.redhat.com/show_bug.cgi?id=1526000
#18015 this PR is needed for the BZ

@miq-bot miq-bot added the wip label Sep 11, 2018
@lpichler lpichler closed this Sep 12, 2018
@lpichler lpichler reopened this Sep 12, 2018
@lpichler lpichler changed the title [WIP] Create script for mapped tags Conversion script for mapped tags/classification from remote regions to global Oct 3, 2018
@miq-bot miq-bot removed the wip label Oct 3, 2018
@lpichler lpichler changed the title Conversion script for mapped tags/classification from remote regions to global [WIP] Conversion script for mapped tags/classification from remote regions to global Oct 3, 2018
@lpichler lpichler force-pushed the convert_mapped_tags branch 2 times, most recently from 09f81b2 to b31c774 Compare October 3, 2018 14:30
@miq-bot miq-bot added the wip label Oct 3, 2018
@lpichler
Copy link
Contributor Author

lpichler commented Oct 3, 2018

@miq-bot assign @gtanzillo

@lpichler lpichler changed the title [WIP] Conversion script for mapped tags/classification from remote regions to global Conversion script for mapped tags/classification from remote regions to global Oct 3, 2018
@miq-bot miq-bot removed the wip label Oct 3, 2018
#!/usr/bin/env ruby
require File.expand_path('../config/environment', __dir__)

read_only = (ARGV[0] != 'WRITE')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking you can do this with command line options like this

require 'trollop'

opts = Trollop.options(ARGV) do
  banner "USAGE:  #{__FILE__} -c|--commit" \
         "Example (Commit):  #{__FILE__} --commit\n" \
         "Example (Dry Run): #{__FILE__}         \n" \

  opt :commit,  "Commit to database. The default behavior is to do a dry run",                                  :short => "c"
end

read_only = !opts[:commit]


condition_for_mapped_tags = ContainerLabelTagMapping::TAG_PREFIXES.map { "tags.name LIKE ?" }.join(' OR ')
tag_values = ContainerLabelTagMapping::TAG_PREFIXES.map { |x| "#{x}%:%" }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be good to do this in a transaction and roll back if any of the saves fail

@lpichler
Copy link
Contributor Author

lpichler commented Oct 4, 2018

@gtanzillo thanks, I added your suggestions 👍

@miq-bot
Copy link
Member

miq-bot commented Oct 5, 2018

Checked commit lpichler@bb8b99b with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
1 file checked, 1 offense detected

tools/convert_mapped_tags.rb

Copy link
Member

@gtanzillo gtanzillo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍

@gtanzillo gtanzillo added this to the Sprint 97 Ending Oct 22, 2018 milestone Oct 9, 2018
@gtanzillo gtanzillo merged commit 8a9222c into ManageIQ:master Oct 9, 2018
@lpichler lpichler deleted the convert_mapped_tags branch October 9, 2018 16:07
simaishi pushed a commit that referenced this pull request Oct 11, 2018
Conversion script for mapped tags/classification from remote regions to global

(cherry picked from commit 8a9222c)

https://bugzilla.redhat.com/show_bug.cgi?id=1526000
@simaishi
Copy link
Contributor

Hammer backport details:

$ git log -1
commit 8f7ff6aadf503619399148ff400adc37ebfb70b4
Author: Gregg Tanzillo <gtanzill@redhat.com>
Date:   Tue Oct 9 11:19:25 2018 -0400

    Merge pull request #17971 from lpichler/convert_mapped_tags
    
    Conversion script for mapped tags/classification from remote regions to global
    
    (cherry picked from commit 8a9222cd885023f848f6b032151e1f38a69249e3)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1526000

simaishi pushed a commit that referenced this pull request Jan 21, 2019
Conversion script for mapped tags/classification from remote regions to global

(cherry picked from commit 8a9222c)

https://bugzilla.redhat.com/show_bug.cgi?id=1650152
@simaishi
Copy link
Contributor

Gaprindashvili backport details:

$ git log -1
commit b1df4c27a5cb2a4adac14d762ad70c6ac3866499
Author: Gregg Tanzillo <gtanzill@redhat.com>
Date:   Tue Oct 9 11:19:25 2018 -0400

    Merge pull request #17971 from lpichler/convert_mapped_tags
    
    Conversion script for mapped tags/classification from remote regions to global
    
    (cherry picked from commit 8a9222cd885023f848f6b032151e1f38a69249e3)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1650152

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants