knife-vrealize 3.0.0 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 267c713a407cd2265caf2e14a8fe31cfd9b5014e
4
- data.tar.gz: b84bf831de2c95d2c302ff5bd1fcadf6ad8aafa1
2
+ SHA256:
3
+ metadata.gz: 26774900025bacb20c92669ec354fa5eecf896a05e5dc0360639bc3c58b58998
4
+ data.tar.gz: c374fd4befb4616243716ddd664a509f13c33d9a1254d1c0af3985103604c7dd
5
5
  SHA512:
6
- metadata.gz: 2b50faa246e6875d2f9d25b3612236943a316c759e5dc65adb6a78fc260eab8347d0ed44a334b719982ef51fbaf9600afa954aa401f10c4a9df64681f552a19c
7
- data.tar.gz: 0b83282bc5280d5d7e79d0bf8424d12b0ee9270c683da89937385c94f85261a9d301cbf10e156c6ecd7f702f03a2488a456b44bb6d28fbb9f4b235ec8f11fb85
6
+ metadata.gz: 29be7394fb628f6ff10f98e63b3d4a01ec3ab7bcdc8d23c35140dc754481051be09bd9668ce2f73ee169d9f380197c8114bf611e90e9e6fcb142ff0cbfaf2a94
7
+ data.tar.gz: 48870906b9cc159ff4c95faac60f3a4a1e8657b9b1f82003e0441534eb1b2fda359fba59869b0502b6e67cbf3631e1674f51e3fa3be635dd25bd1a70a7a454ef
File without changes
@@ -2,7 +2,7 @@
2
2
 
3
3
  #
4
4
  # Author:: Chef Partner Engineering (<partnereng@chef.io>)
5
- # Copyright:: Copyright (c) 2015 Chef Software, Inc.
5
+ # Copyright:: Copyright (c) Chef Software Inc.
6
6
  # License:: Apache License, Version 2.0
7
7
  #
8
8
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,19 +18,19 @@
18
18
  # limitations under the License.
19
19
  #
20
20
 
21
- require 'chef/knife/cloud/exceptions'
22
- require 'chef/knife/cloud/service'
23
- require 'chef/knife/cloud/helpers'
24
- require 'chef/knife/cloud/vra_service_helpers'
25
- require 'vra'
21
+ require "chef/knife/cloud/exceptions"
22
+ require "chef/knife/cloud/service"
23
+ require "chef/knife/cloud/helpers"
24
+ require_relative "vra_service_helpers"
25
+ require "vra"
26
26
 
27
27
  class Chef
28
28
  class Knife
29
29
  class Cloud
30
30
  class VraService < Service
31
31
  include VraServiceHelpers
32
- def initialize(options={})
33
- super(options)
32
+ def initialize(options = {})
33
+ super(config: options)
34
34
 
35
35
  @username = options[:username]
36
36
  @password = options[:password]
@@ -51,7 +51,7 @@ class Chef
51
51
  )
52
52
  end
53
53
 
54
- def create_server(options={})
54
+ def create_server(options = {})
55
55
  submitted_request = catalog_request(options).submit
56
56
  ui.msg("Catalog request #{submitted_request.id} submitted.")
57
57
  wait_for_request(submitted_request, options[:wait_time].to_i, options[:refresh_rate])
@@ -61,8 +61,8 @@ class Chef
61
61
  raise CloudExceptions::ServerCreateError, submitted_request.completion_details if submitted_request.failed?
62
62
 
63
63
  servers = submitted_request.resources.select(&:vm?)
64
- raise CloudExceptions::ServerCreateError, 'The vRA request created more than one server, but we were only expecting 1' if servers.length > 1
65
- raise CloudExceptions::ServerCreateError, 'The vRA request did not create any servers' if servers.length.zero?
64
+ raise CloudExceptions::ServerCreateError, "The vRA request created more than one server, but we were only expecting 1" if servers.length > 1
65
+ raise CloudExceptions::ServerCreateError, "The vRA request did not create any servers" if servers.length == 0
66
66
 
