hammer_cli_foreman 2.0.2 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/doc/developer_docs.md +1 -0
  3. data/doc/plugin.md +22 -0
  4. data/doc/release_notes.md +20 -4
  5. data/lib/hammer_cli_foreman.rb +8 -0
  6. data/lib/hammer_cli_foreman/api/oauth/authentication_code_grant.rb +7 -4
  7. data/lib/hammer_cli_foreman/associating_commands.rb +33 -5
  8. data/lib/hammer_cli_foreman/auth.rb +6 -6
  9. data/lib/hammer_cli_foreman/bookmark.rb +50 -0
  10. data/lib/hammer_cli_foreman/command_extensions.rb +2 -0
  11. data/lib/hammer_cli_foreman/command_extensions/puppet_environment.rb +13 -7
  12. data/lib/hammer_cli_foreman/command_extensions/puppet_environments.rb +13 -7
  13. data/lib/hammer_cli_foreman/command_extensions/subnet.rb +25 -0
  14. data/lib/hammer_cli_foreman/command_extensions/user.rb +17 -0
  15. data/lib/hammer_cli_foreman/commands.rb +14 -9
  16. data/lib/hammer_cli_foreman/compute_resource.rb +15 -0
  17. data/lib/hammer_cli_foreman/compute_resource/ec2.rb +11 -0
  18. data/lib/hammer_cli_foreman/compute_resource/gce.rb +9 -0
  19. data/lib/hammer_cli_foreman/compute_resource/libvirt.rb +11 -0
  20. data/lib/hammer_cli_foreman/compute_resource/openstack.rb +7 -0
  21. data/lib/hammer_cli_foreman/compute_resource/ovirt.rb +21 -9
  22. data/lib/hammer_cli_foreman/compute_resource/vmware.rb +15 -2
  23. data/lib/hammer_cli_foreman/hostgroup.rb +11 -19
  24. data/lib/hammer_cli_foreman/hosts/common_update_options.rb +32 -10
  25. data/lib/hammer_cli_foreman/id_resolver.rb +12 -11
  26. data/lib/hammer_cli_foreman/mail_notification.rb +31 -0
  27. data/lib/hammer_cli_foreman/option_builders.rb +70 -48
  28. data/lib/hammer_cli_foreman/option_sources.rb +1 -0
  29. data/lib/hammer_cli_foreman/option_sources/referenced_resource_id_params.rb +47 -0
  30. data/lib/hammer_cli_foreman/subnet.rb +26 -15
  31. data/lib/hammer_cli_foreman/task_helper.rb +180 -0
  32. data/lib/hammer_cli_foreman/user.rb +3 -17
  33. data/lib/hammer_cli_foreman/version.rb +1 -1
  34. data/lib/hammer_cli_foreman/virtual_machine.rb +55 -0
  35. data/locale/ca/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  36. data/locale/de/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  37. data/locale/en/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  38. data/locale/en_GB/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  39. data/locale/es/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  40. data/locale/fr/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  41. data/locale/it/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  42. data/locale/ja/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  43. data/locale/ko/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  44. data/locale/pt_BR/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  45. data/locale/ru/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  46. data/locale/zh_CN/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  47. data/locale/zh_TW/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  48. data/test/data/2.1/foreman_api.json +1 -0
  49. data/test/functional/associating_commands_test.rb +134 -30
  50. data/test/functional/bookmark_test.rb +193 -0
  51. data/test/functional/host_test.rb +27 -1
  52. data/test/functional/mail_notification_test.rb +57 -0
  53. data/test/functional/subnet/create_test.rb +28 -5
  54. data/test/functional/template_test.rb +2 -2
  55. data/test/functional/virtual_machine_test.rb +129 -0
  56. data/test/test_helper.rb +1 -1
  57. metadata +23 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb9fbae8eb789656dd8557891ccafe9b1a29fcd1bc3d11707b69d548466734fc
4
- data.tar.gz: 4a97eeabaa13b2b7b5b42f464684fee2e7d5f6d0e926e494610131612af7bdba
3
+ metadata.gz: 4db93fb25a95e818a8b0b9fdaab9ab8760cc7f42c2607661e99ec4bb990815d4
4
+ data.tar.gz: d2187c023afc8dd80ae0247b53475354913950f1416e5f8bc308a48388e807fe
5
5
  SHA512:
6
- metadata.gz: de79bacffe1e4629244df7d1ba449bb05d9eff56e41035a85ed9e1f22e9cc53a9c5a1bd66f531c0582b18b8276894879fb12dcae7adbba571c414af92d553733
7
- data.tar.gz: cb4707c53325b8103202faf2f28dec768f8f364c71113e694d2cc34ed7942ce3ae8e457aa3a1aa1f2053de7d9d529c1fbc60bc6f8400e52979a1a6d0a1f6cbc4
6
+ metadata.gz: ac00a2af523db5f7cf5c881273f715128fbc1df82604ecd01bf6c06b95a09963fac84e76c79260b77908925f38e4864ace72a8f3b31f4b1e60179b8b89b716d6
7
+ data.tar.gz: 5300260e5c63d59ba8971dd784bb5f1e23a18a2de5b1611be02204c8a6b670368678742d8fa60815118b0f3b50127a4db92c599fb797d4bf045deb6ed366d263
@@ -10,6 +10,7 @@ Foreman plugin extends the Hammer Core in following areas:
10
10
  - [Building options](option_builder.md#option-builders)
11
11
  - [Automatic name resolution](name_id_resolution.md#name-to-id-resolution)
12
12
  - [Testing commands](testing.md#testing-hammer-commands)
13
+ - [Writing a plugin](plugin.md#writing-a-plugin)
13
14
 
14
15
  It's recommended that you set `:refresh_cache: true` in the plugin settings if
15
16
  engaging in API development to enable aggressive apidoc cache checking.
data/doc/plugin.md ADDED
@@ -0,0 +1,22 @@
1
+ # Writing a plugin
2
+
3
+ ### Basic
4
+
5
+ If you want to create a plugin for hammer-cli-foreman, you might want to create
6
+ a simple draft at first.
7
+
8
+ To do so, just run the following:
9
+ ```
10
+ # You will need to checkout this repository first if you don't have it already
11
+ $ git checkout https://github.com/theforeman/hammer-cli-foreman.git
12
+ $ cd hammer-cli-foreman
13
+ $ rake plugin:draft
14
+ # fill prompts
15
+ ```
16
+ This will create a directory called `hammer-cli-foreman-prompted-name` with
17
+ basic structure where you can put your code afterwards. Please, don't forget to
18
+ take a look at `TODO`s as there might be places you want to change or adjust to
19
+ your needs first.
20
+
21
+ For more information, please see: https://github.com/theforeman/hammer-cli/blob/master/doc/developer_docs.md
22
+ as well as https://github.com/theforeman/hammer-cli-foreman/blob/master/doc/developer_docs.md
data/doc/release_notes.md CHANGED
@@ -1,10 +1,26 @@
1
1
  Release notes
2
2
  =============
3
- ### 2.0.2 (2020-03-24)
3
+ ### 2.1.0 (2020-05-14)
4
+ * Bump hammer_cli to 2.1.0 ([PR #519](https://github.com/theforeman/hammer-cli-foreman/pull/519))
5
+ * Ask for oauth code only when needed ([PR #517](https://github.com/theforeman/hammer-cli-foreman/pull/517)), [#29635](http://projects.theforeman.org/issues/29635)
6
+ * Possibility to create ipv6 subnet, [#28760](http://projects.theforeman.org/issues/28760)
7
+ * Add the ability to manage bookmarks ([PR #510](https://github.com/theforeman/hammer-cli-foreman/pull/510)), [#12845](http://projects.theforeman.org/issues/12845)
8
+ * Add aliases for info/list/delete commands ([PR #512](https://github.com/theforeman/hammer-cli-foreman/pull/512)), [#29413](http://projects.theforeman.org/issues/29413)
9
+ * Help contains squeezed options ([PR #489](https://github.com/theforeman/hammer-cli-foreman/pull/489)), [#28440](http://projects.theforeman.org/issues/28440)
10
+ * Add cr to hostgroup info, [#29140](http://projects.theforeman.org/issues/29140)
11
+ * Add rake task with plugin template
12
+ * Added virtual machine command for compute resource ([PR #469](https://github.com/theforeman/hammer-cli-foreman/pull/469)), [#20451](http://projects.theforeman.org/issues/20451)
13
+ * Add display options to host creation on ovirt ([PR #507](https://github.com/theforeman/hammer-cli-foreman/pull/507)), [#29254](http://projects.theforeman.org/issues/29254)
14
+ * Add mail notification command ([PR #509](https://github.com/theforeman/hammer-cli-foreman/pull/509)), [#29326](http://projects.theforeman.org/issues/29326)
4
15
  * Use right param for os default template ([PR #508](https://github.com/theforeman/hammer-cli-foreman/pull/508)), [#29274](http://projects.theforeman.org/issues/29274)
5
-
6
- ### 2.0.1 (2020-02-25)
7
- * Remove duplicate api requests on addassociatedcommand ([PR #503](https://github.com/theforeman/hammer-cli-foreman/pull/503)) ([PR #504](https://github.com/theforeman/hammer-cli-foreman/pull/504)), [#29096](http://projects.theforeman.org/issues/29096)
16
+ * Update api docs to 2.1
17
+ * Correct hot add options ([PR #505](https://github.com/theforeman/hammer-cli-foreman/pull/505)), [#29253](http://projects.theforeman.org/issues/29253)
18
+ * Feature #28836 - allow multiple disassociating of provisioning templates ([PR #502](https://github.com/theforeman/hammer-cli-foreman/pull/502)), [#28836](http://projects.theforeman.org/issues/28836)
19
+ * Fixed updating host owner when ownertype is usergroup ([PR #501](https://github.com/theforeman/hammer-cli-foreman/pull/501)), [#11279](http://projects.theforeman.org/issues/11279)
20
+ * Remove duplicate api requests on addassociatedcommand ([PR #503](https://github.com/theforeman/hammer-cli-foreman/pull/503)), [#29096](http://projects.theforeman.org/issues/29096)
21
+ * Fix help for ovirt boolean values, [#29026](http://projects.theforeman.org/issues/29026)
22
+ * Deprecate --root-pass in host group, [#22573](http://projects.theforeman.org/issues/22573)
23
+ * Bump to 2.1.0-develop
8
24
 
9
25
  ### 2.0.0 (2020-02-12)
10
26
  * Change the description of the scoped loc and org ([PR #494](https://github.com/theforeman/hammer-cli-foreman/pull/494)), [#28869](http://projects.theforeman.org/issues/28869)
@@ -11,6 +11,7 @@ module HammerCLIForeman
11
11
  require 'hammer_cli_foreman/i18n'
12
12
 
13
13
  require 'hammer_cli_foreman/version'
14
+ require 'hammer_cli_foreman/task_helper'
14
15
  require 'hammer_cli_foreman/output'
15
16
  require 'hammer_cli_foreman/output/fields'
16
17
  require 'hammer_cli_foreman/exception_handler'
@@ -180,6 +181,13 @@ module HammerCLIForeman
180
181
  HammerCLI::MainCommand.lazy_subcommand('trend', _("Manage trends"),
181
182
  'HammerCLIForeman::Trend', 'hammer_cli_foreman/trend'
182
183
  )
184
+
185
+ HammerCLI::MainCommand.lazy_subcommand('mail-notification', _("Manage mail notifications"),
186
+ 'HammerCLIForeman::MailNotification', 'hammer_cli_foreman/mail_notification'
187
+ )
188
+
189
+ HammerCLI::MainCommand.lazy_subcommand('bookmark', _("Manage bookmarks"),
190
+ 'HammerCLIForeman::Bookmark', 'hammer_cli_foreman/bookmark')
183
191
  rescue => e
184
192
  handler = HammerCLIForeman::ExceptionHandler.new(:context => {}, :adapter => :base)
185
193
  handler.handle_exception(e)
@@ -5,19 +5,22 @@ module HammerCLIForeman
5
5
  module Api
6
6
  module Oauth
7
7
  class AuthenticationCodeGrant < ApipieBindings::Authenticators::TokenAuth
8
- attr_accessor :oidc_token_endpoint, :oidc_authorization_endpoint, :oidc_client_id, :token, :oidc_redirect_uri
8
+ attr_accessor :oidc_token_endpoint, :oidc_authorization_endpoint,
9
+ :oidc_client_id, :token, :oidc_redirect_uri
9
10
 
10
11
  def initialize(oidc_token_endpoint, oidc_authorization_endpoint, oidc_client_id, oidc_redirect_uri)
11
12
  @oidc_token_endpoint = oidc_token_endpoint
12
13
  @oidc_authorization_endpoint = oidc_authorization_endpoint
13
14
  @oidc_client_id = oidc_client_id
14
15
  @oidc_redirect_uri = oidc_redirect_uri
15
- super set_token(oidc_token_endpoint, oidc_authorization_endpoint, oidc_client_id, oidc_redirect_uri)
16
+ super(nil)
16
17
  end
17
18
 
18
19
  def authenticate(request, token)
19
20
  if HammerCLI.interactive?
20
21
  set_token_interactively
22
+ else
23
+ set_token(oidc_token_endpoint, oidc_authorization_endpoint, oidc_client_id, oidc_redirect_uri)
21
24
  end
22
25
  super
23
26
  end
@@ -35,7 +38,7 @@ module HammerCLIForeman
35
38
  if @oidc_client_id.to_s.empty? || @oidc_authorization_endpoint.to_s.empty? || @oidc_redirect_uri.to_s.empty? || @oidc_token_endpoint.to_s.empty?
36
39
  @token = nil
37
40
  else
38
- get_code
41
+ @code ||= get_code
39
42
  @token = HammerCLIForeman::OpenidConnect.new(
40
43
  @oidc_token_endpoint, @oidc_client_id).get_token_via_2fa(@code, @oidc_redirect_uri)
41
44
  end
@@ -68,7 +71,7 @@ module HammerCLIForeman
68
71
  "&redirect_uri=#{@oidc_redirect_uri}"\
69
72
  '&scope=openid'
70
73
  HammerCLI.interactive_output.say("Enter URL in browser: #{@token_url}")
71
- @code ||= ask_user(_("Code:%s") % " ")
74
+ ask_user(_("Code:%s") % " ")
72
75
  end
73
76
 
74
77
  def get_oidc_authorization_endpoint
@@ -245,6 +245,7 @@ module HammerCLIForeman
245
245
  def request_params
246
246
  params = super
247
247
 
248
+ template_ids = params['operatingsystem']['provisioning_template_ids']
248
249
  if options['option_provisioning_template_search']
249
250
  templates = HammerCLIForeman.collection_to_common_format(
250
251
  associated_resource.call(
@@ -255,10 +256,10 @@ module HammerCLIForeman
255
256
 
256
257
  templates.each do |template|
257
258
  template_id = template['id']
258
- params['operatingsystem']['provisioning_template_ids'] << template_id.to_s
259
+ template_ids << template_id.to_s
259
260
  end
260
261
  end
261
- params['operatingsystem']['provisioning_template_ids'] = params['operatingsystem']['provisioning_template_ids'].uniq
262
+ params['operatingsystem']['provisioning_template_ids'] = template_ids.uniq
262
263
  params
263
264
  end
264
265
 
@@ -269,10 +270,37 @@ module HammerCLIForeman
269
270
 
270
271
  class RemoveProvisioningTemplateCommand < HammerCLIForeman::RemoveAssociatedCommand
271
272
  associated_resource :provisioning_templates
272
- desc _("Disassociate a provisioning template")
273
+ desc _("Disassociate provisioning templates")
273
274
 
274
- success_message _("The provisioning template has been disassociated.")
275
- failure_message _("Could not disassociate the provisioning template")
275
+ option "--provisioning-template-ids", "PROVISIONING_TEMPLATE_IDS", _("List of provisioning template ids"),
276
+ format: HammerCLI::Options::Normalizers::List.new
277
+ option "--provisioning-templates", "PROVISIONING_TEMPLATE_NAMES", _("List of provisioning template names"),
278
+ format: HammerCLI::Options::Normalizers::List.new, attribute_name: :option_provisioning_template_names
279
+ option "--provisioning-template-search", "PROVISIONING_TEMPLATE_SEARCH", _("Provisioning template name regex to search, all matching templates will be disassociated")
280
+
281
+ def request_params
282
+ params = super
283
+
284
+ template_ids = params['operatingsystem']['provisioning_template_ids']
285
+ if options['option_provisioning_template_search']
286
+ templates = HammerCLIForeman.collection_to_common_format(
287
+ associated_resource.call(
288
+ :index,
289
+ :search => "name ~ \"#{options['option_provisioning_template_search']}\"")
290
+ )
291
+ raise ResolverError.new(_("%s not found.") % associated_resource.singular_name, associated_resource) if templates.empty?
292
+
293
+ templates.each do |template|
294
+ template_id = template['id']
295
+ template_ids.delete(template_id.to_s)
296
+ end
297
+ end
298
+ params['operatingsystem']['provisioning_template_ids'] = template_ids.uniq
299
+ params
300
+ end
301
+
302
+ success_message _("The provisioning templates were disassociated.")
303
+ failure_message _("Could not disassociate the provisioning templates")
276
304
  end
277
305
  end
278
306
 
@@ -46,16 +46,16 @@ module HammerCLIForeman
46
46
  if option_two_factor?
47
47
  Oauth.execute_with_params(
48
48
  AUTH_TYPES[:oauth_authentication_code_grant],
49
- option_oidc_token_endpoint,
50
- option_oidc_authorization_endpoint,
51
- option_oidc_client_id,
52
- option_oidc_redirect_uri
49
+ option_oidc_token_endpoint || HammerCLI::Settings.get(:foreman, :oidc_token_endpoint),
50
+ option_oidc_authorization_endpoint || HammerCLI::Settings.get(:foreman, :oidc_authorization_endpoint),
51
+ option_oidc_client_id || HammerCLI::Settings.get(:foreman, :oidc_client_id),
52
+ option_oidc_redirect_uri || HammerCLI::Settings.get(:foreman, :oidc_redirect_uri)
53
53
  )
54
54
  else
55
55
  Oauth.execute_with_params(
56
56
  AUTH_TYPES[:oauth_password_grant],
57
- option_oidc_token_endpoint,
58
- option_oidc_client_id,
57
+ option_oidc_token_endpoint || HammerCLI::Settings.get(:foreman, :oidc_token_endpoint),
58
+ option_oidc_client_id || HammerCLI::Settings.get(:foreman, :oidc_client_id),
59
59
  option_username || HammerCLI::Settings.get('_params', 'username'),
60
60
  option_password || HammerCLI::Settings.get('_params', 'password')
61
61
  )
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HammerCLIForeman
4
+ class Bookmark < HammerCLIForeman::Command
5
+ resource :bookmarks
6
+
7
+ class ListCommand < HammerCLIForeman::ListCommand
8
+ output do
9
+ field :id, _('Id')
10
+ field :name, _('Name')
11
+ field :controller, _('Controller')
12
+ field :query, _('Search Query')
13
+ field :public, _('Public')
14
+ field :owner_id, _('Owner Id')
15
+ field :owner_type, _('Owner Type')
16
+ end
17
+
18
+ build_options
19
+ end
20
+
21
+ class InfoCommand < HammerCLIForeman::InfoCommand
22
+ output ListCommand.output_definition
23
+
24
+ build_options
25
+ end
26
+
27
+ class CreateCommand < HammerCLIForeman::CreateCommand
28
+ success_message _('Bookmark %<name>s created.')
29
+ failure_message _('Failed to create %<name>s bookmark')
30
+
31
+ build_options
32
+ end
33
+
34
+ class UpdateCommand < HammerCLIForeman::UpdateCommand
35
+ success_message _('Bookmark %<name>s updated successfully.')
36
+ failure_message _('Failed to update %<name>s bookmark')
37
+
38
+ build_options
39
+ end
40
+
41
+ class DeleteCommand < HammerCLIForeman::DeleteCommand
42
+ success_message _('Bookmark deleted successfully.')
43
+ failure_message _('Failed to delete bookmark')
44
+
45
+ build_options
46
+ end
47
+
48
+ autoload_subcommands
49
+ end
50
+ end
@@ -5,3 +5,5 @@ require 'hammer_cli_foreman/command_extensions/option_sources'
5
5
  require 'hammer_cli_foreman/command_extensions/hosts'
6
6
  require 'hammer_cli_foreman/command_extensions/ping'
7
7
  require 'hammer_cli_foreman/command_extensions/status'
8
+ require 'hammer_cli_foreman/command_extensions/user'
9
+ require 'hammer_cli_foreman/command_extensions/subnet'
@@ -2,13 +2,19 @@ module HammerCLIForeman
2
2
  module CommandExtensions
3
3
  class PuppetEnvironment < HammerCLI::CommandExtensions
4
4
  # Remove when support of --environment options is ended.
5
- option '--environment', 'ENVIRONMENT_NAME', _('Environment name'),
6
- attribute_name: :option_environment_name,
7
- deprecated: { '--environment' => _('Use --puppet-environment instead') }
8
- option '--environment-id', 'ENVIRONMENT_ID', _(''),
9
- format: HammerCLI::Options::Normalizers::Number.new,
10
- attribute_name: :option_environment_id,
11
- deprecated: { '--environment-id' => _('Use --puppet-environment-id instead') }
5
+ option_family(
6
+ aliased_resource: 'environment',
7
+ description: _('Puppet environment'),
8
+ deprecation: _("Use %s instead") % '--puppet-environment[-id]',
9
+ deprecated: { '--environment' => _("Use %s instead") % '--puppet-environment[-id]',
10
+ '--environment-id' => _("Use %s instead") % '--puppet-environment[-id]'}
11
+ ) do
12
+ parent '--environment-id', 'ENVIRONMENT_ID', _(''),
13
+ format: HammerCLI::Options::Normalizers::Number.new,
14
+ attribute_name: :option_environment_id
15
+ child '--environment', 'ENVIRONMENT_NAME', _('Environment name'),
16
+ attribute_name: :option_environment_name
17
+ end
12
18
 
13
19
  option_sources do |sources, command|
14
20
  sources.find_by_name('IdResolution').insert_relative(
@@ -2,13 +2,19 @@ module HammerCLIForeman
2
2
  module CommandExtensions
3
3
  class PuppetEnvironments < HammerCLI::CommandExtensions
4
4
  # Remove when support of --environments options is ended.
5
- option '--environments', 'ENVIRONMENT_NAMES', _(''),
6
- attribute_name: :option_environment_names,
7
- deprecated: { '--environments' => _('Use --puppet-environments instead') }
8
- option '--environment-ids', 'ENVIRONMENT_IDS', _('Environment IDs'),
9
- format: HammerCLI::Options::Normalizers::List.new,
10
- attribute_name: :option_environment_ids,
11
- deprecated: { '--environment-ids' => _('Use --puppet-environment-ids instead') }
5
+ option_family(
6
+ aliased_resource: 'environment',
7
+ description: _('Puppet environments'),
8
+ deprecation: _("Use %s instead") % '--puppet-environment[s|-ids]',
9
+ deprecated: { '--environments' => _("Use %s instead") % '--puppet-environment[s|-ids]',
10
+ '--environment-ids' => _("Use %s instead") % '--puppet-environment[s|-ids]' }
11
+ ) do
12
+ parent '--environment-ids', 'ENVIRONMENT_IDS', _('Environment IDs'),
13
+ format: HammerCLI::Options::Normalizers::List.new,
14
+ attribute_name: :option_environment_ids
15
+ child '--environments', 'ENVIRONMENT_NAMES', _(''),
16
+ attribute_name: :option_environment_names
17
+ end
12
18
 
13
19
  option_sources do |sources, command|
14
20
  sources.find_by_name('IdResolution').insert_relative(
@@ -0,0 +1,25 @@
1
+ module HammerCLIForeman
2
+ module CommandExtensions
3
+ class Subnet < HammerCLI::CommandExtensions
4
+ option "--dns", "DNS_NAME", _("DNS Proxy to use within this subnet"),
5
+ attribute_name: :option_dns_name,
6
+ referenced_resource: :smart_proxy
7
+ option "--dhcp", "DHCP_NAME", _("DHCP Proxy to use within this subnet"),
8
+ attribute_name: :option_dhcp_name,
9
+ referenced_resource: :smart_proxy
10
+ option "--tftp", "TFTP_NAME", _("TFTP Proxy to use within this subnet"),
11
+ attribute_name: :option_tftp_name,
12
+ referenced_resource: :smart_proxy
13
+ option "--prefix", "PREFIX", _("Network prefix in CIDR notation (e.g. 64) for this subnet")
14
+
15
+ option_sources do |sources, command|
16
+ sources.find_by_name('IdResolution').insert_relative(
17
+ :after,
18
+ 'IdParams',
19
+ HammerCLIForeman::OptionSources::ReferencedResourceIdParams.new(command)
20
+ )
21
+ sources
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,17 @@
1
+ module HammerCLIForeman
2
+ module CommandExtensions
3
+ class User < HammerCLI::CommandExtensions
4
+ option '--default-organization', 'DEFAULT_ORGANIZATION_NAME', _('Default organization name'),
5
+ aliased_resource: 'default_organization', referenced_resource: 'default_organization'
6
+ option '--default-location', 'DEFAULT_LOCATION_NAME', _('Default location name'),
7
+ aliased_resource: 'default_location', referenced_resource: 'default_location'
8
+
9
+ option '--ask-password', 'ASK_PW', ' ', format: HammerCLI::Options::Normalizers::Bool.new
10
+
11
+ option_sources do |sources, command|
12
+ sources << HammerCLIForeman::OptionSources::UserParams.new(command)
13
+ sources
14
+ end
15
+ end
16
+ end
17
+ end
@@ -275,8 +275,8 @@ module HammerCLIForeman
275
275
  record
276
276
  end
277
277
 
278
- def self.command_name(name=nil)
279
- super(name) || "list"
278
+ def self.command_names(*names)
279
+ super(*names) || %w(list index)
280
280
  end
281
281
 
282
282
  def execute
@@ -502,8 +502,8 @@ module HammerCLIForeman
502
502
  end
503
503
  end
504
504
 
505
- def self.command_name(name=nil)
506
- super(name) || "info"
505
+ def self.command_names(*names)
506
+ super(*names) || %w(info show)
507
507
  end
508
508
 
509
509
  def send_request
@@ -565,8 +565,8 @@ module HammerCLIForeman
565
565
 
566
566
  action :destroy
567
567
 
568
- def self.command_name(name=nil)
569
- super(name) || "delete"
568
+ def self.command_names(*names)
569
+ super(*names) || %w(delete destroy)
570
570
  end
571
571
 
572
572
  end
@@ -687,7 +687,7 @@ module HammerCLIForeman
687
687
  class RemoveAssociatedCommand < AssociatedCommand
688
688
 
689
689
  def self.command_name(name=nil)
690
- name = super(name) || (associated_resource ? "remove-"+associated_resource.singular_name : nil)
690
+ name = super(name) || (associated_resource ? "remove-" + associated_resource.singular_name : nil)
691
691
  name.respond_to?(:gsub) ? name.gsub('_', '-') : name
692
692
  end
693
693
 
@@ -698,9 +698,14 @@ module HammerCLIForeman
698
698
 
699
699
  def get_new_ids
700
700
  ids = get_current_ids.map(&:to_s)
701
- required_id = get_associated_identifier.to_s
702
701
 
703
- ids = ids.delete_if { |id| id == required_id }
702
+ associated_identifiers = get_associated_identifiers
703
+ associated_identifier = get_associated_identifier
704
+
705
+ required_ids = associated_identifiers.nil? ? [] : associated_identifiers.map(&:to_s)
706
+ required_ids << associated_identifier.to_s unless associated_identifier.nil?
707
+
708
+ ids = ids.delete_if { |id| required_ids.include? id }
704
709
  ids
705
710
  end
706
711