hammer_cli_foreman 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of hammer_cli_foreman might be problematic. Click here for more details.

@@ -12,10 +12,8 @@ module HammerCLIForeman
12
12
  class ListCommand < HammerCLIForeman::ListCommand
13
13
 
14
14
  output do
15
- from "puppetclass" do
16
- field :id, "Id"
17
- field :name, "Name"
18
- end
15
+ field :id, "Id"
16
+ field :name, "Name"
19
17
  end
20
18
 
21
19
  def retrieve_data
@@ -23,7 +21,10 @@ module HammerCLIForeman
23
21
  end
24
22
 
25
23
  def self.unhash_classes(classes)
26
- classes.inject([]) { |list, (pp_module, pp_module_classes)| list + pp_module_classes }
24
+ clss = classes.first.inject([]) { |list, (pp_module, pp_module_classes)| list + pp_module_classes }
25
+
26
+ HammerCLI::Output::RecordCollection.new(clss, :meta => classes.meta)
27
+
27
28
  end
28
29
 
29
30
  apipie_options
@@ -32,14 +33,12 @@ module HammerCLIForeman
32
33
 
33
34
  class InfoCommand < HammerCLIForeman::InfoCommand
34
35
 
35
- #FIXME: show environments and hostgroups
36
+ #FIXME: show environments, hostgroups, variables and parameters
36
37
  output ListCommand.output_definition do
37
- from "puppetclass" do
38
- collection :lookup_keys, "Smart variables" do
39
- from :lookup_key do
40
- field :key, "Parameter"
41
- field :default_value, "Default value"
42
- end
38
+ collection :lookup_keys, "Smart variables" do
39
+ from :lookup_key do
40
+ field :key, "Parameter"
41
+ field :default_value, "Default value"
43
42
  end
44
43
  end
45
44
  end
@@ -50,7 +49,7 @@ module HammerCLIForeman
50
49
  class SCParamsCommand < HammerCLIForeman::SmartClassParametersBriefList
51
50
 
52
51
  apipie_options :without => [:host_id, :hostgroup_id, :puppetclass_id, :environment_id]
53
- option ['--id', '--name'], 'PUPPET_CLASS_ID', 'puppet class id/name',
52
+ option ['--id', '--name'], 'PUPPET_CLASS_ID', 'puppet class id/name',
54
53
  :attribute_name => :puppetclass_id, :required => true
55
54
  end
56
55
 
@@ -11,18 +11,16 @@ module HammerCLIForeman
11
11
  class ListCommand < HammerCLIForeman::ListCommand
12
12
 
13
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
14
+ field :id, "Id"
15
+ field :host_name, "Host"
16
+ field :reported_at, "Last report", Fields::Date
17
+ from "status" do
18
+ field :applied, "Applied"
19
+ field :restarted, "Restarted"
20
+ field :failed, "Failed"
21
+ field :failed_restarts, "Restart Failures"
22
+ field :skipped, "Skipped"
23
+ field :pending, "Pending"
26
24
  end
27
25
  end
28
26
 
@@ -35,44 +33,42 @@ module HammerCLIForeman
35
33
  identifiers :id
36
34
 
37
35
  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
36
+ field :id, "Id"
37
+ field :host_name, "Host"
38
+ field :reported_at, "Reported at", Fields::Date
39
+ label "Report status" do
40
+ from "status" do
41
+ field :applied, "Applied"
42
+ field :restarted, "Restarted"
43
+ field :failed, "Failed"
44
+ field :failed_restarts, "Restart Failures"
45
+ field :skipped, "Skipped"
46
+ field :pending, "Pending"
51
47
  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
48
+ end
49
+ label "Report metrics" do
50
+ from "metrics" do
51
+ from "time" do
52
+ field :config_retrieval, "config_retrieval"
53
+ field :exec, "exec"
54
+ field :file, "file"
55
+ field :package, "package"
56
+ field :service, "service"
57
+ field :user, "user"
58
+ field :yumrepo, "yumrepo"
59
+ field :filebucket, "filebucket"
60
+ field :cron, "cron"
61
+ field :total, "total"
66
62
  end
67
63
  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
64
+ end
65
+ field :logs, "Logs", Fields::Collection do
66
+ from :log do
67
+ from :source do
68
+ field :source, "Resource"
69
+ end
70
+ from :message do
71
+ field :message, "Message"
76
72
  end
