hammer_cli_foreman 0.0.10 → 0.0.11

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 (46) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +27 -0
  3. data/doc/host_create.md +190 -0
  4. data/lib/hammer_cli_foreman.rb +1 -0
  5. data/lib/hammer_cli_foreman/commands.rb +21 -7
  6. data/lib/hammer_cli_foreman/common_parameter.rb +12 -18
  7. data/lib/hammer_cli_foreman/domain.rb +8 -6
  8. data/lib/hammer_cli_foreman/environment.rb +10 -0
  9. data/lib/hammer_cli_foreman/exception_handler.rb +11 -1
  10. data/lib/hammer_cli_foreman/exceptions.rb +9 -0
  11. data/lib/hammer_cli_foreman/host.rb +107 -16
  12. data/lib/hammer_cli_foreman/hostgroup.rb +10 -0
  13. data/lib/hammer_cli_foreman/puppet_class.rb +10 -1
  14. data/lib/hammer_cli_foreman/resource_supported_test.rb +3 -3
  15. data/lib/hammer_cli_foreman/smart_class_parameter.rb +110 -0
  16. data/lib/hammer_cli_foreman/version.rb +1 -1
  17. data/test/unit/apipie_resource_mock.rb +88 -0
  18. data/test/unit/architecture_test.rb +91 -0
  19. data/test/unit/common_parameter_test.rb +77 -0
  20. data/test/unit/compute_resource_test.rb +94 -0
  21. data/test/unit/domain_test.rb +130 -0
  22. data/test/unit/environment_test.rb +110 -0
  23. data/test/unit/exception_handler_test.rb +48 -0
  24. data/test/unit/fact_test.rb +31 -0
  25. data/test/unit/helpers/command.rb +69 -0
  26. data/test/unit/helpers/resource_disabled.rb +24 -0
  27. data/test/unit/host_test.rb +315 -0
  28. data/test/unit/hostgroup_test.rb +145 -0
  29. data/test/unit/image_test.rb +136 -0
  30. data/test/unit/location_test.rb +109 -0
  31. data/test/unit/media_test.rb +106 -0
  32. data/test/unit/model_test.rb +98 -0
  33. data/test/unit/operating_system_test.rb +151 -0
  34. data/test/unit/organization_test.rb +109 -0
  35. data/test/unit/output/formatters_test.rb +19 -0
  36. data/test/unit/partition_table_test.rb +143 -0
  37. data/test/unit/puppet_class_test.rb +71 -0
  38. data/test/unit/report_test.rb +64 -0
  39. data/test/unit/smart_class_parameter_test.rb +77 -0
  40. data/test/unit/smart_proxy_test.rb +102 -0
  41. data/test/unit/subnet_test.rb +95 -0
  42. data/test/unit/template_test.rb +141 -0
  43. data/test/unit/test_helper.rb +27 -0
  44. data/test/unit/test_output_adapter.rb +19 -0
  45. data/test/unit/user_test.rb +92 -0
  46. metadata +107 -29
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3108251968e9b35a4e1a1ee37bf744bb08f1e383
4
- data.tar.gz: 48d434939e0033fe7d593dd21eb03b168f33dfba
3
+ metadata.gz: 42450c6d2fad76c1f31ea6a860406c4a6511ccd8
4
+ data.tar.gz: d6b26b6896df8cd1db9b2f4e8d3f5a037d145167
5
5
  SHA512:
