hammer_cli_foreman 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of hammer_cli_foreman might be problematic. Click here for more details.

Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -1
  3. data/doc/configuration.md +13 -0
  4. data/lib/hammer_cli_foreman.rb +3 -0
  5. data/lib/hammer_cli_foreman/architecture.rb +9 -9
  6. data/lib/hammer_cli_foreman/associating_commands.rb +57 -34
  7. data/lib/hammer_cli_foreman/commands.rb +188 -101
  8. data/lib/hammer_cli_foreman/common_parameter.rb +7 -10
  9. data/lib/hammer_cli_foreman/compute_resource.rb +8 -11
  10. data/lib/hammer_cli_foreman/domain.rb +14 -40
  11. data/lib/hammer_cli_foreman/environment.rb +10 -15
  12. data/lib/hammer_cli_foreman/exceptions.rb +4 -0
  13. data/lib/hammer_cli_foreman/fact.rb +5 -5
  14. data/lib/hammer_cli_foreman/host.rb +76 -132
  15. data/lib/hammer_cli_foreman/hostgroup.rb +26 -61
  16. data/lib/hammer_cli_foreman/id_resolver.rb +163 -0
  17. data/lib/hammer_cli_foreman/image.rb +14 -50
  18. data/lib/hammer_cli_foreman/location.rb +35 -17
  19. data/lib/hammer_cli_foreman/media.rb +9 -16
  20. data/lib/hammer_cli_foreman/model.rb +6 -8
  21. data/lib/hammer_cli_foreman/operating_system.rb +129 -63
  22. data/lib/hammer_cli_foreman/organization.rb +36 -16
  23. data/lib/hammer_cli_foreman/output/fields.rb +10 -2
  24. data/lib/hammer_cli_foreman/output/formatters.rb +44 -18
  25. data/lib/hammer_cli_foreman/parameter.rb +45 -41
  26. data/lib/hammer_cli_foreman/partition_table.rb +9 -12
  27. data/lib/hammer_cli_foreman/puppet_class.rb +14 -14
  28. data/lib/hammer_cli_foreman/references.rb +122 -0
  29. data/lib/hammer_cli_foreman/report.rb +3 -6
  30. data/lib/hammer_cli_foreman/searchables_option_builder.rb +99 -0
  31. data/lib/hammer_cli_foreman/smart_class_parameter.rb +17 -13
  32. data/lib/hammer_cli_foreman/smart_proxy.rb +18 -28
  33. data/lib/hammer_cli_foreman/subnet.rb +12 -13
  34. data/lib/hammer_cli_foreman/template.rb +10 -19
  35. data/lib/hammer_cli_foreman/user.rb +9 -28
  36. data/lib/hammer_cli_foreman/version.rb +1 -1
  37. data/locale/hammer-cli-foreman.pot +828 -817
  38. data/test/unit/apipie_resource_mock.rb +33 -11
  39. data/test/unit/architecture_test.rb +7 -10
  40. data/test/unit/commands_test.rb +8 -9
  41. data/test/unit/common_parameter_test.rb +6 -8
  42. data/test/unit/compute_resource_test.rb +9 -12
  43. data/test/unit/data/1.5/foreman_api.json +14130 -0
  44. data/test/unit/domain_test.rb +19 -22
  45. data/test/unit/environment_test.rb +9 -11
  46. data/test/unit/fact_test.rb +5 -6
  47. data/test/unit/helpers/command.rb +115 -59
  48. data/test/unit/helpers/fake_searchables.rb +19 -0
  49. data/test/unit/host_test.rb +44 -33
  50. data/test/unit/hostgroup_test.rb +19 -26
  51. data/test/unit/id_resolver_test.rb +225 -0
  52. data/test/unit/image_test.rb +16 -18
  53. data/test/unit/location_test.rb +8 -10
  54. data/test/unit/media_test.rb +11 -13
  55. data/test/unit/model_test.rb +8 -10
  56. data/test/unit/operating_system_test.rb +23 -23
  57. data/test/unit/organization_test.rb +9 -10
  58. data/test/unit/output/formatters_test.rb +133 -20
  59. data/test/unit/partition_table_test.rb +12 -9
  60. data/test/unit/puppet_class_test.rb +3 -7
  61. data/test/unit/report_test.rb +3 -7
  62. data/test/unit/searchables_option_builder_test.rb +172 -0
  63. data/test/unit/smart_class_parameter_test.rb +5 -7
  64. data/test/unit/smart_proxy_test.rb +11 -12
  65. data/test/unit/subnet_test.rb +15 -16
  66. data/test/unit/template_test.rb +15 -12
  67. data/test/unit/test_helper.rb +1 -1
  68. data/test/unit/user_test.rb +9 -12
  69. metadata +536 -509
