knife-vcenter 2.0.0 → 2.0.1

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.
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  #
3
3
  # Author:: Chef Partner Engineering (<partnereng@chef.io>)
4
- # Copyright:: Copyright (c) 2017 Chef Software, Inc.
4
+ # Copyright:: Copyright (c) 2017-2018 Chef Software, Inc.
5
5
  # License:: Apache License, Version 2.0
6
6
  #
7
7
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -20,34 +20,35 @@
20
20
  class Chef
21
21
  class Knife
22
22
  class Cloud
23
- # rubocop:disable Style/AlignParameters
24
- # rubocop:disable Metrics/BlockLength
25
23
  module VcenterServiceOptions
24
+ # The main service options for this plugin
25
+ #
26
+ # @param [Object] includer are the options that can be handed off to this method
26
27
  def self.included(includer)
27
28
  includer.class_eval do
28
29
  option :vcenter_username,
29
- long: '--vcenter-username USERNAME',
30
- description: 'Username to use to connect to the VCenter API'
30
+ long: "--vcenter-username USERNAME",
31
+ description: "Username to use to connect to the VCenter API"
31
32
 
32
33
  option :vcenter_password,
33
- long: '--vcenter-password PASSWORD',
34
- description: 'Password associated with the specified user'
34
+ long: "--vcenter-password PASSWORD",
35
+ description: "Password associated with the specified user"
35
36
 
36
37
  option :vcenter_host,
37
- long: '--vcenter-host HOST',
38
- description: 'Host to target for operations'
38
+ long: "--vcenter-host HOST",
39
+ description: "Host to target for operations"
39
40
 
40
41
  option :vcenter_disable_ssl_verify,
41
- long: '--vcenter-disable-ssl-verify',
42
- description: 'Skip any SSL verification for the API',
43
- boolean: true,
44
- default: false
42
+ long: "--vcenter-disable-ssl-verify",
43
+ description: "Skip any SSL verification for the API",
44
+ boolean: true,
45
+ default: false
45
46
 
46
47
  option :vcenter_logs,
47
- long: '--vcenter-logs',
48
- description: 'Whether or not to display logs from VCenter SDK. Default: false',
49
- boolean: true,
50
- default: false
48
+ long: "--vcenter-logs",
49
+ description: "Whether or not to display logs from VCenter SDK. Default: false",
50
+ boolean: true,
51
+ default: false
51
52
  end
52
53
  end
53
54
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  #
3
3
  # Author:: Chef Partner Engineering (<partnereng@chef.io>)
4
- # Copyright:: Copyright (c) 2017 Chef Software, Inc.
4
+ # Copyright:: Copyright (c) 2017-2018 Chef Software, Inc.
5
5
  # License:: Apache License, Version 2.0
6
6
  #
7
7
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,37 +17,43 @@
17
17
  # limitations under the License.
18
18
  #
19
19
 
20
- require 'chef/knife'
21
- require 'chef/knife/cloud/list_resource_command'
22
- require 'chef/knife/cloud/vcenter_service'
23
- require 'chef/knife/cloud/vcenter_service_helpers'
24
- require 'chef/knife/cloud/vcenter_service_options'
20
+ require "chef/knife"
21
+ require "chef/knife/cloud/list_resource_command"
22
+ require "chef/knife/cloud/vcenter_service"
23
+ require "chef/knife/cloud/vcenter_service_helpers"
24
+ require "chef/knife/cloud/vcenter_service_options"
25
25
 
26
26
  class Chef
27
27
  class Knife
28
28
  class Cloud
29
+ # Extends ResourceListcommand to talk to vCenter
29
30
  class VcenterClusterList < ResourceListCommand
30
31
  include VcenterServiceHelpers
31
32
  include VcenterServiceOptions
32
33
 
33
- banner 'knife vcenter cluster list'
34
+ banner "knife vcenter cluster list"
34
35
 
