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,93 @@
1
+ require 'hammer_cli'
2
+ require 'foreman_api'
3
+ require 'hammer_cli_foreman/commands'
4
+
5
+ module HammerCLIForeman
6
+
7
+ class PartitionTable < HammerCLI::AbstractCommand
8
+
9
+ class ListCommand < HammerCLIForeman::ListCommand
10
+
11
+ heading "Partition table list"
12
+ output do
13
+ from "ptable" do
14
+ field :id, "Id"
15
+ field :name, "Name"
16
+ field :os_family, "OS Family"
17
+ end
18
+ end
19
+
20
+ resource ForemanApi::Resources::Ptable, "index"
21
+ apipie_options
22
+ end
23
+
24
+
25
+ class InfoCommand < HammerCLIForeman::InfoCommand
26
+
27
+ heading "Partition table info"
28
+ output ListCommand.output_definition do
29
+ from "ptable" do
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::Ptable, "show"
36
+ end
37
+
38
+
39
+ class DumpCommand < HammerCLIForeman::InfoCommand
40
+
41
+ resource ForemanApi::Resources::Ptable, "show"
42
+
43
+ def print_data(partition_table)
44
+ puts partition_table["ptable"]["layout"]
45
+ end
46
+
47
+ end
48
+
49
+
50
+ class CreateCommand < HammerCLIForeman::CreateCommand
51
+
52
+ option "--file", "LAYOUT", "Path to a file that contains the partition layout", :attribute_name => :layout, :required => true, &HammerCLI::OptionFormatters.method(:file)
53
+
54
+ success_message "Partition table created"
55
+ failure_message "Could not create the partition table"
56
+ resource ForemanApi::Resources::Ptable, "create"
57
+
58
+ apipie_options :without => [:layout] + declared_identifiers.keys
59
+ end
60
+
61
+
62
+ class UpdateCommand < HammerCLIForeman::UpdateCommand
63
+
64
+ option "--file", "LAYOUT", "Path to a file that contains the partition layout", :attribute_name => :layout, &HammerCLI::OptionFormatters.method(:file)
65
+
66
+ success_message "Partition table updated"
67
+ failure_message "Could not update the partition table"
68
+ resource ForemanApi::Resources::Ptable, "update"
69
+
70
+ apipie_options :without => [:layout] + declared_identifiers.keys
71
+ end
72
+
73
+
74
+ class DeleteCommand < HammerCLIForeman::DeleteCommand
75
+
76
+ success_message "Partition table deleted"
77
+ failure_message "Could not delete the partition table"
78
+ resource ForemanApi::Resources::Ptable, "destroy"
79
+ end
80
+
81
+ subcommand "list", "List partition tables.", HammerCLIForeman::PartitionTable::ListCommand
82
+ subcommand "info", "Detailed info about a partition table.", HammerCLIForeman::PartitionTable::InfoCommand
83
+ subcommand "dump", "View partition table content.", HammerCLIForeman::PartitionTable::DumpCommand
84
+ subcommand "create", "Create a new partition table.", HammerCLIForeman::PartitionTable::CreateCommand
85
+ subcommand "update", "Update a partition table.", HammerCLIForeman::PartitionTable::UpdateCommand
86
+ subcommand "delete", "Delete a partition table.", HammerCLIForeman::PartitionTable::DeleteCommand
87
+
88
+ end
89
+
90
+ end
91
+
92
+ HammerCLI::MainCommand.subcommand 'partition_table', "Manipulate Foreman's partition tables.", HammerCLIForeman::PartitionTable
93
+
@@ -0,0 +1,25 @@
1
+ module HammerCLIForeman
2
+
3
+ module ResourceSupportedTest
4
+
5
+ def execute
6
+ if resource_supported?
7
+ super
8
+ else
9
+ output.print_error "The server does not support such operation."
10
+ 1
11
+ end
12
+ end
13
+
14
+ def resource_supported?
15
+ resource.index
16
+ true
17
+ rescue RestClient::ResourceNotFound => e
18
+ false
19
+ end
20
+
21
+ end
22
+
23
+ end
24
+
25
+
@@ -0,0 +1,85 @@
1
+ require 'hammer_cli'
2
+ require 'foreman_api'
3
+ require 'hammer_cli_foreman/commands'
4
+
5
+ module HammerCLIForeman
6
+
7
+ class SmartProxy < HammerCLI::AbstractCommand
8
+ class ListCommand < HammerCLIForeman::ListCommand
9
+ resource ForemanApi::Resources::SmartProxy, "index"
10
+
11
+ #FIXME: search by unknown type returns 500 from the server, propper error handling should resove this
12
+ heading "Smart Proxy list"
13
+ output do
14
+ from "smart_proxy" do
15
+ field :id, "Id"
16
+ field :name, "Name"
17
+ field :url, "URL"
18
+ end
19
+ end
20
+
21
+ apipie_options
22
+ end
23
+
24
+
25
+ class InfoCommand < HammerCLIForeman::InfoCommand
26
+
27
+ resource ForemanApi::Resources::SmartProxy, "show"
28
+
29
+ def retrieve_data
30
+ sp = super
31
+ sp['smart_proxy']['_features'] = sp['smart_proxy']['features'].map { |f| f['feature']['name'] }
32
+ sp
33
+ end
34
+
35
+ heading "Smart proxy info"
36
+ output ListCommand.output_definition do
37
+ from "smart_proxy" do
38
+ field :_features, "Features", HammerCLI::Output::Fields::List
39
+ field :created_at, "Created at", HammerCLI::Output::Fields::Date
40
+ field :updated_at, "Updated at", HammerCLI::Output::Fields::Date
41
+ end
42
+ end
43
+
44
+ end
45
+
46
+
47
+ class CreateCommand < HammerCLIForeman::CreateCommand
48
+
49
+ success_message "Smart proxy created"
50
+ failure_message "Could not create the proxy"
51
+ resource ForemanApi::Resources::SmartProxy, "create"
52
+
53
+ apipie_options
54
+ end
55
+
56
+
57
+ class UpdateCommand < HammerCLIForeman::UpdateCommand
58
+
59
+ success_message "Smart proxy updated"
60
+ failure_message "Could not update the proxy"
61
+ resource ForemanApi::Resources::SmartProxy, "update"
62
+
63
+ apipie_options
64
+ end
65
+
66
+
67
+ class DeleteCommand < HammerCLIForeman::DeleteCommand
68
+
69
+ success_message "Smart proxy deleted"
70
+ failure_message "Could not delete the proxy"
71
+ resource ForemanApi::Resources::SmartProxy, "destroy"
72
+
73
+ apipie_options
74
+ end
75
+
76
+ subcommand "list", "List smart proxies.", HammerCLIForeman::SmartProxy::ListCommand
77
+ subcommand "info", "Detailed info about an smart proxy.", HammerCLIForeman::SmartProxy::InfoCommand
78
+ subcommand "create", "Create new smart proxy.", HammerCLIForeman::SmartProxy::CreateCommand
79
+ subcommand "update", "Update an smart proxy.", HammerCLIForeman::SmartProxy::UpdateCommand
80
+ subcommand "delete", "Delete an smart proxy.", HammerCLIForeman::SmartProxy::DeleteCommand
81
+ end
82
+
83
+ end
84
+
85
+ HammerCLI::MainCommand.subcommand 'proxy', "Manipulate Foreman's smart proxies.", HammerCLIForeman::SmartProxy
@@ -0,0 +1,90 @@
1
+ require 'hammer_cli'
2
+ require 'foreman_api'
3
+ require 'hammer_cli_foreman/commands'
4
+
5
+ module HammerCLIForeman
6
+
7
+ class Subnet < HammerCLI::AbstractCommand
8
+ class ListCommand < HammerCLIForeman::ListCommand
9
+ resource ForemanApi::Resources::Subnet, "index"
10
+
11
+ heading "Subnet list"
12
+ output do
13
+ from "subnet" do
14
+ field :id, "Id"
15
+ field :name, "Name"
16
+ field :network, "Network"
17
+ field :mask, "Mask"
18
+ end
19
+ end
20
+
21
+ apipie_options
22
+ end
23
+
24
+
25
+ class InfoCommand < HammerCLIForeman::InfoCommand
26
+
27
+ resource ForemanApi::Resources::Subnet, "show"
28
+
29
+ heading "Subnet info"
30
+ output ListCommand.output_definition do
31
+ from "subnet" do
32
+ field :priority, "Priority"
33
+ field :dns, "DNS", HammerCLI::Output::Fields::Server
34
+ field :dns_primary, "Primary DNS"
35
+ field :dns_secondary, "Secondary DNS"
36
+ field :domain_ids, "Domain ids", HammerCLI::Output::Fields::List
37
+ field :tftp, "TFTP", HammerCLI::Output::Fields::Server
38
+ field :tftp_id, "TFTP id"
39
+ field :dhcp, "DHCP", HammerCLI::Output::Fields::Server
40
+ field :dhcp_id, "DHCP id"
41
+ field :vlanid, "vlan id"
42
+ field :gateway, "Gateway"
43
+ field :from, "From"
44
+ field :to, "To"
45
+ end
46
+ end
47
+
48
+ end
49
+
50
+
51
+ class CreateCommand < HammerCLIForeman::CreateCommand
52
+
53
+ success_message "Subnet created"
54
+ failure_message "Could not create the subnet"
55
+ resource ForemanApi::Resources::Subnet, "create"
56
+
57
+ apipie_options
58
+ end
59
+
60
+
61
+ class UpdateCommand < HammerCLIForeman::UpdateCommand
62
+
63
+ success_message "Subnet updated"
64
+ failure_message "Could not update the subnet"
65
+ resource ForemanApi::Resources::Subnet, "update"
66
+
67
+ apipie_options
68
+ end
69
+
70
+
71
+ class DeleteCommand < HammerCLIForeman::DeleteCommand
72
+
73
+ success_message "Subnet deleted"
74
+ failure_message "Could not delete the subnet"
75
+ resource ForemanApi::Resources::Subnet, "destroy"
76
+
77
+ apipie_options
78
+ end
79
+
80
+ subcommand "list", "List subnets.", HammerCLIForeman::Subnet::ListCommand
81
+ subcommand "info", "Detailed info about an subnet.", HammerCLIForeman::Subnet::InfoCommand
82
+ subcommand "create", "Create new subnet.", HammerCLIForeman::Subnet::CreateCommand
83
+ subcommand "update", "Update an subnet.", HammerCLIForeman::Subnet::UpdateCommand
84
+ subcommand "delete", "Delete an subnet.", HammerCLIForeman::Subnet::DeleteCommand
85
+ end
86
+
87
+ end
88
+
89
+ HammerCLI::MainCommand.subcommand 'subnet', "Manipulate Foreman's subnets.", HammerCLIForeman::Subnet
90
+
@@ -0,0 +1,164 @@
1
+ require 'hammer_cli'
2
+ require 'foreman_api'
3
+ require 'hammer_cli_foreman/commands'
4
+
5
+ module HammerCLIForeman
6
+
7
+ class Template < HammerCLI::AbstractCommand
8
+
9
+ class ListCommand < HammerCLIForeman::ListCommand
10
+
11
+ heading "Template list"
12
+ output do
13
+ from "config_template" do
14
+ field :id, "Id"
15
+ field :name, "Name"
16
+ field :type, "Type"
17
+ end
18
+ end
19
+
20
+ def retrieve_data
21
+ templates = super
22
+ templates.each do |tpl|
23
+ if tpl["config_template"]["snippet"]
24
+ tpl["config_template"]["type"] = "snippet"
25
+ else
26
+ tpl["config_template"]["type"] = tpl["config_template"]["template_kind"]["name"]
27
+ end
28
+ end
29
+ end
30
+
31
+ resource ForemanApi::Resources::ConfigTemplate, "index"
32
+ apipie_options
33
+ end
34
+
35
+
36
+ class InfoCommand < HammerCLIForeman::InfoCommand
37
+
38
+ #FIXME: Add name identifier when the find by name issue is fixed in the api
39
+ # Api currently does not accept names containing a dot
40
+ identifiers :id
41
+
42
+ heading "Template info"
43
+ output ListCommand.output_definition do
44
+ from "config_template" do
45
+ field :operatingsystem_ids, "OS ids", HammerCLI::Output::Fields::List
46
+ end
47
+ end
48
+
49
+ def retrieve_data
50
+ template = super
51
+ if template["config_template"]["snippet"]
52
+ template["config_template"]["type"] = "snippet"
53
+ else
54
+ template["config_template"]["type"] = template["config_template"]["template_kind"]["name"]
55
+ end
56
+ template
57
+ end
58
+
59
+ resource ForemanApi::Resources::ConfigTemplate, "show"
60
+ end
61
+
62
+
63
+ class ListKindsCommand < HammerCLIForeman::ListCommand
64
+
65
+ heading "Template kind list"
66
+ output do
67
+ from "template_kind" do
68
+ field :name, "Name"
69
+ end
70
+ end
71
+
72
+ def retrieve_data
73
+ snippet = { "template_kind" => { "name" => "snippet" }}
74
+ super << snippet
75
+ end
76
+
77
+ resource ForemanApi::Resources::TemplateKind, "index"
78
+ end
79
+
80
+
81
+ class DumpCommand < HammerCLIForeman::InfoCommand
82
+
83
+ identifiers :id
84
+
85
+ resource ForemanApi::Resources::ConfigTemplate, "show"
86
+
87
+ def print_data(template)
88
+ puts template["config_template"]["template"]
89
+ end
90
+
91
+ end
92
+
93
+
94
+ class CreateCommand < HammerCLIForeman::CreateCommand
95
+
96
+ option "--file", "TEMPLATE", "Path to a file that contains the template", :attribute_name => :template, :required => true, &HammerCLI::OptionFormatters.method(:file)
97
+ option "--type", "TYPE", "Template type. Eg. snippet, script, provision", :required => true
98
+
99
+ success_message "Config template created"
100
+ failure_message "Could not create the config template"
101
+ resource ForemanApi::Resources::ConfigTemplate, "create"
102
+
103
+ def snippet
104
+ type == "snippet"
105
+ end
106
+
107
+ def template_kind_id
108
+ kinds = ForemanApi::Resources::TemplateKind.new(resource_config).index()[0]
109
+ table = kinds.inject({}){ |result, k| result.update(k["template_kind"]["name"] => k["template_kind"]["id"]) }
110
+ table[type]
111
+ end
112
+
113
+ apipie_options :without => [:template_combinations_attributes, :template, :snippet, :template_kind_id]
114
+ end
115
+
116
+
117
+ class UpdateCommand < HammerCLIForeman::UpdateCommand
118
+
119
+ option "--file", "TEMPLATE", "Path to a file that contains the template", :attribute_name => :template, &HammerCLI::OptionFormatters.method(:file)
120
+ option "--type", "TYPE", "Template type. Eg. snippet, script, provision"
121
+
122
+ identifiers :id
123
+
124
+ success_message "Config template updated"
125
+ failure_message "Could not update the config template"
126
+ resource ForemanApi::Resources::ConfigTemplate, "update"
127
+
128
+ def snippet
129
+ type == "snippet"
130
+ end
131
+
132
+ def template_kind_id
133
+ kinds = ForemanApi::Resources::TemplateKind.new(resource_config).index()[0]
134
+ table = kinds.inject({}){ |result, k| result.update(k["template_kind"]["name"] => k["template_kind"]["id"]) }
135
+ table[type]
136
+ end
137
+
138
+ apipie_options :without => [:template_combinations_attributes, :template, :snippet, :template_kind_id]
139
+ end
140
+
141
+
142
+ class DeleteCommand < HammerCLIForeman::DeleteCommand
143
+
144
+ identifiers :id
145
+
146
+ success_message "Config template deleted"
147
+ failure_message "Could not delete the config template"
148
+ resource ForemanApi::Resources::ConfigTemplate, "destroy"
149
+ end
150
+
151
+ subcommand "list", "List config templates.", HammerCLIForeman::Template::ListCommand
152
+ subcommand "info", "Detailed info about a config template.", HammerCLIForeman::Template::InfoCommand
153
+ subcommand "dump", "View config template content.", HammerCLIForeman::Template::DumpCommand
154
+ subcommand "create", "Create a new config template.", HammerCLIForeman::Template::CreateCommand
155
+ subcommand "update", "Update a config template.", HammerCLIForeman::Template::UpdateCommand
156
+ subcommand "delete", "Delete a config template.", HammerCLIForeman::Template::DeleteCommand
157
+ subcommand "kinds", "List available config template kinds.", HammerCLIForeman::Template::ListKindsCommand
158
+
159
+ end
160
+
161
+ end
162
+
163
+ HammerCLI::MainCommand.subcommand 'template', "Manipulate Foreman's config templates.", HammerCLIForeman::Template
164
+