@@ -14,19 +14,34 @@ module HammerCLIForeman
14
14
  field :name, _("Name")
15
15
  end
16
16
 
17
- apipie_options
17
+ build_options
18
18
  end
19
19
 
20
20
 
21
21
  class InfoCommand < HammerCLIForeman::InfoCommand
22
22
  include HammerCLIForeman::ResourceSupportedTest
23
23
 
24
+ option "--id", "ID", " "
25
+
24
26
  output ListCommand.output_definition do
25
- field :created_at, _("Created at"), Fields::Date
26
- field :updated_at, _("Updated at"), Fields::Date
27
+ HammerCLIForeman::References.users(self)
28
+ HammerCLIForeman::References.smart_proxies(self)
29
+ HammerCLIForeman::References.subnets(self)
30
+ HammerCLIForeman::References.compute_resources(self)
31
+ HammerCLIForeman::References.media(self)
32
+ HammerCLIForeman::References.config_templates(self)
33
+ HammerCLIForeman::References.domains(self)
34
+ HammerCLIForeman::References.environments(self)
35
+ HammerCLIForeman::References.hostgroups(self)
36
+ HammerCLIForeman::References.parameters(self)
37
+ collection :locations, _("Locations"), :numbered => false, :hide_blank => true do
38
+ custom_field Fields::Reference
39
+ end
40
+ HammerCLIForeman::References.timestamps(self)
27
41
  end
28
42
 
29
- apipie_options
43
+
44
+ build_options
30
45
  end
31
46
 
32
47
 
@@ -36,38 +51,43 @@ module HammerCLIForeman
36
51
  success_message _("Organization created")
37
52
  failure_message _("Could not create the organization")
38
53
 
39
- apipie_options
54
+ build_options
40
55
  end
41
56
 
42
57
 
43
58
  class UpdateCommand < HammerCLIForeman::UpdateCommand
44
59
  include HammerCLIForeman::ResourceSupportedTest
45
60
 
61
+ option "--id", "ID", " "
62
+
46
63
  success_message _("Organization updated")
47
64
  failure_message _("Could not update the organization")
48
65
 
49
- apipie_options
66
+ build_options
50
67
  end
51
68
 
52
69
 
53
70
  class DeleteCommand < HammerCLIForeman::DeleteCommand
54
71
  include HammerCLIForeman::ResourceSupportedTest
55
72
 
73
+ option "--id", "ID", " "
74
+
56
75
  success_message _("Organization deleted")
57
76
  failure_message _("Could not delete the organization")
58
77
 
59
- apipie_options
78
+ build_options
60
79
  end
61
80
 
62
- include HammerCLIForeman::AssociatingCommands::Hostgroup
63
- include HammerCLIForeman::AssociatingCommands::Environment
64
- include HammerCLIForeman::AssociatingCommands::Domain
65
- include HammerCLIForeman::AssociatingCommands::Medium
66
- include HammerCLIForeman::AssociatingCommands::Subnet
67
- include HammerCLIForeman::AssociatingCommands::ComputeResource
68
- include HammerCLIForeman::AssociatingCommands::SmartProxy
69
- include HammerCLIForeman::AssociatingCommands::User
70
- include HammerCLIForeman::AssociatingCommands::ConfigTemplate
81
+
82
+ HammerCLIForeman::AssociatingCommands::Hostgroup.extend_command(self)
83
+ HammerCLIForeman::AssociatingCommands::Environment.extend_command(self)
84
+ HammerCLIForeman::AssociatingCommands::Domain.extend_command(self)
85
+ HammerCLIForeman::AssociatingCommands::Medium.extend_command(self)
86
+ HammerCLIForeman::AssociatingCommands::Subnet.extend_command(self)
87
+ HammerCLIForeman::AssociatingCommands::ComputeResource.extend_command(self)
88
+ HammerCLIForeman::AssociatingCommands::SmartProxy.extend_command(self)
89
+ HammerCLIForeman::AssociatingCommands::User.extend_command(self)
90
+ HammerCLIForeman::AssociatingCommands::ConfigTemplate.extend_command(self)
71
91
 
72
92
  autoload_subcommands
73
93
  end
@@ -2,10 +2,18 @@ require 'hammer_cli'
2
2
 