36
+ # Creates the columns and how to sort the columns
37
+ #
35
38
  def before_exec_command
36
39
  @columns_with_info = [
37
- { label: 'ID', key: 'cluster' },
38
- { label: 'Name', key: 'name' },
39
- { label: 'DRS?', key: 'drs_enabled', value_callback: method(:format_boolean) },
40
- { label: 'HA?', key: 'ha_enabled', value_callback: method(:format_boolean)},
40
+ { label: "ID", key: "cluster" },
41
+ { label: "Name", key: "name" },
42
+ { label: "DRS?", key: "drs_enabled", value_callback: method(:format_boolean) },
43
+ { label: "HA?", key: "ha_enabled", value_callback: method(:format_boolean) }
41
44
  ]
42
45
 
43
- @sort_by_field = 'name'
46
+ @sort_by_field = "name"
44
47
  end
45
48
 
49
+ # Call service to get the list of hosts from vcenter
50
+ #
46
51
  def query_resource
47
- # Call service to get the list of hosts from vcenter
48
52
  service.list_clusters
49
53
  end
50
54
 
55
+ # How to set the color of the text
56
+ #
51
57
  def format_boolean(status)
52
58
  status_color = status ? :green : :red
53
59
  ui.color(status ? "True" : "False", status_color)
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  #
3
3
  # Author:: Chef Partner Engineering (<partnereng@chef.io>)
4
- # Copyright:: Copyright (c) 2017 Chef Software, Inc.
4
+ # Copyright:: Copyright (c) 2017-2018 Chef Software, Inc.
5
5
  # License:: Apache License, Version 2.0
6
6
  #
7
7
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,35 +17,41 @@
17
17
  # limitations under the License.
18
18
  #
19
19
 
20
- require 'chef/knife'
21
- require 'chef/knife/cloud/list_resource_command'
22
- require 'chef/knife/cloud/vcenter_service'
23
- require 'chef/knife/cloud/vcenter_service_helpers'
24
- require 'chef/knife/cloud/vcenter_service_options'
20
+ require "chef/knife"
21
+ require "chef/knife/cloud/list_resource_command"
22
+ require "chef/knife/cloud/vcenter_service"
23
+ require "chef/knife/cloud/vcenter_service_helpers"
24
+ require "chef/knife/cloud/vcenter_service_options"
25
25
 
26
26
  class Chef
27
+ # The main knife class
27
28
  class Knife
29
+ # The main cloud class from knife-cloud
28
30
  class Cloud
31
+ # Extends the ResourceListCommand for specific vCenter
29
32
  class VcenterDatacenterList < ResourceListCommand
30
33
  include VcenterServiceHelpers
31
34
  include VcenterServiceOptions
32
35
 
33
- banner 'knife vcenter datacenter list'
36
+ banner "knife vcenter datacenter list"
34
37
 
38
+ # Sets up the columns for listing out and sorts by name
39
+ #
35
40
  def before_exec_command
36
41
  @columns_with_info = [
37
- { label: 'ID', key: 'datacenter' },
38
- { label: 'Name', key: 'name' },
42
+ { label: "ID", key: "datacenter" },
43
+ { label: "Name", key: "name" }
39
44
  ]
40
45
 
41
- @sort_by_field = 'name'
46
+ @sort_by_field = "name"
42
47
  end
43
48
 
49
+ # Call service to get the list of hosts from vcenter
50
+ #
44
51
  def query_resource
45
- # Call service to get the list of hosts from vcenter
46
52
  service.list_datacenters
47
- end
53
+ end
48
54
  end
49
55
  end
50
56
  end
51
- end
57
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  #
3
3
  # Author:: Chef Partner Engineering (<partnereng@chef.io>)
4
- # Copyright:: Copyright (c) 2017 Chef Software, Inc.
4
+ # Copyright:: Copyright (c) 2017-2018 Chef Software, Inc.
5
5
  # License:: Apache License, Version 2.0
