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
@@ -19,20 +19,27 @@ module HammerCLIForeman
19
19
  class SetCommand < HammerCLI::Apipie::Command
20
20
 
21
21
  include HammerCLI::Messages
22
- resource ForemanApi::Resources::Parameter
23
22
 
24
23
  option "--name", "NAME", "parameter name", :required => true
25
24
  option "--value", "VALUE", "parameter value", :required => true
26
25
 
26
+ def self.command_name(name=nil)
27
+ super(name) || "set_parameter"
28
+ end
29
+
30
+ def self.resource(resource=nil)
31
+ super(resource) || HammerCLI::Apipie::ResourceDefinition.new(ForemanApi::Resources::Parameter)
32
+ end
33
+
27
34
  def execute
28
35
  if parameter_exist?
29
36
  update_parameter
30
- output.print_message success_message_for :update if success_message_for :update
37
+ output.print_message success_message_for :update if success_message_for :update
31
38
  else
32
39
  create_parameter
33
- output.print_message success_message_for :create if success_message_for :create
40
+ output.print_message success_message_for :create if success_message_for :create
34
41
  end
35
- 0
42
+ HammerCLI::EX_OK
36
43
  end
37
44
 
38
45
  def base_action_params
@@ -40,7 +47,7 @@ module HammerCLIForeman
40
47
  end
41
48
 
42
49
  def parameter_exist?
43
- params = resource.index(base_action_params)[0]
50
+ params = resource.call(:index, base_action_params)[0]
44
51
  params.find { |p| p["parameter"]["name"] == name }
45
52
  end
46
53
 
@@ -52,7 +59,7 @@ module HammerCLIForeman
52
59
  }
53
60
  }.merge base_action_params
54
61
 
55
- resource.update(params)
62
+ resource.call(:update, params)
56
63
  end
57
64
 
58
65
  def create_parameter
@@ -63,7 +70,7 @@ module HammerCLIForeman
63
70
  }
64
71
  }.merge base_action_params
65
72
 
66
- resource.create(params)
73
+ resource.call(:create, params)
67
74
  end
68
75
 
69
76
  end
@@ -72,18 +79,25 @@ module HammerCLIForeman
72
79
  class DeleteCommand < HammerCLI::Apipie::Command
73
80
 
74
81
  include HammerCLI::Messages
75
- resource ForemanApi::Resources::Parameter
76
82
 
77
83
  option "--name", "NAME", "parameter name", :required => true
78
84
 
85
+ def self.command_name(name=nil)
86
+ super(name) || "delete_parameter"
87
+ end
88
+
89
+ def self.resource(resource=nil)
90
+ super(resource) || HammerCLI::Apipie::ResourceDefinition.new(ForemanApi::Resources::Parameter)
91
+ end
92
+
79
93
  def execute
80
94
  params = {
81
95
  "id" => name
82
96
  }.merge base_action_params
83
97
 
84
- resource.destroy(params)
98
+ resource.call(:destroy, params)
85
99
  output.print_message success_message if success_message
86
- 0
100
+ HammerCLI::EX_OK
87
101
  end
88
102
 
89
103
  def base_action_params
@@ -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 PartitionTable < HammerCLI::AbstractCommand
8
+ class PartitionTable < HammerCLI::Apipie::Command
9
+
10
+ resource ForemanApi::Resources::Ptable
8
11
 
9
12
  class ListCommand < HammerCLIForeman::ListCommand
10
13
 
11
- heading "Partition table list"
12
14
  output do
13
15
  from "ptable" do
14
16
  field :id, "Id"
@@ -17,28 +19,27 @@ module HammerCLIForeman
17
19
  end
18
20
  end
19
21
 
20
- resource ForemanApi::Resources::Ptable, "index"
21
22
  apipie_options
22
23
  end
23
24
 
24
25
 
25
26
  class InfoCommand < HammerCLIForeman::InfoCommand
26
27
 
27
- heading "Partition table info"
28
28
  output ListCommand.output_definition do
29
29
  from "ptable" do
30
- field :created_at, "Created at", HammerCLI::Output::Fields::Date
31
- field :updated_at, "Updated at", HammerCLI::Output::Fields::Date
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::Ptable, "show"
36
35
  end
37
36
 