77
73
  end
78
74
  end
@@ -21,19 +21,19 @@ module HammerCLIForeman
21
21
  # FIXME: API returns doubled records, probably just if filtered by puppetclasses
22
22
  # it seems group by environment is missing
23
23
  # having the uniq to fix that
24
- res["smart_class_parameters"].uniq
24
+ HammerCLI::Output::RecordCollection.new(res.uniq, :meta => res.meta)
25
25
  end
26
26
  end
27
27
 
28
28
  class SmartClassParametersList < SmartClassParametersBriefList
29
29
 
30
- output do
30
+ output do
31
31
  from :puppetclass do
32
32
  field :name, "Puppet class"
33
33
  field :id, "Class Id", Fields::Id
34
34
  end
35
35
  end
36
- end
36
+ end
37
37
 
38
38
  class SmartClassParameter < HammerCLI::Apipie::Command
39
39
 
@@ -63,7 +63,7 @@ module HammerCLIForeman
63
63
  label "Value" do
64
64
  field :id, 'Id'
65
65
  field :match, 'Match'
66
- field :value, 'Value'
66
+ field :value, 'Value'
67
67
  end
68
68
  end
69
69
  end
@@ -71,9 +71,8 @@ module HammerCLIForeman
71
71
  field :updated_at, "Updated at", Fields::Date
72
72
  end
73
73
 
74
- def retrieve_data
75
- res = super['smart_class_parameter']
76
- res['override_value_order'] = res['override_value_order'].split("\n")
74
+ def extend_data(res)
75
+ res['override_value_order'] = res['override_value_order'].split("\n")
77
76
  res['_environments'] = res['environments'].map { |e| e['environment']['name']}
78
77
  res['_environment_ids'] = res['environments'].map { |e| e['environment']['id']}
79
78
  res
@@ -13,11 +13,9 @@ module HammerCLIForeman
13
13
 
14
14
  #FIXME: search by unknown type returns 500 from the server, propper error handling should resove this
15
15
  output do
16
- from "smart_proxy" do
17
- field :id, "Id"
18
- field :name, "Name"
19
- field :url, "URL"
20
- end
16
+ field :id, "Id"
17
+ field :name, "Name"
18
+ field :url, "URL"
21
19
  end
22
20
 
23
21
  apipie_options
@@ -28,18 +26,15 @@ module HammerCLIForeman
28
26
 
29
27
  action :show
30
28
 
31
- def retrieve_data
32
- sp = super
33
- sp['smart_proxy']['_features'] = sp['smart_proxy']['features'].map { |f| f['feature']['name'] }
34
- sp
29
+ output ListCommand.output_definition do
30
+ field :_features, "Features", Fields::List
31
+ field :created_at, "Created at", Fields::Date
32
+ field :updated_at, "Updated at", Fields::Date
35
33
  end
36
34
 
37
- output ListCommand.output_definition do
38
- from "smart_proxy" do
39
- field :_features, "Features", Fields::List
40
- field :created_at, "Created at", Fields::Date
41
- field :updated_at, "Updated at", Fields::Date
42
- end
35
+ def extend_data(proxy)
36
+ proxy['_features'] = proxy['features'].map { |f| f['feature']['name'] }
37
+ proxy
43
38
  end
44
39
 
45
40
  end
@@ -57,7 +52,7 @@ module HammerCLIForeman
57
52
 
58
53
 
59
54
  class UpdateCommand < HammerCLIForeman::UpdateCommand
60
-
55
+
61
56
  action :update
62
57
 
63
58
  success_message "Smart proxy updated"
@@ -97,7 +92,6 @@ module HammerCLIForeman
97
92
  end
98
93
  end
99
94
 
100
-
101
95
  autoload_subcommands
102
96
  end
103
97
 
@@ -9,12 +9,10 @@ module HammerCLIForeman
9
9
  resource ForemanApi::Resources::Subnet, "index"
10
10
 
11
11
  output do
12
- from "subnet" do
13
- field :id, "Id"
14
- field :name, "Name"
15
- field :network, "Network"
16
- field :mask, "Mask"
17
- end
12
+ field :id, "Id"
13
+ field :name, "Name"
14
+ field :network, "Network"
15
+ field :mask, "Mask"
18
16
  end