3
3
  module Fields
4
4
 
5
- class OSName < Field
5
+ class SingleReference < Field
6
6
  end
7
7
 
8
- class Server < Field
8
+ class Reference < Field
9
+ end
10
+
11
+ class Template < Reference
12
+
13
+ def initialize(options={})
14
+ options[:details] ||= [:template_kind_name]
15
+ super(options)
16
+ end
9
17
  end
10
18
 
11
19
  end
@@ -1,44 +1,70 @@
1
1
  module HammerCLIForeman::Output
2
2
  module Formatters
3
3
 
4
- class OSNameFormatter < HammerCLI::Output::Formatters::FieldFormatter
4
+ class SingleReferenceFormatter < HammerCLI::Output::Formatters::FieldFormatter
5
5
 
6
6
  def tags
7
7
  [:flat]
8
8
  end
9
9
 
10
- def format(os)
11
- return nil if os.nil?
10
+ def format(resource, field_params={})
11
+ return "" if resource.nil?
12
12
 
13
- name = os['name'] || os[:name]
14
- major = os['major'] || os[:major]
15
- minor = os['minor'] || os[:minor]
13
+ key = field_params[:key]
16
14
 
17
- formatted_name = "%s %s" % [name, major]
18
- formatted_name += ".%s" % minor if (!minor.nil? && !minor.empty?)
19
- formatted_name
15
+ id_key = "#{key}_id"
16
+ name_key = "#{key}_name"
17
+
18
+ name = resource[name_key.to_sym] || resource[name_key]
19
+ id = resource[id_key.to_sym] || resource[id_key]
20
+
21
+ context = field_params[:context] || {}
22
+
23
+ if context[:show_ids]
24
+ "#{name} (id: #{id})" if id && name
25
+ else
26
+ "#{name}" if name
27
+ end
20
28
  end
29
+
21
30
  end
22
31
 
23
- class ServerFormatter < HammerCLI::Output::Formatters::FieldFormatter
32
+ class ReferenceFormatter < HammerCLI::Output::Formatters::FieldFormatter
24
33
 
25
34
  def tags
26
35
  [:flat]
27
36
  end
28
37
 
29
- def format(server)
30
- if server.kind_of? Hash
31
- name = server[:name] || server['name']
32
- url = server[:url] || server['url']
33
- "#{name} (#{url})"
38
+ def format(reference, field_params={})
39
+ return "" if reference.nil?
40
+
41
+ id_key = field_params[:id_key] || :id
42
+ name_key = field_params[:name_key] || :name
43
+
44
+ name = reference[name_key] || reference[name_key.to_s]
45
+ id = reference[id_key] || reference[id_key.to_s]
46
+
47
+ context = field_params[:context] || {}
48
+
49
+ details = field_params[:details] || []
50
+ details = [details] unless details.is_a? Array
51
+ values = details.collect do |key|
52
+ reference[key] || reference[key.to_s]
53
+ end
54
+ values << "id: #{id}" if context[:show_ids]
55
+
56
+ if values.empty?
57
+ "#{name}" if name
34
58
  else
35
- server
59
+ "#{name} (#{values.join(', ')})" if name && !values.empty?
36
60
  end
37
61
  end
62
+
38
63
  end
39
64
 
40
- HammerCLI::Output::Output.register_formatter(OSNameFormatter.new, :OSName)
41
- HammerCLI::Output::Output.register_formatter(ServerFormatter.new, :Server)
65
+ HammerCLI::Output::Output.register_formatter(SingleReferenceFormatter.new, :SingleReference)
66
+ HammerCLI::Output::Output.register_formatter(ReferenceFormatter.new, :Reference)
67
+ HammerCLI::Output::Output.register_formatter(ReferenceFormatter.new, :Template)
42
68
 
43
69
  end
44
70
  end
@@ -4,20 +4,46 @@ module HammerCLIForeman
4
4
 
5
5
  module Parameter
6
6
 
7
- def self.get_parameters(resource_config, resource_type, resource)
8
- params = {
9
- resource_type.to_s+"_id" => resource["id"] || resource["name"]
10
- }
7
+ class AbstractParameterCommand < HammerCLIForeman::Command
11
8
 
12
- params = HammerCLIForeman.foreman_resource(:parameters).call(:index, params)
13
- HammerCLIForeman.collection_to_common_format(params)
14
- end
9
+ def self.parameter_resource
10
+ HammerCLIForeman.foreman_resource(:parameters)
11
+ end
12
+
13
+ def parameter_resource
14
+ self.class.parameter_resource
15
+ end
15
16
 