38
37
 
39
38
  class DumpCommand < HammerCLIForeman::InfoCommand
40
39
 
41
- resource ForemanApi::Resources::Ptable, "show"
40
+ command_name "dump"
41
+ desc "View partition table content."
42
+
42
43
 
43
44
  def print_data(partition_table)
44
45
  puts partition_table["ptable"]["layout"]
@@ -53,7 +54,6 @@ module HammerCLIForeman
53
54
 
54
55
  success_message "Partition table created"
55
56
  failure_message "Could not create the partition table"
56
- resource ForemanApi::Resources::Ptable, "create"
57
57
 
58
58
  apipie_options :without => [:layout] + declared_identifiers.keys
59
59
  end
@@ -65,7 +65,6 @@ module HammerCLIForeman
65
65
 
66
66
  success_message "Partition table updated"
67
67
  failure_message "Could not update the partition table"
68
- resource ForemanApi::Resources::Ptable, "update"
69
68
 
70
69
  apipie_options :without => [:layout] + declared_identifiers.keys
71
70
  end
@@ -75,16 +74,13 @@ module HammerCLIForeman
75
74
 
76
75
  success_message "Partition table deleted"
77
76
  failure_message "Could not delete the partition table"
78
- resource ForemanApi::Resources::Ptable, "destroy"
79
77
  end
80
78
 
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
79
 
80
+ include HammerCLIForeman::AssociatingCommands::OperatingSystem
81
+
82
+
83
+ autoload_subcommands
88
84
  end
89
85
 
90
86
  end
@@ -0,0 +1,55 @@
1
+ require 'hammer_cli'
2
+ require 'foreman_api'
3
+ require 'hammer_cli_foreman/commands'
4
+
5
+ module HammerCLIForeman
6
+
7
+ class PuppetClass < HammerCLI::Apipie::Command
8
+
9
+ resource ForemanApi::Resources::Puppetclass
10
+
11
+ class ListCommand < HammerCLIForeman::ListCommand
12
+
13
+ output do
14
+ from "puppetclass" do
15
+ field :id, "Id"
16
+ field :name, "Name"
17
+ end
18
+ end
19
+
20
+ def retrieve_data
21
+ self.class.unhash_classes(super)
22
+ end
23
+
24
+ def self.unhash_classes(classes)
25
+ classes.inject([]) { |list, (pp_module, pp_module_classes)| list + pp_module_classes }
26
+ end
27
+
28
+ apipie_options
29
+ end
30
+
31
+
32
+ class InfoCommand < HammerCLIForeman::InfoCommand
33
+
34
+ #FIXME: show environments and hostgroups
35
+ output ListCommand.output_definition do
36
+ from "puppetclass" do
37
+ collection :lookup_keys, "Smart variables" do
38
+ from :lookup_key do
39
+ field :key, "Parameter"
40
+ field :default_value, "Default value"
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ end
47
+
48
+
49
+ autoload_subcommands
50
+ end
51
+
52
+ end
53
+
54
+ HammerCLI::MainCommand.subcommand 'puppet_class', "Browse and read reports.", HammerCLIForeman::PuppetClass
55
+
@@ -0,0 +1,97 @@
1
+ require 'hammer_cli'
2
+ require 'foreman_api'
3
+ require 'hammer_cli_foreman/commands'
4
+
5
+ module HammerCLIForeman
6
+
7
+ class Report < HammerCLI::Apipie::Command
8
+
9
+ resource ForemanApi::Resources::Report
10
+
11
+ class ListCommand < HammerCLIForeman::ListCommand
12
+
13
+ output do
14
+ from "report" do
15
+ field :id, "Id"
16
+ field :host_name, "Host"
17
+ field :reported_at, "Last report", Fields::Date
18
+ from "status" do
19
+ field :applied, "Applied"
20
+ field :restarted, "Restarted"
21
+ field :failed, "Failed"
22
+ field :failed_restarts, "Restart Failures"
23
+ field :skipped, "Skipped"
24
+ field :pending, "Pending"
25
+ end
26
+ end
27
+ end
28
+
29
+ apipie_options
30
+ end
31
+
32
+
33
+ class InfoCommand < HammerCLIForeman::InfoCommand
34
+
35
+ identifiers :id
36
+
37
+ output do
38
+ from "report" do
39
+ field :id, "Id"
40
+ field :host_name, "Host"
41
+ field :reported_at, "Reported at", Fields::Date
42
+ label "Report status" do
43
+ from "status" do
44
+ field :applied, "Applied"
45
+ field :restarted, "Restarted"
46
+ field :failed, "Failed"
47
+ field :failed_restarts, "Restart Failures"
48
+ field :skipped, "Skipped"
49
+ field :pending, "Pending"
50
+ end
51
+ end
52
+ label "Report metrics" do
53
+ from "metrics" do
54
+ from "time" do
55
+ field :config_retrieval, "config_retrieval"
56
+ field :exec, "exec"
57
+ field :file, "file"
58
+ field :package, "package"
59
+ field :service, "service"
60
+ field :user, "user"
61
+ field :yumrepo, "yumrepo"
62
+ field :filebucket, "filebucket"
63
+ field :cron, "cron"
64
+ field :total, "total"
65
+ end
66
+ end
67
+ end
68
+ field :logs, "Logs", Fields::Collection do
69
+ from :log do
70
+ from :source do
71
+ field :source, "Resource"
72
+ end
73
+ from :message do
74
+ field :message, "Message"
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+
81
+ end
82
+
83
+
84
+ class DeleteCommand < HammerCLIForeman::DeleteCommand
85
+ identifiers :id
86
+ success_message "Report has been deleted"
87
+ failure_message "Could not delete the report"
88
+ end
89
+
90
+
91
+ autoload_subcommands
92
+ end
93
+
94
+ end
95
+
96
+ HammerCLI::MainCommand.subcommand 'report', "Browse and read reports.", HammerCLIForeman::Report
97
+
@@ -12,7 +12,7 @@ module HammerCLIForeman
12
12
  end