6
6
  #
7
7
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,46 +17,55 @@
17
17
  # limitations under the License.
18
18
  #
19
19
 
20
- require 'chef/knife'
21
- require 'chef/knife/cloud/list_resource_command'
22
- require 'chef/knife/cloud/vcenter_service'
23
- require 'chef/knife/cloud/vcenter_service_helpers'
24
- require 'chef/knife/cloud/vcenter_service_options'
20
+ require "chef/knife"
21
+ require "chef/knife/cloud/list_resource_command"
22
+ require "chef/knife/cloud/vcenter_service"
23
+ require "chef/knife/cloud/vcenter_service_helpers"
24
+ require "chef/knife/cloud/vcenter_service_options"
25
25
 
26
26
  class Chef
27
+ # Main knife class
27
28
  class Knife
29
+ # the main cloud class from knife-cloud
28
30
  class Cloud
31
+ # Extends the ResourceListcommand for specific vCenter
29
32
  class VcenterHostList < ResourceListCommand
30
33
  include VcenterServiceHelpers
31
34
  include VcenterServiceOptions
32
35
 
33
- banner 'knife vcenter host list'
36
+ banner "knife vcenter host list"
34
37
 
38
+ # Sets up the columns for listing out and sorts by name
39
+ #
35
40
  def before_exec_command
36
41
  @columns_with_info = [
37
- { label: 'ID', key: 'host' },
38
- { label: 'Name', key: 'name' },
39
- { label: 'Power State', key: 'power_state', value_callback: method(:format_power_status) },
40
- { label: 'Connection State', key: 'connection_state'},
42
+ { label: "ID", key: "host" },
43
+ { label: "Name", key: "name" },
44
+ { label: "Power State", key: "power_state", value_callback: method(:format_power_status) },
45
+ { label: "Connection State", key: "connection_state" }
41
46
  ]
42
47
 
43
- @sort_by_field = 'name'
48
+ @sort_by_field = "name"
44
49
  end
45
50
 
51
+ # Call service to get the list of hosts from vCenter
52
+ #
46
53
  def query_resource
47
- # Call service to get the list of hosts from vcenter
48
54
  service.list_hosts
49
55
  end
50
56
 
57
+ # Formats the power status
58
+ #
59
+ # @param [Object] status takes the number and formats it how you need it to
51
60
  def format_power_status(status)
52
61
  status_check = status.value
53
62
  status_color = case status_check
54
- when 'POWERED_OFF'
55
- :red
56
- when 'POWERED_ON'
57
- :green
58
- when 'SUSPENDED'
59
- :yellow
63
+ when "POWERED_OFF"
64
+ :red
65
+ when "POWERED_ON"
66
+ :green
67
+ when "SUSPENDED"
68
+ :yellow
60
69
  end
61
70
 
62
71
  ui.color(status.value, status_color)
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  #
3
4
  # Author:: Chef Partner Engineering (<partnereng@chef.io>)
4
- # Copyright:: Copyright (c) 2017 Chef Software, Inc.
5
+ # Copyright:: Copyright (c) 2017-2018 Chef Software, Inc.
5
6
  # License:: Apache License, Version 2.0
6
7
  #
7
8
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,86 +18,96 @@
17
18
  # limitations under the License.
18
19
  #
19
20
 
20
- require 'chef/knife'
21
- require 'chef/knife/cloud/server/create_command'
22
- require 'chef/knife/cloud/server/create_options'
23
- require 'chef/knife/cloud/vcenter_service'
24
- require 'chef/knife/cloud/vcenter_service_helpers'
25
- require 'chef/knife/cloud/vcenter_service_options'
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/vcenter_service"
25
+ require "chef/knife/cloud/vcenter_service_helpers"
26
+ require "chef/knife/cloud/vcenter_service_options"
26
27
 
27
28
  class Chef
29
+ # The main knife class
28
30
  class Knife