67
67
  servers.first
68
68
  end
@@ -70,19 +70,19 @@ class Chef
70
70
  def delete_server(instance_id)
71
71
  server = get_server(instance_id)
72
72
  server_summary(server)
73
- ui.msg('')
73
+ ui.msg("")
74
74
 
75
- if server.status == 'DELETED'
75
+ if server.status == "DELETED"
76
76
  ui.warn("Server is already deleted.\n")
77
77
  return
78
78
  end
79
79
 
80
- ui.confirm('Do you really want to delete this server')
80
+ ui.confirm("Do you really want to delete this server")
81
81
 
82
82
  destroy_request = server.destroy
83
83
  ui.msg("Destroy request #{destroy_request.id} submitted.")
84
84
  wait_for_request(destroy_request)
85
- ui.msg('Destroy request complete.')
85
+ ui.msg("Destroy request complete.")
86
86
  request_summary(destroy_request)
87
87
  end
88
88
 
@@ -102,22 +102,22 @@ class Chef
102
102
  connection.resources.by_id(instance_id)
103
103
  end
104
104
 
105
- def server_summary(server, _columns_with_info=nil)
106
- msg_pair('Server ID', server.id)
107
- msg_pair('Server Name', server.name)
108
- msg_pair('IP Addresses', server.ip_addresses.nil? ? 'none' : server.ip_addresses.join(', '))
109
- msg_pair('Status', server.status)
110
- msg_pair('Catalog Name', server.catalog_name)
111
- msg_pair('Owner IDs', server.owner_ids.empty? ? 'none' : server.owner_ids.join(', '))
112
- msg_pair('Owner Names', server.owner_names.empty? ? 'none' : server.owner_names.join(', '))
105
+ def server_summary(server, _columns_with_info = nil)
106
+ msg_pair("Server ID", server.id)
107
+ msg_pair("Server Name", server.name)
108
+ msg_pair("IP Addresses", server.ip_addresses.nil? ? "none" : server.ip_addresses.join(", "))
109
+ msg_pair("Status", server.status)
110
+ msg_pair("Catalog Name", server.catalog_name)
111
+ msg_pair("Owner IDs", server.owner_ids.empty? ? "none" : server.owner_ids.join(", "))
112
+ msg_pair("Owner Names", server.owner_names.empty? ? "none" : server.owner_names.join(", "))
113
113
  end
114
114
 
115
115
  def request_summary(request)
116
- ui.msg('')
117
- msg_pair('Request Status', request.status)
118
- msg_pair('Completion State', request.completion_state)
119
- msg_pair('Completion Details', request.completion_details)
120
- ui.msg('')
116
+ ui.msg("")
117
+ msg_pair("Request Status", request.status)
118
+ msg_pair("Completion State", request.completion_state)
119
+ msg_pair("Completion Details", request.completion_details)
120
+ ui.msg("")
121
121
  end
122
122
 
123
123
  def catalog_request(options)
@@ -2,7 +2,7 @@
2
2
 
3
3
  #
4
4
  # Author:: Chef Partner Engineering (<partnereng@chef.io>)
5
- # Copyright:: Copyright (c) 2015 Chef Software, Inc.
5
+ # Copyright:: Copyright (c) Chef Software Inc.
6
6
  # License:: Apache License, Version 2.0
7
7
  #
8
8
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,7 +18,7 @@
18
18
  # limitations under the License.
19
19
  #
20
20
 
21
- require 'chef/knife/cloud/helpers'
21
+ require "chef/knife/cloud/helpers"
22
22
 
23
23
  class Chef
24
24
  class Knife
@@ -27,22 +27,22 @@ class Chef
27
27
  include Chef::Knife::Cloud::Helpers
28
28
 
29
29
  def create_service_instance