13
13
 
14
14
  def resource_supported?
15
- resource.index
15
+ resource.call(:index)
16
16
  true
17
17
  rescue RestClient::ResourceNotFound => e
18
18
  false
@@ -9,7 +9,6 @@ module HammerCLIForeman
9
9
  resource ForemanApi::Resources::SmartProxy, "index"
10
10
 
11
11
  #FIXME: search by unknown type returns 500 from the server, propper error handling should resove this
12
- heading "Smart Proxy list"
13
12
  output do
14
13
  from "smart_proxy" do
15
14
  field :id, "Id"
@@ -32,12 +31,11 @@ module HammerCLIForeman
32
31
  sp
33
32
  end
34
33
 
35
- heading "Smart proxy info"
36
34
  output ListCommand.output_definition do
37
35
  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
36
+ field :_features, "Features", Fields::List
37
+ field :created_at, "Created at", Fields::Date
38
+ field :updated_at, "Updated at", Fields::Date
41
39
  end
42
40
  end
43
41
 
@@ -65,7 +63,7 @@ module HammerCLIForeman
65
63
 
66
64
 
67
65
  class DeleteCommand < HammerCLIForeman::DeleteCommand
68
-
66
+
69
67
  success_message "Smart proxy deleted"
70
68
  failure_message "Could not delete the proxy"
71
69
  resource ForemanApi::Resources::SmartProxy, "destroy"
@@ -73,11 +71,7 @@ module HammerCLIForeman
73
71
  apipie_options
74
72
  end
75
73
 
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
74
+ autoload_subcommands
81
75
  end
82
76
 
83
77
  end
@@ -8,7 +8,6 @@ module HammerCLIForeman
8
8
  class ListCommand < HammerCLIForeman::ListCommand
9
9
  resource ForemanApi::Resources::Subnet, "index"
10
10
 
11
- heading "Subnet list"
12
11
  output do
13
12
  from "subnet" do
14
13
  field :id, "Id"
@@ -26,17 +25,16 @@ module HammerCLIForeman
26
25
 
27
26
  resource ForemanApi::Resources::Subnet, "show"
28
27
 
29
- heading "Subnet info"
30
28
  output ListCommand.output_definition do
31
29
  from "subnet" do
32
30
  field :priority, "Priority"
33
- field :dns, "DNS", HammerCLI::Output::Fields::Server
31
+ field :dns, "DNS", Fields::Server
34
32
  field :dns_primary, "Primary DNS"