16
- class SetCommand < HammerCLIForeman::Command
17
+ def get_identifier
18
+ @identifier ||= get_resource_id(resource, :scoped => true)
19
+ @identifier
20
+ end
21
+
22
+ def get_parameter_identifier
23
+ if @parameter_identifier.nil?
24
+ opts = all_options
25
+ opts[HammerCLI.option_accessor_name("#{resource.singular_name}_id")] ||= get_identifier
26
+ @parameter_identifier = resolver.send("#{parameter_resource.singular_name}_id", opts)
27
+ end
28
+ @parameter_identifier
29
+ end
30
+
31
+ def base_action_params
32
+ {
33
+ "#{resource.singular_name}_id" => get_identifier
34
+ }
35
+ end
36
+
37
+ def self.custom_option_builders
38
+ [
39
+ DependentSearchablesOptionBuilder.new(resource, searchables)
40
+ ]
41
+ end
42
+
43
+ end
17
44
 
18
- include HammerCLI::Messages
19
- include HammerCLIForeman::ConnectionSetup
20
45
 
46
+ class SetCommand < AbstractParameterCommand
21
47
  option "--name", "NAME", _("parameter name"), :required => true
22
48
  option "--value", "VALUE", _("parameter value"), :required => true
23
49
 
@@ -25,10 +51,6 @@ module HammerCLIForeman
25
51
  (super(name) || "set-parameter").gsub('_', '-')
26
52
  end
27
53
 
28
- def self.resource(resource=nil)
29
- super(resource) || HammerCLIForeman.foreman_resource(:parameters)
30
- end
31
-
32
54
  def execute
33
55
  if parameter_exist?
34
56
  update_parameter
@@ -40,24 +62,18 @@ module HammerCLIForeman
40
62
  HammerCLI::EX_OK
41
63
  end
42
64
 
43
- def base_action_params
44
- {}
45
- end
46
-
47
65
  def parameter_exist?
48
- params = HammerCLIForeman.collection_to_common_format(resource.call(:index, base_action_params))
49
- params.find { |p| p["name"] == option_name }
66
+ get_parameter_identifier rescue false
50
67
  end
51
68
 
52
69
  def update_parameter
53
70
  params = {
54
- "id" => option_name,
71
+ "id" => get_parameter_identifier,
55
72
  "parameter" => {
56
73
  "value" => option_value
57
74
  }
58
- }.merge base_action_params
59
-
60
- HammerCLIForeman.record_to_common_format(resource.call(:update, params))
75
+ }.merge(base_action_params)
76
+ HammerCLIForeman.record_to_common_format(parameter_resource.call(:update, params))
61
77
  end
62
78
 
63
79
  def create_parameter
@@ -66,43 +82,31 @@ module HammerCLIForeman
66
82
  "name" => option_name,
67
83
  "value" => option_value
68
84
  }
69
- }.merge base_action_params
85
+ }.merge(base_action_params)
70
86
 
71
- HammerCLIForeman.record_to_common_format(resource.call(:create, params))
87
+ HammerCLIForeman.record_to_common_format(parameter_resource.call(:create, params))
72
88
  end
73
89
 
74
90
  end
75
91
 
76
92
 
77
- class DeleteCommand < HammerCLIForeman::Command
78
-
79
- include HammerCLI::Messages
80
- include HammerCLIForeman::ConnectionSetup
81
-
93
+ class DeleteCommand < AbstractParameterCommand
82
94
  option "--name", "NAME", _("parameter name"), :required => true
83
95
 
84
96
  def self.command_name(name=nil)
85
97
  (super(name) || "delete-parameter").gsub('_', '-')
86
98
  end
87
99
 
88
- def self.resource(resource=nil)
89
- super(resource) || HammerCLIForeman.foreman_resource(:parameters)
90
- end
91
-
92
100
  def execute
93
101
  params = {
94
- "id" => option_name
102
+ "id" => get_parameter_identifier
95
103
  }.merge base_action_params
96
104
 
97
- HammerCLIForeman.record_to_common_format(resource.call(:destroy, params))
105
+ HammerCLIForeman.record_to_common_format(parameter_resource.call(:destroy, params))
98
106
  print_message success_message if success_message
99
107
  HammerCLI::EX_OK
100
108
  end
101
109
 
102
- def base_action_params
103
- {}
104
- end
105
-
106
110
  end
107
111
 
108
112
  end