19
17
 
20
18
  apipie_options
@@ -26,21 +24,19 @@ module HammerCLIForeman
26
24
  resource ForemanApi::Resources::Subnet, "show"
27
25
 
28
26
  output ListCommand.output_definition do
29
- from "subnet" do
30
- field :priority, "Priority"
31
- field :dns, "DNS", Fields::Server
32
- field :dns_primary, "Primary DNS"
33
- field :dns_secondary, "Secondary DNS"
34
- field :domain_ids, "Domain ids", Fields::List
35
- field :tftp, "TFTP", Fields::Server
36
- field :tftp_id, "TFTP id"
37
- field :dhcp, "DHCP", Fields::Server
38
- field :dhcp_id, "DHCP id"
39
- field :vlanid, "vlan id"
40
- field :gateway, "Gateway"
41
- field :from, "From"
42
- field :to, "To"
43
- end
27
+ field :priority, "Priority"
28
+ field :dns, "DNS", Fields::Server
29
+ field :dns_primary, "Primary DNS"
30
+ field :dns_secondary, "Secondary DNS"
31
+ field :domain_ids, "Domain ids", Fields::List
32
+ field :tftp, "TFTP", Fields::Server
33
+ field :tftp_id, "TFTP id"
34
+ field :dhcp, "DHCP", Fields::Server
35
+ field :dhcp_id, "DHCP id"
36
+ field :vlanid, "vlan id"
37
+ field :gateway, "Gateway"
38
+ field :from, "From"
39
+ field :to, "To"
44
40
  end
45
41
 
46
42
  end
@@ -12,22 +12,18 @@ module HammerCLIForeman
12
12
  class ListCommand < HammerCLIForeman::ListCommand
13
13
 
14
14
  output do
15
- from "config_template" do
16
- field :id, "Id"
17
- field :name, "Name"
18
- field :type, "Type"
19
- end
15
+ field :id, "Id"
16
+ field :name, "Name"
17
+ field :type, "Type"
20
18
  end
21
19
 
22
- def retrieve_data
23
- templates = super
24
- templates.each do |tpl|
25
- if tpl["config_template"]["snippet"]
26
- tpl["config_template"]["type"] = "snippet"
27
- else
28
- tpl["config_template"]["type"] = tpl["config_template"]["template_kind"]["name"] if tpl["config_template"]["template_kind"]
29
- end
20
+ def extend_data(tpl)
21
+ if tpl["snippet"]
22
+ tpl["type"] = "snippet"
23
+ else
24
+ tpl["type"] = tpl["template_kind"]["name"] if tpl["template_kind"]
30
25
  end
26
+ tpl
31
27
  end
32
28
 
33
29
  apipie_options
@@ -41,19 +37,16 @@ module HammerCLIForeman
41
37
  identifiers :id
42
38
 
43
39
  output ListCommand.output_definition do
44
- from "config_template" do
45
- field :operatingsystem_ids, "OS ids", Fields::List
46
- end
40
+ field :operatingsystem_ids, "OS ids", Fields::List
47
41
  end
48
42
 
49
- def retrieve_data
50
- template = super
51
- if template["config_template"]["snippet"]
52
- template["config_template"]["type"] = "snippet"
43
+ def extend_data(tpl)
44
+ if tpl["snippet"]
45
+ tpl["type"] = "snippet"
53
46
  else
54
- template["config_template"]["type"] = template["config_template"]["template_kind"]["name"]
47
+ tpl["type"] = tpl["template_kind"]["name"] if tpl["template_kind"]
55
48
  end
56
- template
49
+ tpl
57
50
  end
58
51
 
59
52
  end
@@ -65,14 +58,13 @@ module HammerCLIForeman
65
58
  desc "List available config template kinds."
66
59
 
67
60
  output do
68
- from "template_kind" do
69
- field :name, "Name"
70
- end
61
+ field :name, "Name"
71
62
  end
72
63
 
73
64
  def retrieve_data
74
- snippet = { "template_kind" => { "name" => "snippet" }}
75
- super << snippet
65
+ kinds = super
66
+ kinds << { "name" => "snippet" }
67
+ kinds
76
68
  end
