Class: HammerCLIKatello::IdResolver

Inherits:
HammerCLIForeman::IdResolver
  • Object
show all
Includes:
SearchOptionsCreators
Defined in:
lib/hammer_cli_katello/id_resolver.rb

Instance Method Summary collapse

Methods included from SearchOptionsCreators

#create_content_view_filter_rules_search_options, #create_content_view_versions_search_options, #create_content_views_search_options, #create_file_units_search_options, #create_host_collections_search_options, #create_lifecycle_environments_search_options, #create_module_streams_search_options, #create_repositories_search_options, #create_repository_sets_search_options, #create_search_options_with_katello_api

Methods included from ForemanSearchOptionsCreators

#create_architectures_search_options, #create_capsules_search_options, #create_compute_profiles_search_options, #create_compute_resources_search_options, #create_debs_search_options, #create_domains_search_options, #create_environments_search_options, #create_hostgroups_search_options, #create_hosts_search_options, #create_http_proxies_search_options, #create_images_search_options, #create_locations_search_options, #create_media_search_options, #create_operatingsystems_search_options, #create_organizations_search_options, #create_packages_search_options, #create_ptables_search_options, #create_realms_search_options, #create_smart_proxies_search_options, #create_subnets_search_options, #create_usergroups_search_options, #create_users_search_options

Instance Method Details

#capsule_content_id(options) ⇒ Object



61
62
63
# File 'lib/hammer_cli_katello/id_resolver.rb', line 61

def capsule_content_id(options)
  smart_proxy_id(options)
end

#content_view_version_id(options) ⇒ Object

rubocop:disable Style/EmptyElse rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/hammer_cli_katello/id_resolver.rb', line 125

def content_view_version_id(options)
  key_id = HammerCLI.option_accessor_name("id")
  key_content_view_id = HammerCLI.option_accessor_name("content_view_id")
  from_environment_id = HammerCLI.option_accessor_name("from_environment_id")

  return options[key_id] if options[key_id]

  options[key_content_view_id] ||= search_and_rescue(:content_view_id, "content_view", options)

  if options[key_content_view_id] && options['option_environment_name'] &&
     options['option_environment_id'].nil?
    lifecycle_environment_resource_name = (HammerCLIForeman.param_to_resource('environment') ||
     HammerCLIForeman.param_to_resource('lifecycle_environment')).singular_name
    options['option_environment_id'] = lifecycle_environment_id(
      scoped_options(lifecycle_environment_resource_name, options, :single))
  end

  results = find_resources(:content_view_versions, options)

  options[from_environment_id] ||= from_lifecycle_environment_id(options)

  return pick_result(results, @api.resource(:content_view_versions))['id'] if results.size == 1

  if results.size > 1 && options[from_environment_id]
    results_in_from_environment = results.select do |version|
      member_of_environment_ids = version['environments'].map { |env| env['id'].to_s }
      member_of_environment_ids.include? options[from_environment_id].to_s
    end
    results_in_from_environment
      .sort { |a, b| a['version'].to_f <=> b['version'].to_f }.last['id']
  else
    nil
  end
end

#environment_id(options) ⇒ Object



65
66
67
# File 'lib/hammer_cli_katello/id_resolver.rb', line 65

def environment_id(options)
  lifecycle_environment_id(options)
end

#environment_ids(options) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/hammer_cli_katello/id_resolver.rb', line 73

def environment_ids(options)
  unless options['option_lifecycle_environment_ids'].nil?
    return options['option_lifecycle_environment_ids']
  end

  names = options[HammerCLI.option_accessor_name('lifecycle_environment_names')] ||
          options[HammerCLI.option_accessor_name('environment_names')] ||
          options[HammerCLI.option_accessor_name('names')]
  key_organization_id = HammerCLI.option_accessor_name 'organization_id'
  options[key_organization_id] ||= organization_id(scoped_options('organization', options))

  options['option_lifecycle_environment_names'] = names
  find_resources(:lifecycle_environments, options)
    .select { |repo| names.include? repo['name'] }.map { |repo| repo['id'] }
end

#file_unit_id(options) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/hammer_cli_katello/id_resolver.rb', line 53

def file_unit_id(options)
  if options['option_content_view_version_version']
    options['option_content_view_version_id'] ||=
      content_view_version_id(scoped_options('content_view_version', options))
  end
  get_id(:file_units, options)
end

#lifecycle_environment_ids(options) ⇒ Object



69
70
71
# File 'lib/hammer_cli_katello/id_resolver.rb', line 69

def lifecycle_environment_ids(options)
  environment_ids(options)
end

#repository_id(options) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/hammer_cli_katello/id_resolver.rb', line 89

def repository_id(options)
  key_id = HammerCLI.option_accessor_name("id")
  key_product_id = HammerCLI.option_accessor_name("product_id")
  key_product_name = HammerCLI.option_accessor_name("product_name")

  return options[key_id] if options[key_id]

  unless options[key_product_name].nil?
    options[key_product_id] ||= product_id(scoped_options("product", options))
  end

  find_resource(:repositories, options)['id']
end

#repository_ids(options) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/hammer_cli_katello/id_resolver.rb', line 103

def repository_ids(options)
  return options['option_repository_ids'] unless options['option_repository_ids'].nil?

  key_names = HammerCLI.option_accessor_name 'names'
  key_product_id = HammerCLI.option_accessor_name 'product_id'

  options[key_names] ||= []

  unless options['option_product_name'].nil?
    options[key_product_id] ||= product_id(scoped_options('product', options))
  end

  if options[key_names].any?
    find_resources(:repositories, options)
      .select { |repo| options[key_names].include? repo['name'] }.map { |repo| repo['id'] }
  end
end