6
- metadata.gz: c4e6d4167fc2916eb970123f97bd41f62eb0751c929b2392d448ab324fef651cbcbfb4ff7f54847be4c44716941d66bafd44a7e627f29a2fcf8438a32eb5f98a
7
- data.tar.gz: 7a13a75d06913975322d17dca8411c70401571eede40e84fc00f01630391a24af8aba1ce26fc4ed5959ada591037ccd5edf4f466db4f7ba94b981cf78133a34e
6
+ metadata.gz: fa6ed7e0730233e68b0ee1c4894905a34b6352a9225f73536830ab993dfc9606454339e70173cbb20f122c0b258e2dde6b0e39a173df7f5b92e1c1435433378c
7
+ data.tar.gz: 34c6dc5106bf9d507927600b20c778e6272cf4a24d15eda085b25ac5aedfd6eb0b0d7891aaf5fea92fd482525a2da145e5c9c690417be3797c96111db85a8211
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ Foreman commands for Hammer CLI
2
+ ===============================
3
+
4
+ This Hammer CLI plugin contains set of commands for [Foreman](http://theforeman.org/).
5
+
6
+
7
+ Documentation
8
+ -------------
9
+
10
+ - [Host creation](doc/host_create.md#host-creation)
11
+
12
+ How to run
13
+ ----------
14
+
15
+ The work is still in progress and there are no builds ready yet. You can install the plugin from source.
16
+ See [Hammer CLI readme](https://github.com/theforeman/hammer-cli/blob/master/README.md#how-to-run) for details.
17
+
18
+
19
+ How to test
20
+ ------------
21
+
22
+ $ bundle install
23
+ $ bundle exec "rake test"
24
+
25
+ Generated coverage reports are stored in ./coverage directory.
26
+
27
+
@@ -0,0 +1,190 @@
1
+ Host Creation
2
+ =============
3
+
4
+ Host creation is one of the most complex commands in the hammer's foreman plugin. The majority of its parameters
5
+ is obvious but there are some that need further explanation as their values differ with the type of a compute resource.
6
+
7
+ ```
8
+ $ hammer host create -h
9
+ Usage:
10
+ hammer host create [OPTIONS]
11
+
12
+ Options:
13
+ --name NAME
14
+ --ip IP Not required if using a subnet with dhcp proxy.
15
+ --mac MAC Not required if it's a virtual machine.
16
+ --puppet-class-ids PUPPET_CLASS_IDS Comma separated list of values.
17
+ --medium-id MEDIUM_ID
18
+ --subnet-id SUBNET_ID
19
+ --sp-subnet-id SP_SUBNET_ID
20
+ --model-id MODEL_ID
21
+ --hostgroup-id HOSTGROUP_ID
22
+ --owner-id OWNER_ID
23
+ --puppet-ca-proxy-id PUPPET_CA_PROXY_ID
24
+ --security-groups SECURITY_GROUPS
25
+ --environment-id ENVIRONMENT_ID
26
+ --architecture-id ARCHITECTURE_ID
27
+ --domain-id DOMAIN_ID
28
+ --puppet-proxy-id PUPPET_PROXY_ID
29
+ --operatingsystem-id OPERATINGSYSTEM_ID
30
+ --partition-table-id PARTITION_TABLE_ID
31
+ --compute-resource-id COMPUTE_RESOURCE
32
+ --partition-table-id PARTITION_TABLE
33
+ --build BUILD One of true/false, yes/no, 1/0.
34
+ Default: "true"
35
+ --managed MANAGED One of true/false, yes/no, 1/0.
36
+ Default: "true"
37
+ --enabled ENABLED One of true/false, yes/no, 1/0.
38
+ Default: "true"
39
+ --parameters PARAMS Host parameters.
40
+ Comma-separated list of key=value.
41
+ --compute-attributes COMPUTE_ATTRS Compute resource attributes.
42
+ Comma-separated list of key=value.
43
+ --volume VOLUME Volume parameters
44
+ Comma-separated list of key=value.
45
+ Can be specified multiple times.
46
+ --interface INTERFACE Interface parameters.
47
+ Comma-separated list of key=value.
48
+ Can be specified multiple times.
49
+ -h, --help print help
50
+ ```
51
+
52
+ Example
53
+ =======
54
+
55
+ An example command for creating a host with 2 volumes (5GB raw + 10 GB qcow2) using
56
+ a default network interface on a libvirt provider can look like this:
57
+ ```bash
58
+ hammer host create
59
+ --hostgroup-id=4 # most of the settings is done in the hostgroup
60
+ --compute-resource-id=1 # set the libvirt provider
61
+ --compute-attributes="cpus=2" # specify the provider specific options, see the list below
62
+ --interface="type=network,network=default" # add a network interface, can be passed multiple times
63
+ --volume="capacity=5G" # add a volume, can be passed multiple times
64
+ --volume="capacity=10G,format_type=qcow2" # add another volume with different size and type
65
+ --name="test-host"
66
+ --ip="1.2.3.4"
67
+ ```
68
+
69
+ See the list of all possible option keys below.
70
+
71
+
72
+ Provider specific options
73
+ =========================
74
+
75
+ ## Bare Metal
76
+ Available keys for `--interface`:
77
+ ```
78
+ type # one of Nic::Managed, Nic::BMC
79
+ mac
80
+ name
81
+ domain_id
82
+ subnet_id
83
+ ip
84
+ provider # always IPMI
85
+ username # BMC only
86
+ password # BMC only
87
+ ```
88
+
89
+ ## EC2
90
+ Available keys for `--compute-attributes`:
91
+ ```
92
+ flavor_id # select one of available flavours
93
+ image_id # select one of available images
94
+ availability_zone
95
+ security_group_ids
96
+ managed_ip
97
+ ```
98
+
99
+ ## GCE
100
+ Available keys for `--compute-attributes`:
101
+ ```
102
+ machine_type # one of available flavors
103
+ image_id
104
+ network
105
+ external_ip
106
+ ```
107
+
108
+ ## Libvirt
109
+ Available keys for `--compute-attributes`:
110
+ ```
111
+ cpus # number of CPUs
112
+ memory # string, amount of memory, value in bytes
113
+ start # boolean, whether to start the machine or not
114
+ ```
115
+
116
+ Available keys for `--interface`:
117
+ ```
118
+ type # one of [:bridge, :network]
119
+ network / :bridge # name of interface according to type
120
+ model # one of [virtio, rtl8139, ne2k_pci, pcnet, e1000]
121
+ ```
122
+
123
+ Available keys for `--volume`:
124
+ ```
125
+ pool_name # list of available storage pools
126
+ capacity # string value, eg. 10G
127
+ format_type # one of [raw, qcow2]
128
+ ```
129
+
130
+ ## OpenStack
131
+ Available keys for `--compute-attributes`:
132
+ ```
133
+ flavor_ref
134
+ image_ref
135
+ tenant_id
136
+ security_groups
137
+ network
138
+ ```
139
+
140
+ ## oVirt
141
+ Available keys for `--compute-attributes`:
142
+ ```
143
+ cluster
144
+ template # hardware profile to use
145
+ cores # int value, number of cores
146
+ memory # amount of memory, int value in bytes
147
+ start # boolean, whether to start the machine or not
148
+ ```
149
+
150
+ Available keys for `--interface`:
151
+ ```
152
+ name # eg. eth0
153
+ network # select one of available networks for a cluster
154
+ ```
155
+
156
+ Available keys for `--volume`:
157
+ ```
158
+ size_gb # volume size in GB, integer value
159
+ storage_domain # select one of available storage domains
160
+ bootable # boolean, only one volume can be bootable
161
+ ```
162
+
163
+ ## Rackspace
164
+ Available keys for `--compute-attributes`:
165
+ ```
166
+ flavor_id
167
+ image_id
168
+ ```
169
+
170
+ ## vmWare
171
+ Available keys for `--compute-attributes`:
172
+ ```
173
+ cpus # cpu count
174
+ memory_mb # integer number
175
+ cluster
176
+ path
177
+ ```
178
+
179
+ Available keys for `--interface`:
180
+ ```
181
+ network
182
+ ```
183
+
184
+ Available keys for `--volume`:
185
+ ```
186
+ datastore
187
+ name
188
+ size_gb # integer number
189
+ ```
190
+
@@ -28,6 +28,7 @@ module HammerCLIForeman
28
28
  require 'hammer_cli_foreman/report'
29
29
  require 'hammer_cli_foreman/puppet_class'
30
30
  require 'hammer_cli_foreman/smart_proxy'
31
+ require 'hammer_cli_foreman/smart_class_parameter'
31
32
  require 'hammer_cli_foreman/subnet'
32
33
  require 'hammer_cli_foreman/template'
33
34
  require 'hammer_cli_foreman/user'
@@ -2,6 +2,20 @@ require 'hammer_cli'
2
2
 
3
3
  module HammerCLIForeman
4
4
 
5
+ class WriteCommand < HammerCLI::Apipie::WriteCommand
6
+
7
+ def success_message_params(response)
8
+ if response
9
+ if response.is_a?(Hash) and !response.empty?
10
+ response[response.keys[0]]
11
+ else
12
+ response
13
+ end
14
+ end
15
+ end
16
+
17
+ end
18
+
5
19
  class ListCommand < HammerCLI::Apipie::ReadCommand
6
20
 
7
21
  action :index
@@ -19,7 +33,7 @@ module HammerCLIForeman
19
33
 
20
34
  class InfoCommand < HammerCLI::Apipie::ReadCommand
21
35
 
22
- action :show
36
+ action :show
23
37
 
24
38
  def self.command_name(name=nil)
25
39
  super(name) || "info"
@@ -38,7 +52,7 @@ module HammerCLIForeman
38
52
  end
39
53
 
40
54
 
41
- class CreateCommand < HammerCLI::Apipie::WriteCommand
55
+ class CreateCommand < WriteCommand
42
56
 
43
57
  action :create
44
58
 
@@ -49,7 +63,7 @@ module HammerCLIForeman
49
63
  end
50
64
 
51
65
 
52
- class UpdateCommand < HammerCLI::Apipie::WriteCommand
66
+ class UpdateCommand < WriteCommand
53
67
 
54
68
  action :update
55
69
 
@@ -77,7 +91,7 @@ module HammerCLIForeman
77
91
  end
78
92
 
79
93
 
80
- class DeleteCommand < HammerCLI::Apipie::WriteCommand
94
+ class DeleteCommand < WriteCommand
81
95
 
82
96
  action :destroy
83
97
 
@@ -98,7 +112,7 @@ module HammerCLIForeman
98
112
  end
99
113
 
100
114
 
101
- class AssociatedCommand < HammerCLI::Apipie::WriteCommand
115
+ class AssociatedCommand < WriteCommand
102
116
 
103
117
  identifiers :name, :id
104
118
  action :update
@@ -175,7 +189,7 @@ module HammerCLIForeman
175
189
  class AddAssociatedCommand < AssociatedCommand
176
190
 
177
191
  def self.command_name(name=nil)
178
- super(name) || "add_"+associated_resource.name
192
+ super(name) || (associated_resource ? "add_"+associated_resource.name : nil)
179
193
  end
180
194
 
181
195
  def self.desc(desc=nil)
@@ -195,7 +209,7 @@ module HammerCLIForeman
195
209
  class RemoveAssociatedCommand < AssociatedCommand
196
210
 
197
211
  def self.command_name(name=nil)
198
- super(name) || "remove_"+associated_resource.name
212
+ super(name) || (associated_resource ? "remove_"+associated_resource.name : nil)
199
213
  end
200
214
 
201
215
  def self.desc(desc=nil)
@@ -19,36 +19,30 @@ module HammerCLIForeman
19
19
  apipie_options
20
20
  end
21
21
 
22
- class SetCommand < HammerCLI::Apipie::WriteCommand
22
+ class SetCommand < HammerCLIForeman::WriteCommand
23
23
 
24
24
  command_name "set"
25
25
  desc "Set a global parameter."
26
26
 
27
+ success_message_for :create, "Created parameter [%{name}s] with value [%{value}s]."
28
+ success_message_for :update, "Parameter [%{name}s] updated to [%{value}s]."
29
+
27
30
  resource ForemanApi::Resources::CommonParameter
28
31
 
29
32
  option "--name", "NAME", "parameter name", :required => true
30
33
  option "--value", "VALUE", "parameter value", :required => true
31
34
 
32
- def execute
33
- if parameter_exist?
34
- self.class.action :update
35
- else
36
- self.class.action :create
37
- end
38
- super
35
+ def action
36
+ @action ||= parameter_exist? ? :update : :create
37
+ @action
39
38
  end
40
39
 
41
- def print_message
42
- if self.class.action == :create
43
- msg = "Global parameter created"
44
- else
45
- msg = "Global parameter updated"
46
- end
47
- print_message msg
40
+ def success_message
41
+ success_message_for(action)
48
42
  end
49
43
 
50
44
  def parameter_exist?
51
- params = resource.index(resource_config)[0]
45
+ params = resource.call(:index)[0]
52
46
  params.find { |p| p["common_parameter"]["name"] == name }
53
47
  end
54
48
 
@@ -65,8 +59,8 @@ module HammerCLIForeman
65
59
 
66
60
  identifiers :name
67
61
 
68
- success_message "Global parameter deleted"
69
- failure_message "Could not delete the global parameter"
62
+ success_message "Global parameter [%{name}s] deleted."
63
+ failure_message "Could not delete the global parameter [%{name}s]"
70
64
  resource ForemanApi::Resources::CommonParameter, "destroy"
71
65
 
72
66
  apipie_options :without => :id
@@ -32,7 +32,7 @@ module HammerCLIForeman
32
32
 
33
33
  output ListCommand.output_definition do
34
34
  from "domain" do
35
- field :fullname, "Full Name"
35
+ field :fullname, "Description"
36
36
  field :dns_id, "DNS Id"
37
37
  field :created_at, "Created at", Fields::Date
38
38
  field :updated_at, "Updated at", Fields::Date
@@ -47,27 +47,29 @@ module HammerCLIForeman
47
47
 
48
48
  class CreateCommand < HammerCLIForeman::CreateCommand
49
49
 
50
- success_message "Domain created"
50
+ success_message "Domain [%{name}s] created"
51
51
  failure_message "Could not create the domain"
52
52
  resource ForemanApi::Resources::Domain, "create"
53
53
 
54
- apipie_options :without => ['domain_parameters_attributes']
54
+ apipie_options :without => [:domain_parameters_attributes, :fullname]
55
+ option "--description", "DESC", "Full name describing the domain", :attribute_name => :fullname
55
56
  end
56
57
 
57
58
 
58
59
  class UpdateCommand < HammerCLIForeman::UpdateCommand
59
60
 
60
- success_message "Domain updated"
61
+ success_message "Domain [%{name}s] updated"
61
62
  failure_message "Could not update the domain"
62
63
  resource ForemanApi::Resources::Domain, "update"
63
64
 
64
- apipie_options :without => ['domain_parameters_attributes', 'name', 'id']
65
+ apipie_options :without => [:domain_parameters_attributes, :name, :id, :fullname]
66
+ option "--description", "DESC", "Full name describing the domain", :attribute_name => :fullname
65
67
  end
66
68
 
67
69
 
68
70
  class DeleteCommand < HammerCLIForeman::DeleteCommand
69
71
 
70
- success_message "Domain deleted"
72
+ success_message "Domain [%{name}s] deleted"
71
73
  failure_message "Could not delete the domain"
72
74
  resource ForemanApi::Resources::Domain, "destroy"
73
75
 
@@ -1,5 +1,7 @@
1
1
  require 'hammer_cli'
2
2
  require 'foreman_api'
3
+ require 'hammer_cli_foreman/smart_class_parameter'
4
+
3
5
 
4
6
  module HammerCLIForeman
5
7
 
@@ -61,6 +63,14 @@ module HammerCLIForeman
61
63
  apipie_options
62
64
  end
63
65
 
66
+ class SCParamsCommand < HammerCLIForeman::SmartClassParametersList
67
+
68
+ apipie_options :without => [:host_id, :hostgroup_id, :puppetclass_id, :environment_id]
69
+ option ['--id', '--name'], 'ENVIRONMENT_ID', 'environment id/name',
70
+ :required => true, :attribute_name => :environment_id
71
+ end
72
+
73
+
64
74
  autoload_subcommands
65
75
  end
66
76