hammer_cli_foreman 0.0.4 → 0.0.5

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 (32) hide show
  1. checksums.yaml +7 -0
  2. data/lib/hammer_cli_foreman.rb +8 -1
  3. data/lib/hammer_cli_foreman/architecture.rb +10 -21
  4. data/lib/hammer_cli_foreman/associating_commands.rb +179 -0
  5. data/lib/hammer_cli_foreman/commands.rb +163 -6
  6. data/lib/hammer_cli_foreman/common_parameter.rb +4 -5
  7. data/lib/hammer_cli_foreman/compute_resource.rb +10 -16
  8. data/lib/hammer_cli_foreman/domain.rb +8 -12
  9. data/lib/hammer_cli_foreman/environment.rb +3 -9
  10. data/lib/hammer_cli_foreman/exception_handler.rb +3 -3
  11. data/lib/hammer_cli_foreman/fact.rb +42 -0
  12. data/lib/hammer_cli_foreman/host.rb +84 -18
  13. data/lib/hammer_cli_foreman/hostgroup.rb +30 -13
  14. data/lib/hammer_cli_foreman/location.rb +18 -15
  15. data/lib/hammer_cli_foreman/media.rb +11 -18
  16. data/lib/hammer_cli_foreman/model.rb +66 -0
  17. data/lib/hammer_cli_foreman/operating_system.rb +21 -21
  18. data/lib/hammer_cli_foreman/organization.rb +17 -15
  19. data/lib/hammer_cli_foreman/output.rb +2 -0
  20. data/lib/hammer_cli_foreman/output/fields.rb +11 -0
  21. data/lib/hammer_cli_foreman/output/formatters.rb +23 -0
  22. data/lib/hammer_cli_foreman/parameter.rb +24 -10
  23. data/lib/hammer_cli_foreman/partition_table.rb +13 -17
  24. data/lib/hammer_cli_foreman/puppet_class.rb +55 -0
  25. data/lib/hammer_cli_foreman/report.rb +97 -0
  26. data/lib/hammer_cli_foreman/resource_supported_test.rb +1 -1
  27. data/lib/hammer_cli_foreman/smart_proxy.rb +5 -11
  28. data/lib/hammer_cli_foreman/subnet.rb +5 -11
  29. data/lib/hammer_cli_foreman/template.rb +15 -19
  30. data/lib/hammer_cli_foreman/user.rb +12 -15
  31. data/lib/hammer_cli_foreman/version.rb +1 -1
  32. metadata +25 -29
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 347e1a17bb3de02d953265130d1ee306eb42b9a7
4
+ data.tar.gz: fa67c9be572c2224e7e0f16ea2c2eacad66af3af
5
+ SHA512:
6
+ metadata.gz: 3364fffab86bdb1ac845c4b632cd3a2364c0f3f928cbe98b61298421c540365f24fad21de21dbea0de197b545fac67860f2762ab9d880c1e65a95b5f319f7df1
7
+ data.tar.gz: d89eebb8f3141fcd809f55fa2f7bd73d679fb16f3fbd97d1d0be2c58b8a4bb7482150a281da8cd76a9b8e9acab8aed9f84470c0916e2386429e98a9ba418d3f9
@@ -1,25 +1,32 @@
1
1
  require 'hammer_cli'
2
2
  require 'hammer_cli/exit_codes'
3
3
 
4
+ require 'hammer_cli_foreman/output/fields'
5
+
4
6
  module HammerCLIForeman
5
7
 
6
8
  def self.exception_handler_class
7
9
  HammerCLIForeman::ExceptionHandler
8
10
  end
9
-
11
+
12
+ require 'hammer_cli_foreman/output'
10
13
  require 'hammer_cli_foreman/exception_handler'
11
14
  require 'hammer_cli_foreman/architecture'
12
15
  require 'hammer_cli_foreman/common_parameter'
13
16
  require 'hammer_cli_foreman/compute_resource'
14
17
  require 'hammer_cli_foreman/domain'
15
18
  require 'hammer_cli_foreman/environment'
19
+ require 'hammer_cli_foreman/fact'
16
20
  require 'hammer_cli_foreman/host'
17
21
  require 'hammer_cli_foreman/hostgroup'
18
22
  require 'hammer_cli_foreman/location'
19
23
  require 'hammer_cli_foreman/media'
24
+ require 'hammer_cli_foreman/model'
20
25
  require 'hammer_cli_foreman/operating_system'
