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,29 @@
|
|
1
|
+
require 'hammer_cli'
|
2
|
+
require 'hammer_cli/exit_codes'
|
3
|
+
|
4
|
+
module HammerCLIForeman
|
5
|
+
|
6
|
+
def self.exception_handler_class
|
7
|
+
HammerCLIForeman::ExceptionHandler
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'hammer_cli_foreman/exception_handler'
|
11
|
+
require 'hammer_cli_foreman/architecture'
|
12
|
+
require 'hammer_cli_foreman/common_parameter'
|
13
|
+
require 'hammer_cli_foreman/compute_resource'
|
14
|
+
require 'hammer_cli_foreman/domain'
|
15
|
+
require 'hammer_cli_foreman/environment'
|
16
|
+
require 'hammer_cli_foreman/host'
|
17
|
+
require 'hammer_cli_foreman/hostgroup'
|
18
|
+
require 'hammer_cli_foreman/location'
|
19
|
+
require 'hammer_cli_foreman/media'
|
20
|
+
require 'hammer_cli_foreman/operating_system'
|
21
|
+
require 'hammer_cli_foreman/organization'
|
22
|
+
require 'hammer_cli_foreman/partition_table'
|
23
|
+
require 'hammer_cli_foreman/smart_proxy'
|
24
|
+
require 'hammer_cli_foreman/subnet'
|
25
|
+
require 'hammer_cli_foreman/template'
|
26
|
+
require 'hammer_cli_foreman/user'
|
27
|
+
|
28
|
+
end
|
29
|
+
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'hammer_cli'
|
2
|
+
require 'foreman_api'
|
3
|
+
require 'hammer_cli_foreman/commands'
|
4
|
+
|
5
|
+
module HammerCLIForeman
|
6
|
+
|
7
|
+
class Architecture < HammerCLI::AbstractCommand
|
8
|
+
|
9
|
+
class ListCommand < HammerCLIForeman::ListCommand
|
10
|
+
|
11
|
+
heading "Architecture list"
|
12
|
+
output do
|
13
|
+
from "architecture" do
|
14
|
+
field :id, "Id"
|
15
|
+
field :name, "Name"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
resource ForemanApi::Resources::Architecture, "index"
|
20
|
+
apipie_options
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
class InfoCommand < HammerCLIForeman::InfoCommand
|
25
|
+
|
26
|
+
heading "Architecture info"
|
27
|
+
output ListCommand.output_definition do
|
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
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
resource ForemanApi::Resources::Architecture, "show"
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
class CreateCommand < HammerCLIForeman::CreateCommand
|
41
|
+
|
42
|
+
success_message "Architecture created"
|
43
|
+
failure_message "Could not create the architecture"
|
44
|
+
resource ForemanApi::Resources::Architecture, "create"
|
45
|
+
|
46
|
+
apipie_options
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
class DeleteCommand < HammerCLIForeman::DeleteCommand
|
51
|
+
|
52
|
+
success_message "Architecture deleted"
|
53
|
+
failure_message "Could not delete the architecture"
|
54
|
+
resource ForemanApi::Resources::Architecture, "destroy"
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
class UpdateCommand < HammerCLIForeman::UpdateCommand
|
60
|
+
|
61
|
+
success_message "Architecture updated"
|
62
|
+
failure_message "Could not update the architecture"
|
63
|
+
resource ForemanApi::Resources::Architecture, "update"
|
64
|
+
|
65
|
+
apipie_options
|
66
|
+
end
|
67
|
+
|
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
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
HammerCLI::MainCommand.subcommand 'architecture', "Manipulate Foreman's architectures.", HammerCLIForeman::Architecture
|
78
|
+
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'hammer_cli'
|
2
|
+
|
3
|
+
module HammerCLIForeman
|
4
|
+
|
5
|
+
class ListCommand < HammerCLI::Apipie::ReadCommand
|
6
|
+
|
7
|
+
def output
|
8
|
+
@output ||= HammerCLI::Output::Output.new(
|
9
|
+
:definition => output_definition,
|
10
|
+
:adapter => HammerCLI::Output::Adapter::Table.new)
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
class InfoCommand < HammerCLI::Apipie::ReadCommand
|
18
|
+
|
19
|
+
identifiers :id, :name
|
20
|
+
|
21
|
+
def request_params
|
22
|
+
{'id' => get_identifier[0]}
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.apipie_options options={}
|
26
|
+
super(options.merge(:without => declared_identifiers.keys))
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
class CreateCommand < HammerCLI::Apipie::WriteCommand
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
class UpdateCommand < HammerCLI::Apipie::WriteCommand
|
37
|
+
|
38
|
+
identifiers :id, :name => :current_name
|
39
|
+
|
40
|
+
def setup_identifier_options
|
41
|
+
super
|
42
|
+
self.class.option "--new-name", "NEW_NAME", "new name for the resource", :attribute_name => :name if self.class.identifier? :name
|
43
|
+
end
|
44
|
+
|
45
|
+
def request_params
|
46
|
+
params = method_options
|
47
|
+
params['id'] = get_identifier[0]
|
48
|
+
params
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.apipie_options options={}
|
52
|
+
super({:without => declared_identifiers.keys}.merge(options))
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
class DeleteCommand < HammerCLI::Apipie::WriteCommand
|
59
|
+
|
60
|
+
identifiers :id, :name
|
61
|
+
|
62
|
+
def request_params
|
63
|
+
{'id' => get_identifier[0]}
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.apipie_options options={}
|
67
|
+
super({:without => declared_identifiers.keys}.merge(options))
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'hammer_cli'
|
2
|
+
require 'foreman_api'
|
3
|
+
|
4
|
+
module HammerCLIForeman
|
5
|
+
|
6
|
+
class CommonParameter < HammerCLI::AbstractCommand
|
7
|
+
|
8
|
+
|
9
|
+
class ListCommand < HammerCLIForeman::ListCommand
|
10
|
+
resource ForemanApi::Resources::CommonParameter, "index"
|
11
|
+
|
12
|
+
heading "Global parameter list"
|
13
|
+
output do
|
14
|
+
from "common_parameter" do
|
15
|
+
field :name, "Name"
|
16
|
+
field :value, "Value"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
apipie_options
|
21
|
+
end
|
22
|
+
|
23
|
+
class SetCommand < HammerCLI::Apipie::WriteCommand
|
24
|
+
|
25
|
+
resource ForemanApi::Resources::CommonParameter
|
26
|
+
|
27
|
+
option "--name", "NAME", "parameter name", :required => true
|
28
|
+
option "--value", "VALUE", "parameter value", :required => true
|
29
|
+
|
30
|
+
def execute
|
31
|
+
if parameter_exist?
|
32
|
+
self.class.action :update
|
33
|
+
else
|
34
|
+
self.class.action :create
|
35
|
+
end
|
36
|
+
super
|
37
|
+
end
|
38
|
+
|
39
|
+
def print_message
|
40
|
+
if self.class.action == :create
|
41
|
+
msg = "Global parameter created"
|
42
|
+
else
|
43
|
+
msg = "Global parameter updated"
|
44
|
+
end
|
45
|
+
output.print_message msg
|
46
|
+
end
|
47
|
+
|
48
|
+
def parameter_exist?
|
49
|
+
params = resource.index(resource_config)[0]
|
50
|
+
params.find { |p| p["common_parameter"]["name"] == name }
|
51
|
+
end
|
52
|
+
|
53
|
+
def request_params
|
54
|
+
params = method_options
|
55
|
+
params['id'] = name
|
56
|
+
params
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
class DeleteCommand < HammerCLIForeman::DeleteCommand
|
63
|
+
|
64
|
+
identifiers :name
|
65
|
+
|
66
|
+
success_message "Global parameter deleted"
|
67
|
+
failure_message "Could not delete the global parameter"
|
68
|
+
resource ForemanApi::Resources::CommonParameter, "destroy"
|
69
|
+
|
70
|
+
apipie_options :without => :id
|
71
|
+
end
|
72
|
+
|
73
|
+
subcommand "list", "List global parameters.", HammerCLIForeman::CommonParameter::ListCommand
|
74
|
+
subcommand "set", "Set a global parameter.", HammerCLIForeman::CommonParameter::SetCommand
|
75
|
+
subcommand "delete", "Delete a global parameter.", HammerCLIForeman::CommonParameter::DeleteCommand
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
HammerCLI::MainCommand.subcommand 'global_parameter', "Manipulate Foreman's global parameters.", HammerCLIForeman::CommonParameter
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'hammer_cli'
|
2
|
+
require 'foreman_api'
|
3
|
+
require 'hammer_cli_foreman/commands'
|
4
|
+
|
5
|
+
module HammerCLIForeman
|
6
|
+
|
7
|
+
class ComputeResource < HammerCLI::AbstractCommand
|
8
|
+
|
9
|
+
class ListCommand < HammerCLIForeman::ListCommand
|
10
|
+
resource ForemanApi::Resources::ComputeResource, "index"
|
11
|
+
|
12
|
+
heading "Compute resource list"
|
13
|
+
output do
|
14
|
+
from "compute_resource" do
|
15
|
+
field :id, "Id"
|
16
|
+
field :name, "Name"
|
17
|
+
field :provider, "Provider"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
apipie_options
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
class InfoCommand < HammerCLIForeman::InfoCommand
|
26
|
+
|
27
|
+
PROVIDER_SPECIFIC_FIELDS = {
|
28
|
+
'ovirt' => [
|
29
|
+
HammerCLI::Output::DataField.new(:label => 'UUID', :path => ["compute_resource", "uuid"])
|
30
|
+
],
|
31
|
+
'ec2' => [
|
32
|
+
HammerCLI::Output::DataField.new(:label => 'Region', :path => ["compute_resource", "region"])
|
33
|
+
],
|
34
|
+
'vmware' => [
|
35
|
+
HammerCLI::Output::DataField.new(:label => 'UUID', :path => ["compute_resource", "uuid"]),
|
36
|
+
HammerCLI::Output::DataField.new(:label => 'Server', :path => ["compute_resource", "server"])
|
37
|
+
],
|
38
|
+
'openstack' => [
|
39
|
+
HammerCLI::Output::DataField.new(:label => 'Tenant', :path => ["compute_resource", "tenant"])
|
40
|
+
],
|
41
|
+
'rackspace' => [
|
42
|
+
HammerCLI::Output::DataField.new(:label => 'Region', :path => ["compute_resource", "region"])
|
43
|
+
],
|
44
|
+
'libvirt' => [
|
45
|
+
]
|
46
|
+
}
|
47
|
+
|
48
|
+
resource ForemanApi::Resources::ComputeResource, "show"
|
49
|
+
|
50
|
+
heading "Compute resource info"
|
51
|
+
output ListCommand.output_definition do
|
52
|
+
from "compute_resource" do
|
53
|
+
field :url, "Url"
|
54
|
+
field :description, "Description"
|
55
|
+
field :user, "User"
|
56
|
+
field :created_at, "Created at", HammerCLI::Output::Fields::Date
|
57
|
+
field :updated_at, "Updated at", HammerCLI::Output::Fields::Date
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def print_records data
|
62
|
+
provider = data["compute_resource"]["provider"].downcase
|
63
|
+
output_definition.fields.concat PROVIDER_SPECIFIC_FIELDS[provider]
|
64
|
+
super data
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
class CreateCommand < HammerCLIForeman::CreateCommand
|
71
|
+
|
72
|
+
success_message "Compute resource created"
|
73
|
+
failure_message "Could not create the compute resource"
|
74
|
+
resource ForemanApi::Resources::ComputeResource, "create"
|
75
|
+
|
76
|
+
apipie_options
|
77
|
+
|
78
|
+
validate_options do
|
79
|
+
all(:name, :url, :provider).required
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
class UpdateCommand < HammerCLIForeman::UpdateCommand
|
85
|
+
|
86
|
+
success_message "Compute resource updated"
|
87
|
+
failure_message "Could not update the compute resource"
|
88
|
+
resource ForemanApi::Resources::ComputeResource, "update"
|
89
|
+
|
90
|
+
apipie_options
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
class DeleteCommand < HammerCLIForeman::DeleteCommand
|
95
|
+
|
96
|
+
success_message "Compute resource deleted"
|
97
|
+
failure_message "Could not delete the compute resource"
|
98
|
+
resource ForemanApi::Resources::ComputeResource, "destroy"
|
99
|
+
|
100
|
+
apipie_options
|
101
|
+
end
|
102
|
+
|
103
|
+
subcommand "list", "List compute resources.", HammerCLIForeman::ComputeResource::ListCommand
|
104
|
+
subcommand "info", "Detailed info about a compute resource.", HammerCLIForeman::ComputeResource::InfoCommand
|
105
|
+
subcommand "create", "Create new compute resource.", HammerCLIForeman::ComputeResource::CreateCommand
|
106
|
+
subcommand "update", "Update a compute resource.", HammerCLIForeman::ComputeResource::UpdateCommand
|
107
|
+
subcommand "delete", "Delete a compute resource.", HammerCLIForeman::ComputeResource::DeleteCommand
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
HammerCLI::MainCommand.subcommand 'compute_resource', "Manipulate Foreman's compute resources.", HammerCLIForeman::ComputeResource
|
113
|
+
|
@@ -0,0 +1,133 @@
|
|
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 Domain < HammerCLI::AbstractCommand
|
9
|
+
class ListCommand < HammerCLIForeman::ListCommand
|
10
|
+
resource ForemanApi::Resources::Domain, "index"
|
11
|
+
|
12
|
+
heading "Domain list"
|
13
|
+
output do
|
14
|
+
from "domain" do
|
15
|
+
field :id, "Id"
|
16
|
+
field :name, "Name"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
apipie_options
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
class InfoCommand < HammerCLIForeman::InfoCommand
|
25
|
+
|
26
|
+
resource ForemanApi::Resources::Domain, "show"
|
27
|
+
|
28
|
+
def retrieve_data
|
29
|
+
domain = super
|
30
|
+
domain["parameters"] = HammerCLIForeman::Parameter.get_parameters resource_config, domain
|
31
|
+
domain
|
32
|
+
end
|
33
|
+
|
34
|
+
heading "Domain info"
|
35
|
+
output ListCommand.output_definition do
|
36
|
+
from "domain" do
|
37
|
+
field :fullname, "Full Name"
|
38
|
+
field :dns_id, "DNS Id"
|
39
|
+
field :created_at, "Created at", HammerCLI::Output::Fields::Date
|
40
|
+
field :updated_at, "Updated at", HammerCLI::Output::Fields::Date
|
41
|
+
end
|
42
|
+
collection :parameters, "Parameters" do
|
43
|
+
field :parameter, nil, HammerCLI::Output::Fields::KeyValue
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
class CreateCommand < HammerCLIForeman::CreateCommand
|
51
|
+
|
52
|
+
success_message "Domain created"
|
53
|
+
failure_message "Could not create the domain"
|
54
|
+
resource ForemanApi::Resources::Domain, "create"
|
55
|
+
|
56
|
+
apipie_options :without => ['domain_parameters_attributes']
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
class UpdateCommand < HammerCLIForeman::UpdateCommand
|
61
|
+
|
62
|
+
success_message "Domain updated"
|
63
|
+
failure_message "Could not update the domain"
|
64
|
+
resource ForemanApi::Resources::Domain, "update"
|
65
|
+
|
66
|
+
apipie_options :without => ['domain_parameters_attributes', 'name', 'id']
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
class DeleteCommand < HammerCLIForeman::DeleteCommand
|
71
|
+
|
72
|
+
success_message "Domain deleted"
|
73
|
+
failure_message "Could not delete the domain"
|
74
|
+
resource ForemanApi::Resources::Domain, "destroy"
|
75
|
+
|
76
|
+
apipie_options
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
class SetParameterCommand < HammerCLIForeman::Parameter::SetCommand
|
81
|
+
|
82
|
+
option "--domain-name", "DOMAIN_NAME", "name of the domain the parameter is being set for"
|
83
|
+
option "--domain-id", "DOMAIN_ID", "id of the domain the parameter is being set for"
|
84
|
+
|
85
|
+
success_message_for :update, "Domain parameter updated"
|
86
|
+
success_message_for :create, "New domain parameter created"
|
87
|
+
failure_message "Could not set domain parameter"
|
88
|
+
|
89
|
+
def validate_options
|
90
|
+
super
|
91
|
+
validator.any(:domain_name, :domain_id).required
|
92
|
+
end
|
93
|
+
|
94
|
+
def base_action_params
|
95
|
+
{
|
96
|
+
"domain_id" => domain_id || domain_name
|
97
|
+
}
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
class DeleteParameterCommand < HammerCLIForeman::Parameter::DeleteCommand
|
103
|
+
|
104
|
+
option "--domain-name", "DOMAIN_NAME", "name of the domain the parameter is being deleted for"
|
105
|
+
option "--domain-id", "DOMAIN_ID", "id of the domain the parameter is being deleted for"
|
106
|
+
|
107
|
+
success_message "Domain parameter deleted"
|
108
|
+
|
109
|
+
def validate_options
|
110
|
+
super
|
111
|
+
validator.any(:domain_name, :domain_id).required
|
112
|
+
end
|
113
|
+
|
114
|
+
def base_action_params
|
115
|
+
{
|
116
|
+
"domain_id" => domain_id || domain_name
|
117
|
+
}
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
subcommand "list", "List domains.", HammerCLIForeman::Domain::ListCommand
|
122
|
+
subcommand "info", "Detailed info about a domain.", HammerCLIForeman::Domain::InfoCommand
|
123
|
+
subcommand "create", "Create a new domain.", HammerCLIForeman::Domain::CreateCommand
|
124
|
+
subcommand "update", "Update a domain.", HammerCLIForeman::Domain::UpdateCommand
|
125
|
+
subcommand "delete", "Delete a domain.", HammerCLIForeman::Domain::DeleteCommand
|
126
|
+
subcommand "set_parameter", "Create or update parameter for a domain.", HammerCLIForeman::Domain::SetParameterCommand
|
127
|
+
subcommand "delete_parameter", "Delete parameter for a domain.", HammerCLIForeman::Domain::DeleteParameterCommand
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
HammerCLI::MainCommand.subcommand 'domain', "Manipulate Foreman's domains.", HammerCLIForeman::Domain
|
133
|
+
|