31
+ # The main cloud class from knife-cloud
29
32
  class Cloud
33
+ # Extends the ServerCreateCommand for specific vCenter
30
34
  class VcenterVmClone < Chef::Knife::Cloud::ServerCreateCommand
31
35
  include VcenterServiceHelpers
32
36
  include VcenterServiceOptions
33
37
  include ServerCreateOptions
34
38
 
35
- banner 'knife vcenter vm clone NAME (options)'
39
+ banner "knife vcenter vm clone NAME (options)"
36
40
 
37
41
  option :template,
38
- long: "--template NAME",
42
+ long: "--template NAME",
39
43
  description: "Name of VM or template to use to clone machine from"
40
44
 
41
45
  option :targethost,
42
- long: "--targethost HOST",
46
+ long: "--targethost HOST",
43
47
  description: "Host that the machine should be created on"
44
48
 
45
49
  option :datacenter,
46
- long: "--datacenter NAME",
50
+ long: "--datacenter NAME",
47
51
  description: "The datacenter for vSphere"
48
52
 
49
53
  option :disable_power_on,
50
- long: "--disable-power-on",
51
- boolean: true,
52
- default: false
54
+ long: "--disable-power-on",
55
+ boolean: true,
56
+ default: false
53
57
 
54
58
  option :folder,
55
- long: "--folder NAME",
59
+ long: "--folder NAME",
56
60
  description: "Folder to deploy the new machine into"
57
61
 
58
62
  option :pool,
59
- long: "--pool NAME",
63
+ long: "--pool NAME",
60
64
  description: "Name of resource pool to use when creating the machine"
61
65
 
62
66
  option :node_ssl_verify_mode,
63
- :long => "--node-ssl-verify-mode [peer|none]",
64
- :description => "Whether or not to verify the SSL cert for all HTTPS requests."
67
+ long: "--node-ssl-verify-mode [peer|none]",
68
+ description: "Whether or not to verify the SSL cert for all HTTPS requests."
65
69
 
70
+ # Validates the parameters and maksessure you have a template, name, or datacenter
71
+ #
66
72
  def validate_params!
67
73
  super
68
74
 
69
75
  if @name_args.empty?
70
- ui.error('You must provide the name of the new machine')
76
+ ui.error("You must provide the name of the new machine")
71
77
  end
72
78
 
73
79
  check_for_missing_config_values!(:template, :datacenter)
74
80
  end
75
81
 
82
+ # Creates the @create_options to hand off to the next step
83
+ #
76
84
  def before_exec_command
77
85
  super
78
86
 
79
87
  @create_options = {
80
- name: @name_args[0],
81
- type: "clone",
82
- template: locate_config_value(:template),
83
- targethost: locate_config_value(:targethost),
84
- datacenter: locate_config_value(:datacenter),
85
- poweron: !locate_config_value(:disable_power_on),
86
- folder: locate_config_value(:folder),
88
+ name: @name_args[0],
89
+ type: "clone",
90
+ template: locate_config_value(:template),
91
+ targethost: locate_config_value(:targethost),
92
+ datacenter: locate_config_value(:datacenter),
93
+ poweron: !locate_config_value(:disable_power_on),
94
+ folder: locate_config_value(:folder),
87
95
  resource_pool: locate_config_value(:pool),
88
96
  }
89
97
  end
90
98
 
99
+ # determine the IP address to use to bootstrap the machine with chef
100
+ #
91
101
  def before_bootstrap
92
102
  super
93
103
 
94
- config[:chef_node_name] = locate_config_value(:chef_node_name) ? locate_config_value(:chef_node_name) : server.name
104
+ config[:chef_node_name] = locate_config_value(:chef_node_name) || server.name
95
105
 
96
- # determine the IP address to use to bootstrap the machine with chef
97
106
  config[:bootstrap_ip_address] = hostname_for_server
98
107
  end
99
108
 
109
+ # Gets the ipaddress for the VM to bootstrap with
110
+ #
100
111
  def hostname_for_server