21
26
  require 'hammer_cli_foreman/organization'
22
27
  require 'hammer_cli_foreman/partition_table'
28
+ require 'hammer_cli_foreman/report'
29
+ require 'hammer_cli_foreman/puppet_class'
23
30
  require 'hammer_cli_foreman/smart_proxy'
24
31
  require 'hammer_cli_foreman/subnet'
25
32
  require 'hammer_cli_foreman/template'
@@ -1,14 +1,16 @@
1
1
  require 'hammer_cli'
2
2
  require 'foreman_api'
3
3
  require 'hammer_cli_foreman/commands'
4
+ require 'hammer_cli_foreman/associating_commands'
4
5
 
5
6
  module HammerCLIForeman
6
7
 
7
- class Architecture < HammerCLI::AbstractCommand
8
+ class Architecture < HammerCLI::Apipie::Command
9
+
10
+ resource ForemanApi::Resources::Architecture
8
11
 
9
12
  class ListCommand < HammerCLIForeman::ListCommand
10
13
 
11
- heading "Architecture list"
12
14
  output do
13
15
  from "architecture" do
14
16
  field :id, "Id"
@@ -16,60 +18,47 @@ module HammerCLIForeman
16
18
  end
17
19
  end
18
20
 
19
- resource ForemanApi::Resources::Architecture, "index"
20
21
  apipie_options
21
22
  end
22
23
 
23
24
 
24
25
  class InfoCommand < HammerCLIForeman::InfoCommand
25
26
 
26
- heading "Architecture info"
27
27
  output ListCommand.output_definition do
28
28
  from "architecture" do
29
- field :operatingsystem_ids, "OS ids"
30
- field :created_at, "Created at", HammerCLI::Output::Fields::Date
31
- field :updated_at, "Updated at", HammerCLI::Output::Fields::Date
29
+ field :operatingsystem_ids, "OS ids", Fields::List
30
+ field :created_at, "Created at", Fields::Date
31
+ field :updated_at, "Updated at", Fields::Date
32
32
  end
33
33
  end
34
34
 
35
- resource ForemanApi::Resources::Architecture, "show"
36
-
37
35
  end
38
36
 
39
37
 
40
38
  class CreateCommand < HammerCLIForeman::CreateCommand
41
-
42
39
  success_message "Architecture created"
43
40
  failure_message "Could not create the architecture"
44
- resource ForemanApi::Resources::Architecture, "create"
45
41
 
46
42
  apipie_options
47
43
  end
48
44
 
49
45
 
50
46
  class DeleteCommand < HammerCLIForeman::DeleteCommand
51
-
52
47
  success_message "Architecture deleted"
53
48
  failure_message "Could not delete the architecture"
54
- resource ForemanApi::Resources::Architecture, "destroy"
55
-
56
49
  end
57
50
 
58
51
 
59
52
  class UpdateCommand < HammerCLIForeman::UpdateCommand
60
-
61
53
  success_message "Architecture updated"
62
54
  failure_message "Could not update the architecture"
63
- resource ForemanApi::Resources::Architecture, "update"
64
55
 
65
56
  apipie_options
66
57
  end
67
58
 
68
- subcommand "list", "List architectures.", HammerCLIForeman::Architecture::ListCommand
69
- subcommand "info", "Detailed info about an architecture.", HammerCLIForeman::Architecture::InfoCommand
70
- subcommand "create", "Create new architecture.", HammerCLIForeman::Architecture::CreateCommand
71
- subcommand "update", "Update an architecture.", HammerCLIForeman::Architecture::UpdateCommand
72
- subcommand "delete", "Delete an architecture.", HammerCLIForeman::Architecture::DeleteCommand
59
+ include HammerCLIForeman::AssociatingCommands::OperatingSystem
60
+
61
+ autoload_subcommands
73
62
  end
74
63
 
75
64
  end