35
33
  field :dns_secondary, "Secondary DNS"
36
- field :domain_ids, "Domain ids", HammerCLI::Output::Fields::List
37
- field :tftp, "TFTP", HammerCLI::Output::Fields::Server
34
+ field :domain_ids, "Domain ids", Fields::List
35
+ field :tftp, "TFTP", Fields::Server
38
36
  field :tftp_id, "TFTP id"
39
- field :dhcp, "DHCP", HammerCLI::Output::Fields::Server
37
+ field :dhcp, "DHCP", Fields::Server
40
38
  field :dhcp_id, "DHCP id"
41
39
  field :vlanid, "vlan id"
42
40
  field :gateway, "Gateway"
@@ -77,11 +75,7 @@ module HammerCLIForeman
77
75
  apipie_options
78
76
  end
79
77
 
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
78
+ autoload_subcommands
85
79
  end
86
80
 
87
81
  end
@@ -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 Template < HammerCLI::AbstractCommand
8
+ class Template < HammerCLI::Apipie::Command
9
+
10
+ resource ForemanApi::Resources::ConfigTemplate
8
11
 
9
12
  class ListCommand < HammerCLIForeman::ListCommand
10
13
 
11
- heading "Template list"
12
14
  output do
13
15
  from "config_template" do
14
16
  field :id, "Id"
@@ -28,7 +30,6 @@ module HammerCLIForeman
28
30
  end
29
31
  end
30
32
 
31
- resource ForemanApi::Resources::ConfigTemplate, "index"
32
33
  apipie_options
33
34
  end
34
35
 
@@ -39,10 +40,9 @@ module HammerCLIForeman
39
40
  # Api currently does not accept names containing a dot
40
41
  identifiers :id
41
42
 
42
- heading "Template info"
43
43
  output ListCommand.output_definition do
44
44
  from "config_template" do
45
- field :operatingsystem_ids, "OS ids", HammerCLI::Output::Fields::List
45
+ field :operatingsystem_ids, "OS ids", Fields::List
46
46
  end
47
47
  end
48
48
 
@@ -56,13 +56,14 @@ module HammerCLIForeman
56
56
  template
57
57
  end
58
58
 
59
- resource ForemanApi::Resources::ConfigTemplate, "show"
60
59
  end
61
60
 
62
61
 
63
62
  class ListKindsCommand < HammerCLIForeman::ListCommand
64
63
 
65
- heading "Template kind list"
64
+ command_name "kinds"
65
+ desc "List available config template kinds."
66
+
66
67
  output do
67
68
  from "template_kind" do
68
69
  field :name, "Name"
@@ -80,9 +81,10 @@ module HammerCLIForeman
80
81
 
81
82
  class DumpCommand < HammerCLIForeman::InfoCommand
82
83
 
83
- identifiers :id
84
+ command_name "dump"
85
+ desc "View config template content."
84
86
 
85
- resource ForemanApi::Resources::ConfigTemplate, "show"
87
+ identifiers :id
86
88
 
87
89
  def print_data(template)
88
90
  puts template["config_template"]["template"]
@@ -98,7 +100,6 @@ module HammerCLIForeman
98
100
 
99
101
  success_message "Config template created"
100
102
  failure_message "Could not create the config template"
101
- resource ForemanApi::Resources::ConfigTemplate, "create"
102
103
 
103
104
  def snippet
104
105
  type == "snippet"
@@ -123,7 +124,6 @@ module HammerCLIForeman
123
124
 
124
125
  success_message "Config template updated"
125
126
  failure_message "Could not update the config template"
126
- resource ForemanApi::Resources::ConfigTemplate, "update"
127
127
 
128
128
  def snippet
129
129
  type == "snippet"
@@ -145,17 +145,13 @@ module HammerCLIForeman
145
145
 
146
146
  success_message "Config template deleted"
147
147
  failure_message "Could not delete the config template"
148
- resource ForemanApi::Resources::ConfigTemplate, "destroy"
149
148
  end
150
149
 
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
150
 
151
+ include HammerCLIForeman::AssociatingCommands::OperatingSystem
152
+
153
+
154
+ autoload_subcommands
159
155
  end
160
156
 
161
157
  end