30
- Chef::Knife::Cloud::VraService.new(username: locate_config_value(:vra_username),
31
- password: locate_config_value(:vra_password),
32
- base_url: locate_config_value(:vra_base_url),
33
- tenant: locate_config_value(:vra_tenant),
34
- page_size: locate_config_value(:vra_page_size),
30
+ Chef::Knife::Cloud::VraService.new(username: config[:vra_username],
31
+ password: config[:vra_password],
32
+ base_url: config[:vra_base_url],
33
+ tenant: config[:vra_tenant],
34
+ page_size: config[:vra_page_size],
35
35
  verify_ssl: verify_ssl?)
36
36
  end
37
37
 
38
38
  def verify_ssl?
39
- !locate_config_value(:vra_disable_ssl_verify)
39
+ !config[:vra_disable_ssl_verify]
40
40
  end
41
41
 
42
- def wait_for_request(request, wait_time=600, refresh_rate=2)
43
- print 'Waiting for request to complete.'
42
+ def wait_for_request(request, wait_time = 600, refresh_rate = 2)
43
+ print "Waiting for request to complete."
44
44
 
45
- last_status = ''
45
+ last_status = ""
46
46
 
47
47
  begin
48
48
  Timeout.timeout(wait_time) do
@@ -55,7 +55,7 @@ class Chef
55
55
  end
56
56
 
57
57
  if last_status == request.status
58
- print '.'
58
+ print "."
59
59
  else
60
60
  last_status = request.status
61
61
  print "\n"
@@ -66,7 +66,7 @@ class Chef
66
66
  end
67
67
  end
68
68
  rescue Timeout::Error
69
- ui.msg('')
69
+ ui.msg("")
70
70
  ui.error("Request did not complete in #{wait_time} seconds. Check the Requests tab in the vRA UI for more information.")
71
71
  exit 1
72
72
  end
@@ -78,10 +78,10 @@ class Chef
78
78
 
79
79
  # rubocop:disable Style/GuardClause
80
80
  def check_for_missing_config_values!(*keys)
81
- missing = keys.select { |x| locate_config_value(x).nil? }
81
+ missing = keys.select { |x| config[x].nil? }
82
82
 
83
83
  unless missing.empty?
84
- ui.error("The following required parameters are missing: #{missing.join(', ')}")
84
+ ui.error("The following required parameters are missing: #{missing.join(", ")}")
85
85
  exit(1)
86
86
  end
87
87
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  #
4
4
  # Author:: Chef Partner Engineering (<partnereng@chef.io>)
5
- # Copyright:: Copyright (c) 2015 Chef Software, Inc.
5
+ # Copyright:: Copyright (c) Chef Software Inc.
6
6
  # License:: Apache License, Version 2.0
7
7
  #
8
8
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -27,37 +27,37 @@ class Chef
27
27
  def self.included(includer)
28
28
  includer.class_eval do
29
29
  option :vra_base_url,
30
- long: '--vra-base-url API_URL',
31
- description: 'URL for the vRA server',
32
- proc: proc { |url| url.sub(%r{/(\/)+$/}, '') }
30
+ long: "--vra-base-url API_URL",
31
+ description: "URL for the vRA server",
32
+ proc: proc { |url| url.sub(%r{/(\/)+$/}, "") }
33
33
 
34
34
  option :vra_username,
35
- long: '--vra-username USERNAME',
36
- description: 'Username to use with the vRA API'
35
+ long: "--vra-username USERNAME",
36
+ description: "Username to use with the vRA API"
37
37
 
38
38
  option :vra_password,
39
- long: '--vra-password PASSWORD',
40
- description: 'Password to use with the vRA API'
39
+ long: "--vra-password PASSWORD",
40
+ description: "Password to use with the vRA API"
41
41
 
42
42
  option :vra_tenant,
43
- long: '--vra-tenant TENANT',
44
- description: 'Tenant name (organization) to use with the vRA API'
43
+ long: "--vra-tenant TENANT",
44
+ description: "Tenant name (organization) to use with the vRA API"
45
45
 
46
46
  option :vra_disable_ssl_verify,
47
- long: '--vra-disable-ssl-verify',
48
- description: 'Skip any SSL verification for the vRA API',
47
+ long: "--vra-disable-ssl-verify",
48
+ description: "Skip any SSL verification for the vRA API",
49
49
  boolean: true,
50
50
  default: false
51
51
 
52
52
  option :vra_page_size,
53
- long: '--page-size NUM_OF_ITEMS',
54
- description: 'Maximum number of items to fetch from the vRA API when pagination is forced',
53
+ long: "--page-size NUM_OF_ITEMS",
54
+ description: "Maximum number of items to fetch from the vRA API when pagination is forced",
55
55
  default: 200,
56
56
  proc: proc { |page_size| page_size.to_i }
57
57
 
58
58
  option :request_refresh_rate,
59
- long: '--request-refresh-rate SECS',
60
- description: 'Number of seconds to sleep between each check of the request status, defaults to 2',
59
+ long: "--request-refresh-rate SECS",
60
+ description: "Number of seconds to sleep between each check of the request status, defaults to 2",
61
61
  default: 2,
62
62
  proc: proc { |secs| secs.to_i }
63
63
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  #
4
4
  # Author:: Chef Partner Engineering (<partnereng@chef.io>)
5
- # Copyright:: Copyright (c) 2015 Chef Software, Inc.
5
+ # Copyright:: Copyright (c) Chef Software Inc.
6
6
  # License:: Apache License, Version 2.0
7
7
  #
8
8
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,46 +18,51 @@
18
18
  # limitations under the License.
19
19
  #
20
20
 
21
- require 'chef/knife'
22
- require 'chef/knife/cloud/list_resource_command'
23
- require 'chef/knife/cloud/vra_service'
24
- require 'chef/knife/cloud/vra_service_helpers'
25
- require 'chef/knife/cloud/vra_service_options'
21
+ require "chef/knife"
22
+ require "chef/knife/cloud/list_resource_command"
23
+ require_relative "cloud/vra_service_options"
26
24
 
27
25
  class Chef
28
26
  class Knife
29
27
  class Cloud
30
28
  class VraCatalogList < ResourceListCommand
31
- include VraServiceHelpers
32
29
  include VraServiceOptions
33
30
 
34
- banner 'knife vra catalog list'
31
+ banner "knife vra catalog list"
32
+
33
+ deps do
34
+ require_relative "cloud/vra_service"
35
+ require_relative "cloud/vra_service_helpers"
36
+ include VraServiceHelpers
37
+ end
35
38
 
36
39
  option :entitled,
37
- long: '--entitled-only',
38
- description: 'only list entitled vRA catalog entries',
39
- boolean: true,
40
- default: false
40
+ long: "--entitled-only",
41
+ description: "only list entitled vRA catalog entries",
42
+ boolean: true,
43
+ default: false
41
44
 
42
45
  def before_exec_command
43
46
  @columns_with_info = [
44
- { label: 'Catalog ID', key: 'id' },
45
- { label: 'Name', key: 'name' },
46
- { label: 'Description', key: 'description' },
47
- { label: 'Status', key: 'status', value_callback: method(:format_status_value) },
48
- { label: 'Subtenant', key: 'subtenant_name' }
47
+ { label: "Catalog ID", key: "id" },
48
+ { label: "Name", key: "name" },
49
+ { label: "Description", key: "description" },
50
+ { label: "Status", key: "status", value_callback: method(:format_status_value) },
51
+ { label: "Subtenant", key: "subtenant_name" },
49
52
  ]
50
53
 
51
- @sort_by_field = 'name'
54
+ @sort_by_field = "name"
52
55
  end
53
56
 
54
57
  def query_resource
55
- @service.list_catalog_items(locate_config_value(:entitled))
58
+ @service.list_catalog_items(config[:entitled])
56
59
  end
57
60
 
58
61
  def format_status_value(status)
62
+ return "-" if status.nil?
63
+
59
64
  status = status.downcase
60
- color = if status == 'published'
65
+ color = if status == "published"
61
66
  :green
62
67
  else
63
68
  :red
@@ -2,7 +2,7 @@
2
2
 
3
3
  #
4
4
  # Author:: Chef Partner Engineering (<partnereng@chef.io>)
5
- # Copyright:: Copyright (c) 2015 Chef Software, Inc.
5
+ # Copyright:: Copyright (c) Chef Software Inc.
6
6
  # License:: Apache License, Version 2.0
7
7
  #
8
8
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,12 +18,10 @@
18
18
  # limitations under the License.
19
19
  #
20
20
 
21
- require 'chef/knife'
22
- require 'chef/knife/cloud/server/create_command'
23
- require 'chef/knife/cloud/server/create_options'
24
- require 'chef/knife/cloud/vra_service'
25
- require 'chef/knife/cloud/vra_service_helpers'
26
- require 'chef/knife/cloud/vra_service_options'
21
+ require "chef/knife"
22
+ require "chef/knife/cloud/server/create_command"
23
+ require "chef/knife/cloud/server/create_options"
24
+ require_relative "cloud/vra_service_options"
27
25
 
28
26
  class Chef
29
27
  class Knife
@@ -33,57 +31,62 @@ class Chef
33
31
  include VraServiceOptions
34
32
  include ServerCreateOptions
35
33
 
36
- banner 'knife vra server create CATALOG_ID (options)'
34
+ banner "knife vra server create CATALOG_ID (options)"
35
+
36
+ deps do
37
+ require_relative "cloud/vra_service"
38
+ require_relative "cloud/vra_service_helpers"
39
+ end
37
40
 
38
41
  option :cpus,
39
- long: '--cpus NUM_CPUS',
40
- description: 'Number of CPUs the server should have'
42
+ long: "--cpus NUM_CPUS",
43
+ description: "Number of CPUs the server should have"
41
44
 
42
45
  option :node_ssl_verify_mode,
43
- long: '--node-ssl-verify-mode [peer|none]',
44
- description: 'Whether or not to verify the SSL cert for all HTTPS requests when bootstrapping'
46
+ long: "--node-ssl-verify-mode [peer|none]",
47
+ description: "Whether or not to verify the SSL cert for all HTTPS requests when bootstrapping"
45
48
  option :memory,
46
- long: '--memory RAM_IN_MB',
47
- description: 'Amount of RAM, in MB, the server should have'
49
+ long: "--memory RAM_IN_MB",
50
+ description: "Amount of RAM, in MB, the server should have"
48
51
 
49
52
  option :requested_for,
50
- long: '--requested-for LOGIN',
51
- description: 'The login to list as the owner of this resource. Will default to the vra_username parameter'
53
+ long: "--requested-for LOGIN",
54
+ description: "The login to list as the owner of this resource. Will default to the vra_username parameter"
52
55
 
53
56
  option :server_create_timeout,
54
- long: '--server-create-timeout SECONDS',
55
- description: 'number of seconds to wait for the server to complete',
56
- default: 600
57
+ long: "--server-create-timeout SECONDS",
58
+ description: "number of seconds to wait for the server to complete",
59
+ default: 600
57
60
 
58
61
  option :subtenant_id,
59
- long: '--subtenant-id ID',
60
- description: 'The subtenant ID (a.k.a "business group") to list as the owner of this resource. ' \
61
- 'Will default to the blueprint subtenant if it exists.'
62
+ long: "--subtenant-id ID",
63
+ description: 'The subtenant ID (a.k.a "business group") to list as the owner of this resource. ' \
64
+ "Will default to the blueprint subtenant if it exists."
62
65
 
63
66
  option :lease_days,
64
- long: '--lease-days NUM_DAYS',
65
- description: 'Number of days requested for the server lease, provided the blueprint allows this to be specified'
67
+ long: "--lease-days NUM_DAYS",
68
+ description: "Number of days requested for the server lease, provided the blueprint allows this to be specified"
66
69
 
67
70
  option :notes,
68
- long: '--notes NOTES',
69
- description: 'String of text to be included in the request notes.'
71
+ long: "--notes NOTES",
72
+ description: "String of text to be included in the request notes."
70
73
 
71
74
  option :extra_params,
72
- long: '--extra-param KEY=TYPE:VALUE',
73
- description: 'Additional parameters to pass to vRA for this catalog request. TYPE must be "string" or "integer". ' \
74
- 'Can be used multiple times.',
75
- default: {},
76
- proc: proc { |param|
77
- Chef::Config[:knife][:vra_extra_params] ||= {}
78
- key, value_str = param.split('=')
79
- Chef::Config[:knife][:vra_extra_params].merge!(key => value_str)
80
- }
75
+ long: "--extra-param KEY=TYPE:VALUE",
76
+ description: 'Additional parameters to pass to vRA for this catalog request. TYPE must be "string" or "integer". ' \
77
+ "Can be used multiple times.",
78
+ default: {},
79
+ proc: proc { |param|
80
+ Chef::Config[:knife][:vra_extra_params] ||= {}
81
+ key, value_str = param.split("=")
82
+ Chef::Config[:knife][:vra_extra_params].merge!(key => value_str)
83
+ }
81
84
 
82
85
  def validate_params!
83
86
  super
84
87
 
85
88
  if @name_args.empty?
86
- ui.error('You must supply a Catalog ID to use for your new server.')
89
+ ui.error("You must supply a Catalog ID to use for your new server.")
87
90
  exit 1
88
91
  end
89
92
 
@@ -96,23 +99,23 @@ class Chef
96
99
  super
97
100
 
98
101
  @create_options = {
99
- catalog_id: @name_args.first,
100
- cpus: locate_config_value(:cpus),
101
- memory: locate_config_value(:memory),
102
- requested_for: locate_config_value(:requested_for),
103
- subtenant_id: locate_config_value(:subtenant_id),
104
- lease_days: locate_config_value(:lease_days),
105
- notes: locate_config_value(:notes),
106
- extra_params: extra_params,
107
- wait_time: locate_config_value(:server_create_timeout),
108
- refresh_rate: locate_config_value(:request_refresh_rate)
102
+ catalog_id: @name_args.first,
103
+ cpus: config[:cpus],
104
+ memory: config[:memory],
105
+ requested_for: config[:requested_for],
106
+ subtenant_id: config[:subtenant_id],
107
+ lease_days: config[:lease_days],
108
+ notes: config[:notes],
109
+ extra_params: extra_params,
110
+ wait_time: config[:server_create_timeout],
111
+ refresh_rate: config[:request_refresh_rate],
109
112
  }
110
113
  end
111
114
 
112
115
  def before_bootstrap
113
116
  super
114
117
 
115
- config[:chef_node_name] = locate_config_value(:chef_node_name) ? locate_config_value(:chef_node_name) : server.name
118
+ config[:chef_node_name] = config[:chef_node_name] ? config[:chef_node_name] : server.name
116
119
  config[:bootstrap_ip_address] = hostname_for_server
117
120
  end
118
121
 
@@ -120,7 +123,7 @@ class Chef
120
123
  return if Chef::Config[:knife][:vra_extra_params].nil? || Chef::Config[:knife][:vra_extra_params].empty?
121
124
 
122
125
  Chef::Config[:knife][:vra_extra_params].each_with_object([]) do |(key, value_str), memo|
123
- type, value = value_str.split(':')
126
+ type, value = value_str.split(":")
124
127
  memo << { key: key, type: type, value: value }
125
128
  end
126
129
  end
@@ -131,7 +134,7 @@ class Chef
131
134
  extra_params.each do |param|
132
135
  raise ArgumentError, "No type and value set for extra parameter #{param[:key]}" if param[:type].nil? || param[:value].nil?
133
136
  raise ArgumentError, "Invalid parameter type for #{param[:key]} - must be string or integer" unless
134
- param[:type] == 'string' || param[:type] == 'integer'
137
+ param[:type] == "string" || param[:type] == "integer"
135
138
  end
136
139
  end
137
140