@@ -0,0 +1,179 @@
1
+ require 'hammer_cli'
2
+ require 'foreman_api'
3
+ require 'hammer_cli_foreman/commands'
4
+
5
+ module HammerCLIForeman
6
+ module AssociatingCommands
7
+
8
+ module Hostgroup
9
+ class AddHostgroupCommand < HammerCLIForeman::AddAssociatedCommand
10
+ associated_resource ForemanApi::Resources::Hostgroup
11
+ end
12
+
13
+ class RemoveHostgroupCommand < HammerCLIForeman::RemoveAssociatedCommand
14
+ associated_resource ForemanApi::Resources::Hostgroup
15
+ end
16
+ end
17
+
18
+ module Environment
19
+ class AddEnvironmentCommand < HammerCLIForeman::AddAssociatedCommand
20
+ associated_resource ForemanApi::Resources::Environment
21
+ end
22
+
23
+ class RemoveEnvironmentCommand < HammerCLIForeman::RemoveAssociatedCommand
24
+ associated_resource ForemanApi::Resources::Environment
25
+ end
26
+ end
27
+
28
+ module Domain
29
+ class AddDomainCommand < HammerCLIForeman::AddAssociatedCommand
30
+ associated_resource ForemanApi::Resources::Domain
31
+ end
32
+
33
+ class RemoveDomainCommand < HammerCLIForeman::RemoveAssociatedCommand
34
+ associated_resource ForemanApi::Resources::Domain
35
+ end
36
+ end
37
+
38
+ module Medium
39
+ class AddMediumCommand < HammerCLIForeman::AddAssociatedCommand
40
+ associated_resource ForemanApi::Resources::Medium
41
+ end
42
+
43
+ class RemoveMediumCommand < HammerCLIForeman::RemoveAssociatedCommand
44
+ associated_resource ForemanApi::Resources::Medium
45
+ end
46
+ end
47
+
48
+ module Subnet
49
+ class AddSubnetCommand < HammerCLIForeman::AddAssociatedCommand
50
+ associated_resource ForemanApi::Resources::Subnet
51
+ end
52
+
53
+ class RemoveSubnetCommand < HammerCLIForeman::RemoveAssociatedCommand
54
+ associated_resource ForemanApi::Resources::Subnet
55
+ end
56
+ end
57
+
58
+ module ComputeResource
59
+ class AddComputeResourceCommand < HammerCLIForeman::AddAssociatedCommand
60
+ associated_resource ForemanApi::Resources::ComputeResource
61
+ end
62
+
63
+ class RemoveComputeResourceCommand < HammerCLIForeman::RemoveAssociatedCommand
64
+ associated_resource ForemanApi::Resources::ComputeResource
65
+ end
66
+ end
67
+
68
+ module SmartProxy
69
+ class AddSmartProxyCommand < HammerCLIForeman::AddAssociatedCommand
70
+ associated_resource ForemanApi::Resources::SmartProxy
71
+
72
+ def associated_resource_name
73
+ "smart_proxy"
74
+ end
75
+ end
76
+
77
+ class RemoveSmartProxyCommand < HammerCLIForeman::RemoveAssociatedCommand
78
+ associated_resource ForemanApi::Resources::SmartProxy
79
+
80
+ def associated_resource_name
81
+ "smart_proxy"
82
+ end
83
+ end
84
+ end
85
+
86
+ module User
87
+ class AddUserCommand < HammerCLIForeman::AddAssociatedCommand
88
+ associated_identifiers :id
89
+
90
+ associated_resource ForemanApi::Resources::User
91
+ end
92
+
93
+ class RemoveUserCommand < HammerCLIForeman::RemoveAssociatedCommand
94
+ associated_identifiers :id
95
+
96
+ associated_resource ForemanApi::Resources::User
97
+ end
98
+ end
99
+
100
+ module ConfigTemplate
101
+ class AddConfigTemplateCommand < HammerCLIForeman::AddAssociatedCommand
102
+ associated_resource ForemanApi::Resources::ConfigTemplate
103
+ end
104
+
105
+ class RemoveConfigTemplateCommand < HammerCLIForeman::RemoveAssociatedCommand
106
+ associated_resource ForemanApi::Resources::ConfigTemplate
107
+ end
108
+ end
109
+
110
+ module Organization
111
+ class AddOrganizationCommand < HammerCLIForeman::AddAssociatedCommand
112
+ associated_resource ForemanApi::Resources::Organization
113
+ end
114
+
115
+ class RemoveOrganizationCommand < HammerCLIForeman::RemoveAssociatedCommand
116
+ associated_resource ForemanApi::Resources::Organization
117
+ end
118
+ end
119
+
120
+ module OperatingSystem
121
+ class AddOSCommand < HammerCLIForeman::AddAssociatedCommand
122
+ associated_resource ForemanApi::Resources::OperatingSystem
123
+
124
+ associated_identifiers :id
125
+
126
+ success_message "Operating system has been associated"
127
+ failure_message "Could not associate the operating system"
128
+ end
129
+
130
+
131
+ class RemoveOSCommand < HammerCLIForeman::RemoveAssociatedCommand
132
+ associated_resource ForemanApi::Resources::OperatingSystem
133
+
134
+ associated_identifiers :id
135
+
136
+ success_message "Operating system has been disassociated"
137
+ failure_message "Could not disassociate the operating system"
138
+ end
139
+ end
140
+
141
+ module Architecture
142
+ class AddArchitectureCommand < HammerCLIForeman::AddAssociatedCommand
143
+ associated_resource ForemanApi::Resources::Architecture
144
+
145
+ success_message "Architecture has been associated"
146
+ failure_message "Could not associate the architecture"
147
+ end
148
+
149
+
150
+ class RemoveArchitectureCommand < HammerCLIForeman::RemoveAssociatedCommand
151
+ associated_resource ForemanApi::Resources::Architecture
152
+
153
+ success_message "Architecture has been disassociated"
154
+ failure_message "Could not disassociate the architecture"
155
+ end
156
+ end
157
+
158
+ module PartitionTable
159
+ class AddPartitionTableCommand < HammerCLIForeman::AddAssociatedCommand
160
+ associated_resource ForemanApi::Resources::Ptable
161
+
162
+ success_message "Partition table has been associated"
163
+ failure_message "Could not associate the partition table"
164
+ end
165
+
166
+
167
+ class RemovePartitionTableCommand < HammerCLIForeman::RemoveAssociatedCommand
168
+ associated_resource ForemanApi::Resources::Ptable
169
+
170
+ success_message "Partition table has been disassociated"
171
+ failure_message "Could not disassociate the partition table"
172
+ end
173
+ end
174
+
175
+
176
+ end
177
+ end
178
+
179
+
@@ -4,10 +4,19 @@ module HammerCLIForeman
4
4
 