101
112
  ipaddress = service.ipaddress
102
113
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  #
3
3
  # Author:: Chef Partner Engineering (<partnereng@chef.io>)
4
- # Copyright:: Copyright (c) 2017 Chef Software, Inc.
4
+ # Copyright:: Copyright (c) 2017-2018 Chef Software, Inc.
5
5
  # License:: Apache License, Version 2.0
6
6
  #
7
7
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,65 +17,70 @@
17
17
  # limitations under the License.
18
18
  #
19
19
 
20
- require 'chef/knife'
21
- require 'chef/knife/cloud/server/create_command'
22
- require 'chef/knife/cloud/server/create_options'
23
- require 'chef/knife/cloud/vcenter_service'
24
- require 'chef/knife/cloud/vcenter_service_helpers'
25
- require 'chef/knife/cloud/vcenter_service_options'
20
+ require "chef/knife"
21
+ require "chef/knife/cloud/server/create_command"
22
+ require "chef/knife/cloud/server/create_options"
23
+ require "chef/knife/cloud/vcenter_service"
24
+ require "chef/knife/cloud/vcenter_service_helpers"
25
+ require "chef/knife/cloud/vcenter_service_options"
26
26
 
27
27
  class Chef
28
+ # The main knife class
28
29
  class Knife
30
+ # The main cloud class from knife-cloud
29
31
  class Cloud
32
+ # Extends the ServerCreateCommand for specific vCenter
30
33
  class VcenterVmCreate < Chef::Knife::Cloud::ServerCreateCommand
31
34
  include VcenterServiceHelpers
32
35
  include VcenterServiceOptions
33
36
  include ServerCreateOptions
34
37
 
35
- banner 'knife vcenter vm create NAME'
38
+ banner "knife vcenter vm create NAME"
36
39
 
37
40
  option :targethost,
38
- long: "--targethost HOST",
41
+ long: "--targethost HOST",
39
42
  description: "vCenter host on which the new VM should be created"
40
43
 
41
44
  option :folder,
42
- long: "--folder FOLDER",
45
+ long: "--folder FOLDER",
43
46
  description: "Folder in which the machine will reside"
44
47
 
45
48
  option :datastore,
46
- long: "--datastore DATASTORE",
49
+ long: "--datastore DATASTORE",
47
50
  description: "Datastore to be used for the disks etc"
48
51
 
49
52
  option :resource_pool,
50
- long: "--resource_pool RESOURCEPOOOL",
53
+ long: "--resource_pool RESOURCEPOOOL",
51
54
  description: "Resource Pool to create the machine"
52
55
 
53
-
56
+ # Validates the parameters, you need that unique name person!
57
+ #
54
58
  def validate_params!
55
59
  super
56
60
 
57
61
  if @name_args.empty?
58
- ui.error('You must provide the name of the new machine')
62
+ ui.error("You must provide the name of the new machine")
59
63
  end
60
64
 
61
65
  check_for_missing_config_values!(:targethost, :datastore, :folder)
62
66
  end
63
67
 
68
+ # Sets up the create options and puts them
69
+ #
64
70
  def before_exec_command
65
71
  super
66
72
 
67
73
  @create_options = {
68
- name: @name_args[0],
69
- type: "create",
70
- targethost: locate_config_value(:targethost),
71
- folder: locate_config_value(:folder),
72
- datastore: locate_config_value(:datastore),
73
- resource_pool: locate_config_value(:resource_pool)
74
+ name: @name_args[0],
75
+ type: "create",
76
+ targethost: locate_config_value(:targethost),
77
+ folder: locate_config_value(:folder),
78
+ datastore: locate_config_value(:datastore),
79
+ resource_pool: locate_config_value(:resource_pool),
74
80
  }
75
81
 
76
82
  puts @create_options
77
83
  end
78
-
79
84
  end
80
85
  end
81
86
  end