@@ -12,23 +12,21 @@ module HammerCLIForeman
12
12
  field :os_family, _("OS Family")
13
13
  end
14
14
 
15
- apipie_options
15
+ build_options
16
16
  end
17
17
 
18
18
 
19
19
  class InfoCommand < HammerCLIForeman::InfoCommand
20
-
21
20
  output ListCommand.output_definition do
22
- field :created_at, _("Created at"), Fields::Date
23
- field :updated_at, _("Updated at"), Fields::Date
21
+ HammerCLIForeman::References.operating_systems(self)
22
+ HammerCLIForeman::References.timestamps(self)
24
23
  end
25
24
 
26
- apipie_options
25
+ build_options
27
26
  end
28
27
 
29
28
 
30
29
  class DumpCommand < HammerCLIForeman::InfoCommand
31
-
32
30
  command_name "dump"
33
31
  desc _("View partition table content.")
34
32
 
@@ -36,7 +34,7 @@ module HammerCLIForeman
36
34
  puts partition_table["layout"]
37
35
  end
38
36
 
39
- apipie_options
37
+ build_options
40
38
  end
41
39
 
42
40
 
@@ -48,19 +46,18 @@ module HammerCLIForeman
48
46
  success_message _("Partition table created")
49
47
  failure_message _("Could not create the partition table")
50
48
 
51
- apipie_options :without => [:layout] + declared_identifiers.keys
49
+ build_options :without => [:layout]
52
50
  end
53
51
 
54
52
 
55
53
  class UpdateCommand < HammerCLIForeman::UpdateCommand
56
-
57
54
  option "--file", "LAYOUT", _("Path to a file that contains the partition layout"), :attribute_name => :option_layout,
58
55
  :format => HammerCLI::Options::Normalizers::File.new
59
56
 
60
57
  success_message _("Partition table updated")
61
58
  failure_message _("Could not update the partition table")
62
59
 
63
- apipie_options :without => [:layout] + declared_identifiers.keys
60
+ build_options :without => [:layout]
64
61
  end
65
62
 
66
63
 
@@ -68,11 +65,11 @@ module HammerCLIForeman
68
65
  success_message _("Partition table deleted")
69
66
  failure_message _("Could not delete the partition table")
70
67
 
71
- apipie_options
68
+ build_options
72
69
  end
73
70
 
74
71
 
75
- include HammerCLIForeman::AssociatingCommands::OperatingSystem
72
+ HammerCLIForeman::AssociatingCommands::OperatingSystem.extend_command(self)
76
73
 
77
74
 
78
75
  autoload_subcommands
@@ -13,7 +13,7 @@ module HammerCLIForeman
13
13
  field :name, _("Name")
14
14
  end
15
15
 
16
- def retrieve_data
16
+ def send_request
17
17
  self.class.unhash_classes(super)
18
18
  end
19
19
 
@@ -24,31 +24,31 @@ module HammerCLIForeman
24
24
 
25
25
  end
26
26
 
27
- apipie_options
27
+ build_options
28
28
  end
29
29
 
30
30
 
31
31
  class InfoCommand < HammerCLIForeman::InfoCommand
32
-
33
- #FIXME: show environments, hostgroups, variables and parameters
34
32
  output ListCommand.output_definition do
35
- collection :lookup_keys, _("Smart variables") do
36
- from :lookup_key do
37
- field :key, _("Parameter")
38
- field :default_value, _("Default value")
39
- end
33
+ collection :smart_variables, _("Smart variables") do
34
+ field :key, _("Parameter")
35
+ field :default_value, _("Default value")
36
+ end
37
+ collection :smart_class_parameters, _("Smart class parameters"), :numbered => false do
38
+ custom_field Fields::Reference, :name_key => :parameter
40
39
  end
40
+ HammerCLIForeman::References.hostgroups(self)
41
+ HammerCLIForeman::References.environments(self)
42
+ HammerCLIForeman::References.parameters(self)
41
43
  end
42
44
 
43
- apipie_options
45
+ build_options
44
46
  end
45
47
 
46
48
 
47
49
  class SCParamsCommand < HammerCLIForeman::SmartClassParametersBriefList
48
-
49
- apipie_options :without => [:host_id, :hostgroup_id, :puppetclass_id, :environment_id]
50
- option ['--id', '--name'], 'PUPPET_CLASS_ID', _('puppet class id/name'),
51
- :attribute_name => :puppetclass_id, :required => true
50
+ parent_resource :puppetclasses
51
+ build_options
52
52
  end
53
53
 
54
54