77
69
 
78
70
  resource ForemanApi::Resources::TemplateKind, "index"
@@ -87,7 +79,7 @@ module HammerCLIForeman
87
79
  identifiers :id
88
80
 
89
81
  def print_data(template)
90
- puts template["config_template"]["template"]
82
+ puts template["template"]
91
83
  end
92
84
 
93
85
  end
@@ -107,8 +99,9 @@ module HammerCLIForeman
107
99
  end
108
100
 
109
101
  def template_kind_id
110
- kinds = ForemanApi::Resources::TemplateKind.new(resource_config).index()[0]
111
- table = kinds.inject({}){ |result, k| result.update(k["template_kind"]["name"] => k["template_kind"]["id"]) }
102
+ kinds = HammerCLIForeman.collection_to_common_format(
103
+ ForemanApi::Resources::TemplateKind.new(resource_config).index()[0])
104
+ table = kinds.inject({}){ |result, k| result.update(k["name"] => k["id"]) }
112
105
  table[type]
113
106
  end
114
107
 
@@ -132,8 +125,9 @@ module HammerCLIForeman
132
125
  end
133
126
 
134
127
  def template_kind_id
135
- kinds = ForemanApi::Resources::TemplateKind.new(resource_config).index()[0]
136
- table = kinds.inject({}){ |result, k| result.update(k["template_kind"]["name"] => k["template_kind"]["id"]) }
128
+ kinds = HammerCLIForeman.collection_to_common_format(
129
+ ForemanApi::Resources::TemplateKind.new(resource_config).index()[0])
130
+ table = kinds.inject({}){ |result, k| result.update(k["name"] => k["id"]) }
137
131
  table[type]
138
132
  end
139
133
 
@@ -154,6 +148,7 @@ module HammerCLIForeman
154
148
 
155
149
 
156
150
  autoload_subcommands
151
+
157
152
  end
158
153
 
159
154
  end
@@ -4,25 +4,21 @@ require 'hammer_cli_foreman/commands'
4
4
 
5
5
  module HammerCLIForeman
6
6
 
7
- class User < HammerCLI::AbstractCommand
7
+ class User < HammerCLI::Apipie::Command
8
+ resource ForemanApi::Resources::User
9
+
8
10
  class ListCommand < HammerCLIForeman::ListCommand
9
- resource ForemanApi::Resources::User, "index"
10
-
11
- def retrieve_data
12
- data = super
13
- data.map do |d|
14
- d["user"]["full_name"] = [d["user"]["firstname"], d["user"]["lastname"]].join(' ')
15
- d
16
- end
17
- end
18
11
 
19
12
  output do
20
- from "user" do
21
- field :id, "Id"
22
- field :login, "Login"
23
- field :full_name, "Name"
24
- field :mail, "Email"
25
- end
13
+ field :id, "Id"
14
+ field :login, "Login"
15
+ field :full_name, "Name"
16
+ field :mail, "Email"
17
+ end
18
+
19
+ def extend_data(user)
20
+ user["full_name"] = [user["firstname"], user["lastname"]].join(' ')
21
+ user
26
22
  end
27
23
 
28
24
  apipie_options
@@ -31,21 +27,17 @@ module HammerCLIForeman
31
27
 
32
28
  class InfoCommand < HammerCLIForeman::InfoCommand
33
29
 
34
- resource ForemanApi::Resources::User, "show"
35
30
  identifiers :id
36
31
 
37
- def retrieve_data
38
- data = super
39
- data["user"]["full_name"] = [data["user"]["firstname"], data["user"]["lastname"]].join(' ')
40
- data
32
+ output ListCommand.output_definition do
33
+ field :last_login_on, "Last login", Fields::Date
34
+ field :created_at, "Created at", Fields::Date
35
+ field :updated_at, "Updated at", Fields::Date
41
36
  end
42
37
 
43
- output ListCommand.output_definition do
44
- from "user" do
45
- field :last_login_on, "Last login", Fields::Date
46
- field :created_at, "Created at", Fields::Date
47
- field :updated_at, "Updated at", Fields::Date
48
- end
38
+ def extend_data(user)
39
+ user["full_name"] = [user["firstname"], user["lastname"]].join(' ')
40
+ user
49
41
  end
50
42
 
51
43
  end