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.
- data/lib/hammer_cli_foreman.rb +29 -0
- data/lib/hammer_cli_foreman/architecture.rb +78 -0
- data/lib/hammer_cli_foreman/commands.rb +73 -0
- data/lib/hammer_cli_foreman/common_parameter.rb +80 -0
- data/lib/hammer_cli_foreman/compute_resource.rb +113 -0
- data/lib/hammer_cli_foreman/domain.rb +133 -0
- data/lib/hammer_cli_foreman/environment.rb +76 -0
- data/lib/hammer_cli_foreman/exception_handler.rb +41 -0
- data/lib/hammer_cli_foreman/host.rb +205 -0
- data/lib/hammer_cli_foreman/hostgroup.rb +129 -0
- data/lib/hammer_cli_foreman/location.rb +83 -0
- data/lib/hammer_cli_foreman/media.rb +98 -0
- data/lib/hammer_cli_foreman/operating_system.rb +175 -0
- data/lib/hammer_cli_foreman/organization.rb +83 -0
- data/lib/hammer_cli_foreman/parameter.rb +98 -0
- data/lib/hammer_cli_foreman/partition_table.rb +93 -0
- data/lib/hammer_cli_foreman/resource_supported_test.rb +25 -0
- data/lib/hammer_cli_foreman/smart_proxy.rb +85 -0
- data/lib/hammer_cli_foreman/subnet.rb +90 -0
- data/lib/hammer_cli_foreman/template.rb +164 -0
- data/lib/hammer_cli_foreman/user.rb +96 -0
- data/lib/hammer_cli_foreman/version.rb +5 -0
- metadata +134 -0
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'hammer_cli'
|
2
|
+
require 'foreman_api'
|
3
|
+
require 'hammer_cli_foreman/commands'
|
4
|
+
require 'hammer_cli_foreman/resource_supported_test'
|
5
|
+
|
6
|
+
module HammerCLIForeman
|
7
|
+
|
8
|
+
class Location < HammerCLI::AbstractCommand
|
9
|
+
|
10
|
+
class ListCommand < HammerCLIForeman::ListCommand
|
11
|
+
include HammerCLIForeman::ResourceSupportedTest
|
12
|
+
resource ForemanApi::Resources::Location, "index"
|
13
|
+
|
14
|
+
heading "Locations"
|
15
|
+
output do
|
16
|
+
from "location" do
|
17
|
+
field :id, "Id"
|
18
|
+
field :name, "Name"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
apipie_options
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
class InfoCommand < HammerCLIForeman::InfoCommand
|
27
|
+
include HammerCLIForeman::ResourceSupportedTest
|
28
|
+
resource ForemanApi::Resources::Location, "show"
|
29
|
+
|
30
|
+
heading "Location info"
|
31
|
+
output ListCommand.output_definition do
|
32
|
+
from "location" do
|
33
|
+
field :created_at, "Created at", HammerCLI::Output::Fields::Date
|
34
|
+
field :updated_at, "Updated at", HammerCLI::Output::Fields::Date
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
class CreateCommand < HammerCLIForeman::CreateCommand
|
42
|
+
include HammerCLIForeman::ResourceSupportedTest
|
43
|
+
|
44
|
+
success_message "Location created"
|
45
|
+
failure_message "Could not create the location"
|
46
|
+
resource ForemanApi::Resources::Location, "create"
|
47
|
+
|
48
|
+
apipie_options
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
class UpdateCommand < HammerCLIForeman::UpdateCommand
|
53
|
+
include HammerCLIForeman::ResourceSupportedTest
|
54
|
+
|
55
|
+
success_message "Location updated"
|
56
|
+
failure_message "Could not update the location"
|
57
|
+
resource ForemanApi::Resources::Location, "update"
|
58
|
+
|
59
|
+
apipie_options
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
class DeleteCommand < HammerCLIForeman::DeleteCommand
|
64
|
+
include HammerCLIForeman::ResourceSupportedTest
|
65
|
+
|
66
|
+
success_message "Location deleted"
|
67
|
+
failure_message "Could not delete the location"
|
68
|
+
resource ForemanApi::Resources::Location, "destroy"
|
69
|
+
|
70
|
+
apipie_options
|
71
|
+
end
|
72
|
+
|
73
|
+
subcommand "list", "List locations.", HammerCLIForeman::Location::ListCommand
|
74
|
+
subcommand "info", "Detailed info about an location.", HammerCLIForeman::Location::InfoCommand
|
75
|
+
subcommand "create", "Create new location.", HammerCLIForeman::Location::CreateCommand
|
76
|
+
subcommand "update", "Update an location.", HammerCLIForeman::Location::UpdateCommand
|
77
|
+
subcommand "delete", "Delete an location.", HammerCLIForeman::Location::DeleteCommand
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
HammerCLI::MainCommand.subcommand 'location', "Manipulate Foreman's locations.", HammerCLIForeman::Location
|
83
|
+
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'hammer_cli'
|
2
|
+
require 'foreman_api'
|
3
|
+
require 'hammer_cli_foreman/commands'
|
4
|
+
|
5
|
+
module HammerCLIForeman
|
6
|
+
|
7
|
+
class Medium < HammerCLI::AbstractCommand
|
8
|
+
|
9
|
+
class ListCommand < HammerCLIForeman::ListCommand
|
10
|
+
resource ForemanApi::Resources::Medium, "index"
|
11
|
+
|
12
|
+
heading "Installation Media"
|
13
|
+
output do
|
14
|
+
from "medium" do
|
15
|
+
field :id, "Id"
|
16
|
+
field :name, "Name"
|
17
|
+
field :path, "Path"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
apipie_options
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
class InfoCommand < HammerCLIForeman::InfoCommand
|
26
|
+
resource ForemanApi::Resources::Medium, "show"
|
27
|
+
|
28
|
+
heading "Medium info"
|
29
|
+
output ListCommand.output_definition do
|
30
|
+
from "medium" do
|
31
|
+
field :os_family, "OS Family"
|
32
|
+
field :operatingsystem_ids, "OS IDs"
|
33
|
+
field :created_at, "Created at", HammerCLI::Output::Fields::Date
|
34
|
+
field :updated_at, "Updated at", HammerCLI::Output::Fields::Date
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
class CreateCommand < HammerCLIForeman::CreateCommand
|
42
|
+
|
43
|
+
success_message "Installation medium created"
|
44
|
+
failure_message "Could not create the installation medium"
|
45
|
+
resource ForemanApi::Resources::Medium, "create"
|
46
|
+
|
47
|
+
apipie_options
|
48
|
+
|
49
|
+
#FIXME: remove OS ids option and custom request_params once it's added to foreman's apipie docs
|
50
|
+
option "--operatingsystem-ids", "OSIDS", "os ids", &HammerCLI::OptionFormatters.method(:list)
|
51
|
+
|
52
|
+
def request_params
|
53
|
+
params = super
|
54
|
+
params['medium']['operatingsystem_ids'] = operatingsystem_ids
|
55
|
+
params
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
class UpdateCommand < HammerCLIForeman::UpdateCommand
|
61
|
+
|
62
|
+
success_message "Installation medium updated"
|
63
|
+
failure_message "Could not update the installation media"
|
64
|
+
resource ForemanApi::Resources::Medium, "update"
|
65
|
+
|
66
|
+
apipie_options
|
67
|
+
|
68
|
+
#FIXME: remove OS ids option and custom request_params once it's added to foreman's apipie docs
|
69
|
+
option "--operatingsystem-ids", "OSIDS", "os ids", &HammerCLI::OptionFormatters.method(:list)
|
70
|
+
|
71
|
+
def request_params
|
72
|
+
params = super
|
73
|
+
params['medium']['operatingsystem_ids'] = operatingsystem_ids
|
74
|
+
params
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
class DeleteCommand < HammerCLIForeman::DeleteCommand
|
80
|
+
|
81
|
+
success_message "Installation medium deleted"
|
82
|
+
failure_message "Could not delete the installation media"
|
83
|
+
resource ForemanApi::Resources::Medium, "destroy"
|
84
|
+
|
85
|
+
apipie_options
|
86
|
+
end
|
87
|
+
|
88
|
+
subcommand "list", "List installation media.", HammerCLIForeman::Medium::ListCommand
|
89
|
+
subcommand "info", "Detailed info about an installation medium.", HammerCLIForeman::Medium::InfoCommand
|
90
|
+
subcommand "create", "Create new installation medium.", HammerCLIForeman::Medium::CreateCommand
|
91
|
+
subcommand "update", "Update an installation medium.", HammerCLIForeman::Medium::UpdateCommand
|
92
|
+
subcommand "delete", "Delete an installation medium.", HammerCLIForeman::Medium::DeleteCommand
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
HammerCLI::MainCommand.subcommand 'medium', "Manipulate Foreman's installation media.", HammerCLIForeman::Medium
|
98
|
+
|
@@ -0,0 +1,175 @@
|
|
1
|
+
require 'hammer_cli'
|
2
|
+
require 'foreman_api'
|
3
|
+
require 'hammer_cli_foreman/commands'
|
4
|
+
|
5
|
+
module HammerCLIForeman
|
6
|
+
|
7
|
+
class OperatingSystem < HammerCLI::AbstractCommand
|
8
|
+
|
9
|
+
class ListCommand < HammerCLIForeman::ListCommand
|
10
|
+
resource ForemanApi::Resources::OperatingSystem, "index"
|
11
|
+
|
12
|
+
heading "Operating systems"
|
13
|
+
output do
|
14
|
+
from "operatingsystem" do
|
15
|
+
field :id, "Id"
|
16
|
+
end
|
17
|
+
field :operatingsystem, "Name", HammerCLI::Output::Fields::OSName
|
18
|
+
from "operatingsystem" do
|
19
|
+
field :release_name, "Release name"
|
20
|
+
field :family, "Family"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
apipie_options
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
class InfoCommand < HammerCLIForeman::InfoCommand
|
29
|
+
resource ForemanApi::Resources::OperatingSystem, "show"
|
30
|
+
|
31
|
+
identifiers :id, :label
|
32
|
+
|
33
|
+
heading "Operating system info"
|
34
|
+
output ListCommand.output_definition do
|
35
|
+
from "operatingsystem" do
|
36
|
+
field :media_names, "Installation media", HammerCLI::Output::Fields::List
|
37
|
+
field :architecture_names, "Architectures", HammerCLI::Output::Fields::List
|
38
|
+
field :ptable_names, "Partition tables", HammerCLI::Output::Fields::List
|
39
|
+
field :config_template_names, "Config templates", HammerCLI::Output::Fields::List
|
40
|
+
end
|
41
|
+
collection :parameters, "Parameters" do
|
42
|
+
field :parameter, nil, HammerCLI::Output::Fields::KeyValue
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
#FIXME: remove custom retrieve_data after the api has support for listing names
|
47
|
+
def retrieve_data
|
48
|
+
os = super
|
49
|
+
os["operatingsystem"]["media_names"] = os["operatingsystem"]["media"].collect{|m| m["medium"]["name"] } rescue []
|
50
|
+
os["operatingsystem"]["architecture_names"] = os["operatingsystem"]["architectures"].collect{|m| m["architecture"]["name"] } rescue []
|
51
|
+
os["operatingsystem"]["ptable_names"] = os["operatingsystem"]["ptables"].collect{|m| m["ptable"]["name"] } rescue []
|
52
|
+
os["operatingsystem"]["config_template_names"] = os["operatingsystem"]["config_templates"].collect{|m| m["config_template"]["name"] } rescue []
|
53
|
+
os["parameters"] = HammerCLIForeman::Parameter.get_parameters resource_config, os
|
54
|
+
os
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
class CreateCommand < HammerCLIForeman::CreateCommand
|
61
|
+
|
62
|
+
#FIXME: replace with apipie_options when they are added to the api docs
|
63
|
+
option "--architecture-ids", "ARCH_IDS", "set associated architectures", &HammerCLI::OptionFormatters.method(:list)
|
64
|
+
option "--config-template-ids", "CONFIG_TPL_IDS", "set associated templates", &HammerCLI::OptionFormatters.method(:list)
|
65
|
+
option "--medium-ids", "MEDIUM_IDS", "set associated installation media", &HammerCLI::OptionFormatters.method(:list)
|
66
|
+
option "--ptable-ids", "PTABLE_IDS", "set associated partition tables", &HammerCLI::OptionFormatters.method(:list)
|
67
|
+
|
68
|
+
success_message "Operating system created"
|
69
|
+
failure_message "Could not create the operating system"
|
70
|
+
resource ForemanApi::Resources::OperatingSystem, "create"
|
71
|
+
|
72
|
+
def request_params
|
73
|
+
params = method_options
|
74
|
+
params["operatingsystem"]["architecture_ids"] = architecture_ids if architecture_ids
|
75
|
+
params["operatingsystem"]["config_template_ids"] = config_template_ids if config_template_ids
|
76
|
+
params["operatingsystem"]["medium_ids"] = medium_ids if medium_ids
|
77
|
+
params["operatingsystem"]["ptable_ids"] = ptable_ids if ptable_ids
|
78
|
+
params
|
79
|
+
end
|
80
|
+
|
81
|
+
apipie_options
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
class UpdateCommand < HammerCLIForeman::UpdateCommand
|
86
|
+
|
87
|
+
#FIXME: replace with apipie_options when they are added to the api docs
|
88
|
+
option "--architecture-ids", "ARCH_IDS", "set associated architectures", &HammerCLI::OptionFormatters.method(:list)
|
89
|
+
option "--config-template-ids", "CONFIG_TPL_IDS", "set associated templates", &HammerCLI::OptionFormatters.method(:list)
|
90
|
+
option "--medium-ids", "MEDIUM_IDS", "set associated installation media", &HammerCLI::OptionFormatters.method(:list)
|
91
|
+
option "--ptable-ids", "PTABLE_IDS", "set associated partition tables", &HammerCLI::OptionFormatters.method(:list)
|
92
|
+
|
93
|
+
identifiers :id, :label
|
94
|
+
|
95
|
+
success_message "Operating system updated"
|
96
|
+
failure_message "Could not update the operating system"
|
97
|
+
resource ForemanApi::Resources::OperatingSystem, "update"
|
98
|
+
|
99
|
+
def request_params
|
100
|
+
params = method_options
|
101
|
+
params["operatingsystem"]["architecture_ids"] = architecture_ids if architecture_ids
|
102
|
+
params["operatingsystem"]["config_template_ids"] = config_template_ids if config_template_ids
|
103
|
+
params["operatingsystem"]["medium_ids"] = medium_ids if medium_ids
|
104
|
+
params["operatingsystem"]["ptable_ids"] = ptable_ids if ptable_ids
|
105
|
+
params
|
106
|
+
end
|
107
|
+
|
108
|
+
apipie_options
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
class DeleteCommand < HammerCLIForeman::DeleteCommand
|
113
|
+
|
114
|
+
identifiers :id, :label
|
115
|
+
|
116
|
+
success_message "Operating system deleted"
|
117
|
+
failure_message "Could not delete the operating system"
|
118
|
+
resource ForemanApi::Resources::OperatingSystem, "destroy"
|
119
|
+
|
120
|
+
apipie_options
|
121
|
+
end
|
122
|
+
|
123
|
+
class SetParameterCommand < HammerCLIForeman::Parameter::SetCommand
|
124
|
+
|
125
|
+
#FIXME: add option --os-label when api supports it
|
126
|
+
option "--os-id", "OS_ID", "id of the operating system the parameter is being set for"
|
127
|
+
|
128
|
+
success_message_for :update, "Operating system parameter updated"
|
129
|
+
success_message_for :create, "New operating system parameter created"
|
130
|
+
failure_message "Could not set operating system parameter"
|
131
|
+
|
132
|
+
def validate_options
|
133
|
+
super
|
134
|
+
validator.any(:os_id).required
|
135
|
+
end
|
136
|
+
|
137
|
+
def base_action_params
|
138
|
+
{
|
139
|
+
"operatingsystem_id" => os_id
|
140
|
+
}
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
|
145
|
+
class DeleteParameterCommand < HammerCLIForeman::Parameter::DeleteCommand
|
146
|
+
|
147
|
+
#FIXME: add option --os-label when api supports it
|
148
|
+
option "--os-id", "OS_ID", "id of the operating system the parameter is being deleted for"
|
149
|
+
success_message "operating system parameter deleted"
|
150
|
+
|
151
|
+
def validate_options
|
152
|
+
super
|
153
|
+
validator.any(:os_id).required
|
154
|
+
end
|
155
|
+
|
156
|
+
def base_action_params
|
157
|
+
{
|
158
|
+
"operatingsystem_id" => os_id
|
159
|
+
}
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
subcommand "list", "List operating systems.", HammerCLIForeman::OperatingSystem::ListCommand
|
164
|
+
subcommand "info", "Detailed info about an operating system.", HammerCLIForeman::OperatingSystem::InfoCommand
|
165
|
+
subcommand "create", "Create new operating system.", HammerCLIForeman::OperatingSystem::CreateCommand
|
166
|
+
subcommand "update", "Update an operating system.", HammerCLIForeman::OperatingSystem::UpdateCommand
|
167
|
+
subcommand "delete", "Delete an operating system.", HammerCLIForeman::OperatingSystem::DeleteCommand
|
168
|
+
subcommand "set_parameter", "Create or update parameter for an operating system.", HammerCLIForeman::OperatingSystem::SetParameterCommand
|
169
|
+
subcommand "delete_parameter", "Delete parameter for an operating system.", HammerCLIForeman::OperatingSystem::DeleteParameterCommand
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
173
|
+
|
174
|
+
HammerCLI::MainCommand.subcommand 'os', "Manipulate Foreman's operating system.", HammerCLIForeman::OperatingSystem
|
175
|
+
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'hammer_cli'
|
2
|
+
require 'foreman_api'
|
3
|
+
require 'hammer_cli_foreman/commands'
|
4
|
+
require 'hammer_cli_foreman/resource_supported_test'
|
5
|
+
|
6
|
+
module HammerCLIForeman
|
7
|
+
|
8
|
+
class Organization < HammerCLI::AbstractCommand
|
9
|
+
|
10
|
+
class ListCommand < HammerCLIForeman::ListCommand
|
11
|
+
include HammerCLIForeman::ResourceSupportedTest
|
12
|
+
resource ForemanApi::Resources::Organization, "index"
|
13
|
+
|
14
|
+
heading "Organizations"
|
15
|
+
output do
|
16
|
+
from "organization" do
|
17
|
+
field :id, "Id"
|
18
|
+
field :name, "Name"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
apipie_options
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
class InfoCommand < HammerCLIForeman::InfoCommand
|
27
|
+
include HammerCLIForeman::ResourceSupportedTest
|
28
|
+
resource ForemanApi::Resources::Organization, "show"
|
29
|
+
|
30
|
+
heading "Organization info"
|
31
|
+
output ListCommand.output_definition do
|
32
|
+
from "organization" do
|
33
|
+
field :created_at, "Created at", HammerCLI::Output::Fields::Date
|
34
|
+
field :updated_at, "Updated at", HammerCLI::Output::Fields::Date
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
class CreateCommand < HammerCLIForeman::CreateCommand
|
42
|
+
include HammerCLIForeman::ResourceSupportedTest
|
43
|
+
|
44
|
+
success_message "Organization created"
|
45
|
+
failure_message "Could not create the organization"
|
46
|
+
resource ForemanApi::Resources::Organization, "create"
|
47
|
+
|
48
|
+
apipie_options
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
class UpdateCommand < HammerCLIForeman::UpdateCommand
|
53
|
+
include HammerCLIForeman::ResourceSupportedTest
|
54
|
+
|
55
|
+
success_message "Organization updated"
|
56
|
+
failure_message "Could not update the organization"
|
57
|
+
resource ForemanApi::Resources::Organization, "update"
|
58
|
+
|
59
|
+
apipie_options
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
class DeleteCommand < HammerCLIForeman::DeleteCommand
|
64
|
+
include HammerCLIForeman::ResourceSupportedTest
|
65
|
+
|
66
|
+
success_message "Organization deleted"
|
67
|
+
failure_message "Could not delete the organization"
|
68
|
+
resource ForemanApi::Resources::Organization, "destroy"
|
69
|
+
|
70
|
+
apipie_options
|
71
|
+
end
|
72
|
+
|
73
|
+
subcommand "list", "List organizations.", HammerCLIForeman::Organization::ListCommand
|
74
|
+
subcommand "info", "Detailed info about an organization.", HammerCLIForeman::Organization::InfoCommand
|
75
|
+
subcommand "create", "Create new organization.", HammerCLIForeman::Organization::CreateCommand
|
76
|
+
subcommand "update", "Update an organization.", HammerCLIForeman::Organization::UpdateCommand
|
77
|
+
subcommand "delete", "Delete an organization.", HammerCLIForeman::Organization::DeleteCommand
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
HammerCLI::MainCommand.subcommand 'organization', "Manipulate Foreman's organizations.", HammerCLIForeman::Organization
|
83
|
+
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'hammer_cli'
|
2
|
+
require 'hammer_cli/messages'
|
3
|
+
require 'foreman_api'
|
4
|
+
|
5
|
+
module HammerCLIForeman
|
6
|
+
|
7
|
+
module Parameter
|
8
|
+
|
9
|
+
def self.get_parameters(resource_config, resource)
|
10
|
+
resource_type = resource.keys.first
|
11
|
+
resource = resource[resource_type]
|
12
|
+
params = {
|
13
|
+
resource_type.to_s+"_id" => resource["id"] || resource["name"]
|
14
|
+
}
|
15
|
+
|
16
|
+
ForemanApi::Resources::Parameter.new(resource_config).index(params)[0]
|
17
|
+
end
|
18
|
+
|
19
|
+
class SetCommand < HammerCLI::Apipie::Command
|
20
|
+
|
21
|
+
include HammerCLI::Messages
|
22
|
+
resource ForemanApi::Resources::Parameter
|
23
|
+
|
24
|
+
option "--name", "NAME", "parameter name", :required => true
|
25
|
+
option "--value", "VALUE", "parameter value", :required => true
|
26
|
+
|
27
|
+
def execute
|
28
|
+
if parameter_exist?
|
29
|
+
update_parameter
|
30
|
+
output.print_message success_message_for :update if success_message_for :update
|
31
|
+
else
|
32
|
+
create_parameter
|
33
|
+
output.print_message success_message_for :create if success_message_for :create
|
34
|
+
end
|
35
|
+
0
|
36
|
+
end
|
37
|
+
|
38
|
+
def base_action_params
|
39
|
+
{}
|
40
|
+
end
|
41
|
+
|
42
|
+
def parameter_exist?
|
43
|
+
params = resource.index(base_action_params)[0]
|
44
|
+
params.find { |p| p["parameter"]["name"] == name }
|
45
|
+
end
|
46
|
+
|
47
|
+
def update_parameter
|
48
|
+
params = {
|
49
|
+
"id" => name,
|
50
|
+
"parameter" => {
|
51
|
+
"value" => value
|
52
|
+
}
|
53
|
+
}.merge base_action_params
|
54
|
+
|
55
|
+
resource.update(params)
|
56
|
+
end
|
57
|
+
|
58
|
+
def create_parameter
|
59
|
+
params = {
|
60
|
+
"parameter" => {
|
61
|
+
"name" => name,
|
62
|
+
"value" => value
|
63
|
+
}
|
64
|
+
}.merge base_action_params
|
65
|
+
|
66
|
+
resource.create(params)
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
class DeleteCommand < HammerCLI::Apipie::Command
|
73
|
+
|
74
|
+
include HammerCLI::Messages
|
75
|
+
resource ForemanApi::Resources::Parameter
|
76
|
+
|
77
|
+
option "--name", "NAME", "parameter name", :required => true
|
78
|
+
|
79
|
+
def execute
|
80
|
+
params = {
|
81
|
+
"id" => name
|
82
|
+
}.merge base_action_params
|
83
|
+
|
84
|
+
resource.destroy(params)
|
85
|
+
output.print_message success_message if success_message
|
86
|
+
0
|
87
|
+
end
|
88
|
+
|
89
|
+
def base_action_params
|
90
|
+
{}
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
|