5
5
  class ListCommand < HammerCLI::Apipie::ReadCommand
6
6
 
7
+ action :index
8
+
9
+ def self.command_name(name=nil)
10
+ super(name) || "list"
11
+ end
12
+
7
13
  def output
8
- @output ||= HammerCLI::Output::Output.new(
9
- :definition => output_definition,
10
- :adapter => HammerCLI::Output::Adapter::Table.new)
14
+
15
+ @output ||= HammerCLI::Output::Output.new(
16
+ :context => context,
17
+ :definition => output_definition,
18
+ :adapter => HammerCLI::Output::Adapter::Table.new(
19
+ context, HammerCLIForeman::Output::Formatters::DEFAULT_FORMATTERS))
11
20
 
12
21
  end
13
22
 
@@ -16,25 +25,52 @@ module HammerCLIForeman
16
25
 
17
26
  class InfoCommand < HammerCLI::Apipie::ReadCommand
18
27
 
28
+ action :show
29
+
30
+ def self.command_name(name=nil)
31
+ super(name) || "info"
32
+ end
33
+
19
34
  identifiers :id, :name
20
35
 
21
36
  def request_params
22
37
  {'id' => get_identifier[0]}
23
38
  end
24
39
 
25
- def self.apipie_options options={}
40
+ def self.apipie_options(options={})
26
41
  super(options.merge(:without => declared_identifiers.keys))
27
42
  end
43
+
44
+ def output
45
+ @output ||= HammerCLI::Output::Output.new(
46
+ :context => context,
47
+ :definition => output_definition,
48
+ :adapter => HammerCLI::Output::Adapter::Base.new(
49
+ context, HammerCLIForeman::Output::Formatters::DEFAULT_FORMATTERS))
50
+ end
51
+
28
52
  end
29
53
 
30
54
 
31
55
  class CreateCommand < HammerCLI::Apipie::WriteCommand
32
56
 
57
+ action :create
58
+
59
+ def self.command_name(name=nil)
60
+ super(name) || "create"
61
+ end
62
+
33
63
  end
34
64
 
35
65
 
36
66
  class UpdateCommand < HammerCLI::Apipie::WriteCommand
37
67
 
68
+ action :update
69
+
70
+ def self.command_name(name=nil)
71
+ super(name) || "update"
72
+ end
73
+
38
74
  identifiers :id, :name => :current_name
39
75
 
40
76
  def setup_identifier_options
@@ -48,7 +84,7 @@ module HammerCLIForeman
48
84
  params
49
85
  end
50
86
 
51
- def self.apipie_options options={}
87
+ def self.apipie_options(options={})
52
88
  super({:without => declared_identifiers.keys}.merge(options))
53
89
  end
54
90
 
