hammer_cli_foreman 0.0.4

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.

@@ -0,0 +1,76 @@
1
+ require 'hammer_cli'
2
+ require 'foreman_api'
3
+
4
+ module HammerCLIForeman
5
+
6
+ class Environment < HammerCLI::AbstractCommand
7
+
8
+ class ListCommand < HammerCLIForeman::ListCommand
9
+ resource ForemanApi::Resources::Environment, "index"
10
+
11
+ heading "Environments"
12
+ output do
13
+ from "environment" do
14
+ field :id, "Id"
15
+ field :name, "Name"
16
+ end
17
+ end
18
+
19
+ apipie_options
20
+ end
21
+
22
+
23
+ class InfoCommand < HammerCLIForeman::InfoCommand
24
+ resource ForemanApi::Resources::Environment, "show"
25
+
26
+ heading "Environment info"
27
+ output ListCommand.output_definition do
28
+ from "environment" do
29
+ field :created_at, "Created at", HammerCLI::Output::Fields::Date
30
+ field :updated_at, "Updated at", HammerCLI::Output::Fields::Date
31
+ end
32
+ end
33
+
34
+ end
35
+
36
+
37
+ class CreateCommand < HammerCLIForeman::CreateCommand
38
+
39
+ success_message "Environment created"
40
+ failure_message "Could not create the environment"
41
+ resource ForemanApi::Resources::Environment, "create"
42
+
43
+ apipie_options
44
+ end
45
+
46
+
47
+ class UpdateCommand < HammerCLIForeman::UpdateCommand
48
+
49
+ success_message "Environment updated"
50
+ failure_message "Could not update the environment"
51
+ resource ForemanApi::Resources::Environment, "update"
52
+
53
+ apipie_options
54
+ end
55
+
56
+
57
+ class DeleteCommand < HammerCLIForeman::DeleteCommand
58
+
59
+ success_message "Environment deleted"
60
+ failure_message "Could not delete the environment"
61
+ resource ForemanApi::Resources::Environment, "destroy"
62
+
63
+ apipie_options
64
+ end
65
+
66
+ subcommand "list", "List environments.", HammerCLIForeman::Environment::ListCommand
67
+ subcommand "info", "Detailed info about an environment.", HammerCLIForeman::Environment::InfoCommand
68
+ subcommand "create", "Create new environment.", HammerCLIForeman::Environment::CreateCommand
69
+ subcommand "update", "Update an environment.", HammerCLIForeman::Environment::UpdateCommand
70
+ subcommand "delete", "Delete an environment.", HammerCLIForeman::Environment::DeleteCommand
71
+ end
72
+
73
+ end
74
+
75
+ HammerCLI::MainCommand.subcommand 'environment', "Manipulate Foreman's environments.", HammerCLIForeman::Environment
76
+
@@ -0,0 +1,41 @@
1
+ require 'hammer_cli/exception_handler'
2
+
3
+ module HammerCLIForeman
4
+ class ExceptionHandler < HammerCLI::ExceptionHandler
5
+
6
+ def mappings
7
+ super + [
8
+ [RestClient::Forbidden, :handle_forbidden],
9
+ [RestClient::UnprocessableEntity, :handle_unprocessable_entity],
10
+ [ArgumentError, :handle_argument_error]
11
+ ]
12
+ end
13
+
14
+ protected
15
+
16
+ def handle_unprocessable_entity e
17
+ response = JSON.parse(e.response)
18
+ response = response[response.keys[0]]
19
+
20
+ print_error response["full_messages"]
21
+ HammerCLI::EX_DATAERR
22
+ end
23
+
24
+
25
+ def handle_argument_error e
26
+ print_error e.message
27
+ log_full_error e
28
+ HammerCLI::EX_USAGE
29
+ end
30
+
31
+ def handle_forbidden e
32
+ print_error "Forbidden - server refused to process the request"
33
+ log_full_error e
34
+ HammerCLI::EX_NOPERM
35
+ end
36
+
37
+ end
38
+ end
39
+
40
+
41
+
@@ -0,0 +1,205 @@
1
+ require 'hammer_cli'
2
+ require 'foreman_api'
3
+ require 'hammer_cli_foreman/commands'
4
+ require 'hammer_cli_foreman/parameter'
5
+
6
+ module HammerCLIForeman
7
+
8
+ class Host < HammerCLI::AbstractCommand
9
+ class ListCommand < HammerCLIForeman::ListCommand
10
+ resource ForemanApi::Resources::Host, "index"
11
+
12
+ heading "Host list"
13
+ output do
14
+ from "host" do
15
+ field :id, "Id"
16
+ field :name, "Name"
17
+ field :operatingsystem_id, "Operating System Id"
18
+ field :hostgroup_id, "Host Group Id"
19
+ field :ip, "IP"
20
+ field :mac, "MAC"
21
+ end
22
+ end
23
+
24
+ apipie_options
25
+ end
26
+
27
+
28
+ class InfoCommand < HammerCLIForeman::InfoCommand
29
+
30
+ resource ForemanApi::Resources::Host, "show"
31
+
32
+ def retrieve_data
33
+ host = super
34
+ host["host"]["environment_name"] = host["host"]["environment"]["environment"]["name"] rescue nil
35
+ host["parameters"] = HammerCLIForeman::Parameter.get_parameters resource_config, host
36
+ host
37
+ end
38
+
39
+ heading "Host info"
40
+ output ListCommand.output_definition do
41
+ from "host" do
42
+ field :uuid, "UUID"
43
+ field :certname, "Cert name"
44
+
45
+ field :environment_name, "Environment"
46
+ field :environment_id, "Environment Id"
47
+
48
+ field :managed, "Managed"
49
+ field :enabled, "Enabled"
50
+ field :build, "Build"
51
+
52
+ field :use_image, "Use image"
53
+ field :disk, "Disk"
54
+ field :image_file, "Image file"
55
+
56
+ field :sp_name, "SP Name"
57
+ field :sp_ip, "SP IP"
58
+ field :sp_mac, "SP MAC"
59
+ field :sp_subnet, "SP Subnet"
60
+ field :sp_subnet_id, "SP Subnet Id"
61
+
62
+ field :created_at, "Created at", HammerCLI::Output::Fields::Date
63
+ field :updated_at, "Updated at", HammerCLI::Output::Fields::Date
64
+ field :installed_at, "Installed at", HammerCLI::Output::Fields::Date
65
+ field :last_report, "Last report", HammerCLI::Output::Fields::Date
66
+
67
+ field :puppet_ca_proxy_id, "Puppet CA Proxy Id"
68
+ field :medium_id, "Medium Id"
69
+ field :model_id, "Model Id"
70
+ field :owner_id, "Owner Id"
71
+ field :subnet_id, "Subnet Id"
72
+ field :domain_id, "Domain Id"
73
+ field :puppet_proxy_id, "Puppet Proxy Id"
74
+ field :owner_type, "Owner Type"
75
+ field :ptable_id, "Partition Table Id"
76
+ field :architecture_id, "Architecture Id"
77
+ field :image_id, "Image Id"
78
+ field :compute_resource_id, "Compute Resource Id"
79
+
80
+ field :comment, "Comment"
81
+ end
82
+ collection :parameters, "Parameters" do
83
+ field :parameter, nil, HammerCLI::Output::Fields::KeyValue
84
+ end
85
+ end
86
+ end
87
+
88
+
89
+ class StatusCommand < HammerCLIForeman::InfoCommand
90
+
91
+ resource ForemanApi::Resources::Host, "status"
92
+
93
+ def print_data(records)
94
+ output.print_message records["status"]
95
+ end
96
+ end
97
+
98
+
99
+ class PuppetRunCommand < HammerCLIForeman::InfoCommand
100
+
101
+ resource ForemanApi::Resources::Host, "puppetrun"
102
+
103
+ def print_data(records)
104
+ output.print_message 'Puppet run triggered'
105
+ end
106
+ end
107
+
108
+
109
+ class CreateCommand < HammerCLIForeman::CreateCommand
110
+
111
+ success_message "Host created"
112
+ failure_message "Could not create the host"
113
+ resource ForemanApi::Resources::Host, "create"
114
+
115
+ apipie_options :without => ['host_parameters_attributes']
116
+
117
+ #FIXME with following setup it is possible to create hosts with the default network setup
118
+ # needs create redesign
119
+ def request_params
120
+ params = super
121
+ params['host']['compute_attributes']["nics_attributes"] = {
122
+ "new_nics"=>{"type"=>"bridge", "_delete"=>"", "bridge"=>""},
123
+ "0"=>{"type"=>"network", "_delete"=>"", "network"=>"default", "bridge"=>""}
124
+ }
125
+ params
126
+ end
127
+ end
128
+
129
+
130
+ class UpdateCommand < HammerCLIForeman::UpdateCommand
131
+
132
+ success_message "Host updated"
133
+ failure_message "Could not update the host"
134
+ resource ForemanApi::Resources::Host, "update"
135
+
136
+ apipie_options :without => ['host_parameters_attributes', 'name', 'id']
137
+ end
138
+
139
+
140
+ class DeleteCommand < HammerCLIForeman::DeleteCommand
141
+
142
+ success_message "Host deleted"
143
+ failure_message "Could not delete the host"
144
+ resource ForemanApi::Resources::Host, "destroy"
145
+
146
+ apipie_options
147
+ end
148
+
149
+
150
+ class SetParameterCommand < HammerCLIForeman::Parameter::SetCommand
151
+
152
+ option "--host-name", "HOST_NAME", "name of the host the parameter is being set for"
153
+ option "--host-id", "HOST_ID", "id of the host the parameter is being set for"
154
+
155
+ success_message_for :update, "Host parameter updated"
156
+ success_message_for :create, "New host parameter created"
157
+ failure_message "Could not set host parameter"
158
+
159
+ def validate_options
160
+ super
161
+ validator.any(:host_name, :host_id).required
162
+ end
163
+
164
+ def base_action_params
165
+ {
166
+ "host_id" => host_id || host_name
167
+ }
168
+ end
169
+ end
170
+
171
+
172
+ class DeleteParameterCommand < HammerCLIForeman::Parameter::DeleteCommand
173
+
174
+ option "--host-name", "HOST_NAME", "name of the host the parameter is being deleted for"
175
+ option "--host-id", "HOST_ID", "id of the host the parameter is being deleted for"
176
+
177
+ success_message "Host parameter deleted"
178
+
179
+ def validate_options
180
+ super
181
+ validator.any(:host_name, :host_id).required
182
+ end
183
+
184
+ def base_action_params
185
+ {
186
+ "host_id" => host_id || host_name
187
+ }
188
+ end
189
+ end
190
+
191
+ subcommand "list", "List hosts.", HammerCLIForeman::Host::ListCommand
192
+ subcommand "info", "Detailed info about host.", HammerCLIForeman::Host::InfoCommand
193
+ subcommand "status", "Print host status.", HammerCLIForeman::Host::StatusCommand
194
+ subcommand "puppetrun", "Force puppet run on the agent.", HammerCLIForeman::Host::PuppetRunCommand
195
+ subcommand "create", "Create a new host.", HammerCLIForeman::Host::CreateCommand
196
+ subcommand "update", "Update a host.", HammerCLIForeman::Host::UpdateCommand
197
+ subcommand "delete", "Delete a host.", HammerCLIForeman::Host::DeleteCommand
198
+ subcommand "set_parameter", "Create or update parameter for a host.", HammerCLIForeman::Host::SetParameterCommand
199
+ subcommand "delete_parameter", "Delete parameter for a host.", HammerCLIForeman::Host::DeleteParameterCommand
200
+ end
201
+
202
+ end
203
+
204
+ HammerCLI::MainCommand.subcommand 'host', "Manipulate Foreman's hosts.", HammerCLIForeman::Host
205
+
@@ -0,0 +1,129 @@
1
+ require 'hammer_cli'
2
+ require 'foreman_api'
3
+ require 'hammer_cli_foreman/commands'
4
+ require 'hammer_cli_foreman/parameter'
5
+
6
+ module HammerCLIForeman
7
+
8
+ class Hostgroup < HammerCLI::AbstractCommand
9
+ class ListCommand < HammerCLIForeman::ListCommand
10
+ resource ForemanApi::Resources::Hostgroup, "index"
11
+
12
+ heading "Hostgroup list"
13
+ output do
14
+ from "hostgroup" do
15
+ field :id, "Id"
16
+ field :name, "Name"
17
+ field :label, "Label"
18
+ field :operatingsystem_id, "Operating System Id"
19
+ field :subnet_id, "Subnet Id"
20
+ field :domain_id, "Domain Id"
21
+ field :environment_id, "Environment Id"
22
+ field :puppetclass_ids, "Puppetclass Ids", HammerCLI::Output::Fields::List
23
+ field :ancestry, "Ancestry"
24
+ end
25
+ end
26
+
27
+ apipie_options
28
+ end
29
+
30
+
31
+ class InfoCommand < HammerCLIForeman::InfoCommand
32
+ resource ForemanApi::Resources::Hostgroup, "show"
33
+
34
+ identifiers :id
35
+
36
+ heading "Hostgroup info"
37
+ output ListCommand.output_definition do
38
+ collection :parameters, "Parameters" do
39
+ field :parameter, nil, HammerCLI::Output::Fields::KeyValue
40
+ end
41
+ end
42
+
43
+ def retrieve_data
44
+ hostgroup = super
45
+ hostgroup["parameters"] = HammerCLIForeman::Parameter.get_parameters resource_config, hostgroup
46
+ hostgroup
47
+ end
48
+
49
+ end
50
+
51
+
52
+ class CreateCommand < HammerCLIForeman::CreateCommand
53
+
54
+ success_message "Hostgroup created"
55
+ failure_message "Could not create the hostgroup"
56
+ resource ForemanApi::Resources::Hostgroup, "create"
57
+
58
+ apipie_options
59
+ end
60
+
61
+
62
+ class UpdateCommand < HammerCLIForeman::UpdateCommand
63
+
64
+ identifiers :id
65
+
66
+ success_message "Hostgroup updated"
67
+ failure_message "Could not update the hostgroup"
68
+ resource ForemanApi::Resources::Hostgroup, "update"
69
+
70
+ apipie_options
71
+ end
72
+
73
+
74
+ class DeleteCommand < HammerCLIForeman::DeleteCommand
75
+
76
+ identifiers :id
77
+
78
+ success_message "Hostgroup deleted"
79
+ failure_message "Could not delete the hostgroup"
80
+ resource ForemanApi::Resources::Hostgroup, "destroy"
81
+
82
+ apipie_options
83
+ end
84
+
85
+
86
+ class SetParameterCommand < HammerCLIForeman::Parameter::SetCommand
87
+
88
+ option "--hostgroup-id", "HOSTGROUP_ID", "id of the hostgroup the parameter is being set for", :required => true
89
+
90
+ success_message_for :update, "Hostgroup parameter updated"
91
+ success_message_for :create, "New hostgroup parameter created"
92
+ failure_message "Could not set hostgroup parameter"
93
+
94
+ def base_action_params
95
+ {
96
+ "hostgroup_id" => hostgroup_id
97
+ }
98
+ end
99
+ end
100
+
101
+
102
+ class DeleteParameterCommand < HammerCLIForeman::Parameter::DeleteCommand
103
+
104
+ option "--hostgroup-id", "HOSTGROUP_ID", "id of the hostgroup the parameter is being deleted for", :required => true
105
+
106
+ success_message "Hostgroup parameter deleted"
107
+
108
+ def base_action_params
109
+ {
110
+ "hostgroup_id" => hostgroup_id
111
+ }
112
+ end
113
+ end
114
+
115
+
116
+ subcommand "list", "List hostgroups.", HammerCLIForeman::Hostgroup::ListCommand
117
+ subcommand "info", "Detailed info about hostgroup.", HammerCLIForeman::Hostgroup::InfoCommand
118
+ subcommand "create", "Create a new hostgroup.", HammerCLIForeman::Hostgroup::CreateCommand
119
+ subcommand "update", "Update a hostgroup.", HammerCLIForeman::Hostgroup::UpdateCommand
120
+ subcommand "delete", "Delete a hostgroup.", HammerCLIForeman::Hostgroup::DeleteCommand
121
+ subcommand "set_parameter", "Create or update parameter for a hostgroup.", HammerCLIForeman::Hostgroup::SetParameterCommand
122
+ subcommand "delete_parameter", "Delete parameter for a hostgroup.", HammerCLIForeman::Hostgroup::DeleteParameterCommand
123
+
124
+ end
125
+
126
+ end
127
+
128
+ HammerCLI::MainCommand.subcommand 'hostgroup', "Manipulate Foreman's hostgroups.", HammerCLIForeman::Hostgroup
129
+