@@ -57,17 +93,138 @@ module HammerCLIForeman
57
93
 
58
94
  class DeleteCommand < HammerCLI::Apipie::WriteCommand
59
95
 
96
+ action :destroy
97
+
98
+ def self.command_name(name=nil)
99
+ super(name) || "delete"
100
+ end
101
+
60
102
  identifiers :id, :name
61
103
 
62
104
  def request_params
63
105
  {'id' => get_identifier[0]}
64
106
  end
65
107
 
66
- def self.apipie_options options={}
108
+ def self.apipie_options(options={})
67
109
  super({:without => declared_identifiers.keys}.merge(options))
68
110
  end
69
111
 
70
112
  end
71
113
 
72
114
 
115
+ class AssociatedCommand < HammerCLI::Apipie::WriteCommand
116
+
117
+ identifiers :name, :id
118
+ action :update
119
+
120
+ def validate_options
121
+ associated_ids = self.class.declared_associated_identifiers.collect {|id_name| "associated_#{id_name}" }
122
+ validator.any(*associated_ids).required
123
+ validator.any(*self.class.declared_identifiers.values).required
124
+ end
125
+
126
+ def initialize(*args)
127
+ setup_associated_identifier_options
128
+ super(*args)
129
+ end
130
+
131
+ def setup_associated_identifier_options
132
+ name = associated_resource.name.to_s
133
+ option_switch = "--"+name.gsub('_', '-')
134
+ self.class.option option_switch, name.upcase, " ", :attribute_name => :associated_name if self.class.declared_associated_identifiers.include? :name
135
+ self.class.option option_switch+"-id", name.upcase+"_ID", " ", :attribute_name => :associated_id if self.class.declared_associated_identifiers.include? :id
136
+ end
137
+
138
+
139
+ def associated_resource
140
+ ResourceInstance.from_definition(self.class.associated_resource, resource_config)
141
+ end
142
+
143
+ def self.associated_resource(resource_class=nil)
144
+ @associated_api_resource = HammerCLI::Apipie::ResourceDefinition.new(resource_class) unless resource_class.nil?
145
+ return @associated_api_resource
146
+ end
147
+
148
+
149
+
150
+ def self.associated_identifiers(*keys)
151
+ @associated_identifiers = keys
152
+ end
153
+
154
+ def self.declared_associated_identifiers
155
+ if @associated_identifiers
156
+ return @associated_identifiers
157
+ elsif superclass.respond_to?(:declared_associated_identifiers, true)
158
+ superclass.declared_associated_identifiers
159
+ else
160
+ []
161
+ end
162
+ end
163
+
164
+ associated_identifiers :name, :id
165
+
166
+ def get_new_ids
167
+ []
168
+ end
169
+
170
+ def get_current_ids
171
+ item = resource.call('show', {'id' => get_identifier[0]})[0]
172
+ item[resource.name][associated_resource.name+'_ids'] || []
173
+ end
174
+
175
+ def get_required_id
176
+ item = associated_resource.call('show', {'id' => associated_id || associated_name})[0]
177
+ item[associated_resource.name]['id']
178
+ end
179
+
180
+ def request_params
181
+ params = method_options
182
+ params[resource.name][associated_resource.name+'_ids'] = get_new_ids
183
+ params['id'] = get_identifier[0]
184
+ params
185
+ end
186
+
187
+ end
188
+
189
+ class AddAssociatedCommand < AssociatedCommand
190
+
191
+ def self.command_name(name=nil)
192
+ super(name) || "add_"+associated_resource.name
193
+ end
194
+
195
+ def self.desc(desc=nil)
196
+ "Associate a resource"
197
+ end
198
+
199
+ def get_new_ids
200
+ ids = get_current_ids
201
+ required_id = get_required_id
202
+
203
+ ids << required_id unless ids.include? required_id
204
+ ids
205
+ end
206
+
207
+ end
208
+
209
+ class RemoveAssociatedCommand < AssociatedCommand
210
+
211
+ def self.command_name(name=nil)
212
+ super(name) || "remove_"+associated_resource.name
213
+ end
214
+
215
+ def self.desc(desc=nil)
216
+ "Disassociate a resource"
217
+ end
218
+
219
+ def get_new_ids
220
+ ids = get_current_ids
221
+ required_id = get_required_id
222
+
223
+ ids = ids.delete_if { |id| id == required_id }
224
+ ids
225
+ end
226
+
227
+ end
228
+
229
+
73
230
  end