knife-oci 2.0.0 → 2.0.1

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
2
  SHA1:
3
- metadata.gz: 59081952975a5ed82060447d1f172d47aa62095a
4
- data.tar.gz: 62d68779e1ff5d745c428d941e60c7ff3455b9d4
3
+ metadata.gz: f461931833d1c8eaf21ee448e8402f49eb4c10c7
4
+ data.tar.gz: 8d6715c84720b950ed4661b484895fd3cfa89216
5
5
  SHA512:
6
- metadata.gz: 2fb72b40c8c75d8f842eadf9f065a5251655eb3a88e91836cc8410e7280c611ed3e3ed31796556b8aabb16efbe187b2bcf063c2fad2ef235b7af21a8f223e4c2
7
- data.tar.gz: 83a4e16965ddf3436f239a5218f57926d3e400a4b96d0449ffb504f7fb6e7b47789d73f4dc851dd6169c5aa4b5a6d2c42fa0a4535e1db2e5a835a37c5aebe543
6
+ metadata.gz: 36c6507626cbd2e23b32c805d7cf4babb281ea2a03dbdd2ab6ae1c86de603f8d133e9cd2c6c5aff00342630947e2d57a7ca5dbcdfe65d52a6873f165251a0cf9
7
+ data.tar.gz: 47a873568be4eaf52b67c1c563906c450e3300c1341b527e84875f506540eb25e5d2a49969089775967c5a5ed9032dbf226829e6aa759eca7e8b5a84415a8a88
@@ -173,36 +173,6 @@ class Chef
173
173
  else
174
174
  return response
175
175
  end
176
-
177
- def show_value(key, value, color = :cyan)
178
- ui.msg "#{ui.color(key, color)}: #{value}" if value && !value.to_s.empty?
179
- end
180
-
181
- # rubocop:disable Metrics/CyclomaticComplexity
182
- def display_server_info(config, instance, vnics)
183
- show_value('Display Name', instance.display_name)
184
- show_value('Instance ID', instance.id)
185
- show_value('Lifecycle State', instance.lifecycle_state)
186
- show_value('Availability Domain', instance.availability_domain)
187
- show_value('Compartment Name', instance.compartment_name) if instance.respond_to? :compartment_name
188
- show_value('Compartment ID', instance.compartment_id)
189
- show_value('Region', instance.region)
190
- show_value('Image Name', instance.image_name) if instance.respond_to? :image_name
191
- show_value('Image ID', instance.image_id)
192
- show_value('Shape', instance.shape)
193
- show_value('VCN Name', instance.vcn_name) if instance.respond_to? :vcn_name
194
- show_value('VCN ID', instance.vcn_id) if instance.respond_to? :vcn_id
195
- show_value('Launched', instance.launchtime) if instance.respond_to? :launchtime
196
- vnics.each_index do |index|
197
- prefix = vnics[index].is_primary ? 'Primary' : 'Secondary'
198
- show_value("#{prefix} Public IP Address", vnics[index].public_ip)
199
- show_value("#{prefix} Private IP Address", vnics[index].private_ip)
200
- show_value("#{prefix} Hostname", vnics[index].hostname_label)
201
- show_value("#{prefix} FQDN", vnics[index].fqdn) if vnics[index].respond_to? :fqdn
202
- show_value("#{prefix} Subnet Name", vnics[index].subnet_name) if vnics[index].respond_to? :subnet_name
203
- end
204
- show_value('Node Name', config[:chef_node_name])
205
- end
206
176
  end
207
177
  end
208
178
  end
@@ -0,0 +1,108 @@
1
+ # Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved.
2
+
3
+ require 'chef/knife'
4
+ require 'knife-oci/version'
5
+
6
+ # Methods to extend the instance model
7
+ module ServerDetails
8
+ attr_accessor :compartment_name
9
+ attr_accessor :image_name
10
+ attr_accessor :launchtime
11
+ attr_accessor :vcn_id
12
+ attr_accessor :vcn_name
13
+ end
14
+
15
+ # Methods to extend the vnic model
16
+ module VnicDetails
17
+ attr_accessor :fqdn
18
+ attr_accessor :subnet_name
19
+ attr_accessor :vcn_id
20
+ end
21
+
22
+ class Chef
23
+ class Knife
24
+ # Utility routines to fill out data for 'server show' functionality
25
+ module OciHelperShow
26
+ def lookup_compartment_name(compartment_id)
27
+ compartment = identity_client.get_compartment(compartment_id, {})
28
+ rescue OCI::Errors::ServiceError => service_error
29
+ raise unless service_error.service_code == 'NotAuthorizedOrNotFound'
30
+ else
31
+ compartment.data.name
32
+ end
33
+
34
+ def lookup_image_name(image_id)
35
+ image = compute_client.get_image(image_id, {})
36
+ rescue OCI::Errors::ServiceError => service_error
37
+ raise unless service_error.service_code == 'NotAuthorizedOrNotFound'
38
+ else
39
+ image.data.display_name
40
+ end
41
+
42
+ def lookup_vcn_name(vcn_id)
43
+ vcn = network_client.get_vcn(vcn_id, {})
44
+ rescue OCI::Errors::ServiceError => service_error
45
+ raise unless service_error.service_code == 'NotAuthorizedOrNotFound'
46
+ else
47
+ vcn.data.display_name
48
+ end
49
+
50
+ def add_server_details(server, vcn_id)
51
+ server.extend ServerDetails
52
+
53
+ server.launchtime = server.time_created.strftime('%a, %e %b %Y %T %Z')
54
+ server.compartment_name = lookup_compartment_name(server.compartment_id)
55
+ server.image_name = lookup_image_name(server.image_id)
56
+ server.vcn_id = vcn_id
57
+ server.vcn_name = lookup_vcn_name(vcn_id)
58
+ end
59
+
60
+ def add_vnic_details(vnic)
61
+ vnic.extend VnicDetails
62
+
63
+ begin
64
+ subnet = network_client.get_subnet(vnic.subnet_id, {})
65
+ rescue OCI::Errors::ServiceError => service_error
66
+ raise unless service_error.service_code == 'NotAuthorizedOrNotFound'
67
+ else
68
+ vnic.fqdn = vnic.hostname_label + '.' + subnet.data.subnet_domain_name if
69
+ subnet.data && subnet.data.subnet_domain_name && vnic.hostname_label
70
+ vnic.subnet_name = subnet.data.display_name if
71
+ subnet.data && subnet.data.display_name
72
+ # piggyback the vcn_id from here, so we can avoid a few network calls
73
+ vnic.vcn_id = subnet.data.vcn_id
74
+ end
75
+ end
76
+
77
+ def show_value(key, value, color = :cyan)
78
+ ui.msg "#{ui.color(key, color)}: #{value}" if value && !value.to_s.empty?
79
+ end
80
+
81
+ # rubocop:disable Metrics/CyclomaticComplexity
82
+ def display_server_info(config, instance, vnics)
83
+ show_value('Display Name', instance.display_name)
84
+ show_value('Instance ID', instance.id)
85
+ show_value('Lifecycle State', instance.lifecycle_state)
86
+ show_value('Availability Domain', instance.availability_domain)
87
+ show_value('Compartment Name', instance.compartment_name) if instance.respond_to? :compartment_name
88
+ show_value('Compartment ID', instance.compartment_id)
89
+ show_value('Region', instance.region)
90
+ show_value('Image Name', instance.image_name) if instance.respond_to? :image_name
91
+ show_value('Image ID', instance.image_id)
92
+ show_value('Shape', instance.shape)
93
+ show_value('VCN Name', instance.vcn_name) if instance.respond_to? :vcn_name
94
+ show_value('VCN ID', instance.vcn_id) if instance.respond_to? :vcn_id
95
+ show_value('Launched', instance.launchtime) if instance.respond_to? :launchtime
96
+ vnics.each_index do |index|
97
+ prefix = vnics[index].is_primary ? 'Primary' : 'Secondary'
98
+ show_value("#{prefix} Public IP Address", vnics[index].public_ip)
99
+ show_value("#{prefix} Private IP Address", vnics[index].private_ip)
100
+ show_value("#{prefix} Hostname", vnics[index].hostname_label)
101
+ show_value("#{prefix} FQDN", vnics[index].fqdn) if vnics[index].respond_to? :fqdn
102
+ show_value("#{prefix} Subnet Name", vnics[index].subnet_name) if vnics[index].respond_to? :subnet_name
103
+ end
104
+ show_value('Node Name', config[:chef_node_name])
105
+ end
106
+ end
107
+ end
108
+ end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'chef/knife'
4
4
  require 'chef/knife/oci_helper'
5
+ require 'chef/knife/oci_helper_show'
5
6
  require 'chef/knife/oci_common_options'
6
7
 
7
8
  class Chef
@@ -11,13 +12,14 @@ class Chef
11
12
  banner 'knife oci server create (options)'
12
13
 
13
14
  include OciHelper
15
+ include OciHelperShow
14
16
  include OciCommonOptions
15
17
 
16
18
  # Port for SSH - might want to parameterize this in the future.
17
19
  SSH_PORT = 22
18
20
 
19
21
  WAIT_FOR_SSH_INTERVAL_SECONDS = 2
20
- DEFAULT_WAIT_FOR_SSH_MAX_SECONDS = 180
22
+ DEFAULT_WAIT_FOR_SSH_MAX_SECONDS = 300
21
23
  DEFAULT_WAIT_TO_STABILIZE_SECONDS = 40
22
24
 
23
25
  deps do
@@ -26,14 +28,6 @@ class Chef
26
28
  Chef::Knife::Bootstrap.load_deps
27
29
  end
28
30
 
29
- option :oci_config_file,
30
- long: '--oci-config-file FILE',
31
- description: 'The path to the OCI config file. Default: ~/.oci/config'
32
-
33
- option :oci_profile,
34
- long: '--oci-profile PROFILE',
35
- description: 'The profile to load from the OCI config file. Default: DEFAULT'
36
-
37
31
  option :availability_domain,
38
32
  long: '--availability-domain AD',
39
33
  description: 'The Availability Domain of the instance. (required)'
@@ -135,21 +129,10 @@ class Chef
135
129
  instance = response.data
136
130
 
137
131
  ui.msg "Launched instance '#{instance.display_name}' [#{instance.id}]"
138
- show_value('Display Name', instance.display_name)
139
- show_value('Instance ID', instance.id)
140
- show_value('Availability Domain', instance.availability_domain)
141
- show_value('Compartment ID', instance.compartment_id)
142
- show_value('Region', instance.region)
143
- show_value('Image ID', instance.image_id)
144
- show_value('Shape', instance.shape)
145
-
146
132
  instance = wait_for_instance_running(instance.id)
147
-
148
133
  ui.msg "Instance '#{instance.display_name}' is now running."
149
134
 
150
135
  vnic = get_vnic(instance.id, instance.compartment_id)
151
- show_value('Public IP Address', vnic.public_ip)
152
- show_value('Private IP Address', vnic.private_ip)
153
136
 
154
137
  unless wait_for_ssh(vnic.public_ip, SSH_PORT, WAIT_FOR_SSH_INTERVAL_SECONDS, config[:wait_for_ssh_max])
155
138
  error_and_exit 'Timed out while waiting for SSH access.'
@@ -167,6 +150,9 @@ class Chef
167
150
  ui.msg "Created and bootstrapped node '#{config[:chef_node_name]}'."
168
151
  ui.msg "\n"
169
152
 
153
+ add_vnic_details(vnic)
154
+ add_server_details(instance, vnic.vcn_id)
155
+
170
156
  display_server_info(config, instance, [vnic])
171
157
  end
172
158
 
@@ -31,7 +31,7 @@ class Chef
31
31
 
32
32
  option :purge,
33
33
  long: '--purge',
34
- description: 'Remove the corresponding node from the Chef Server. The instance display name will be used as the node name, unless --node-name is specified.'
34
+ description: 'Remove the corresponding node and client from the Chef Server. The instance display name will be used as the node name, unless --node-name is specified.'
35
35
 
36
36
  option :chef_node_name,
37
37
  short: '-N NAME',
@@ -62,6 +62,7 @@ class Chef
62
62
 
63
63
  terminate_instance(config[:instance_id])
64
64
  delete_chef_node(chef_node) if config[:purge]
65
+ delete_chef_client(node_name) if config[:purge]
65
66
 
66
67
  wait_for_instance_terminated(config[:instance_id], wait_for) if wait_for
67
68
  end
@@ -82,6 +83,13 @@ class Chef
82
83
  ui.msg "Deleted Chef node '#{node.name}'"
83
84
  end
84
85
 
86
+ def delete_chef_client(client_name)
87
+ object = Chef::ApiClient.load(client_name)
88
+ return unless object && !object.validator
89
+ object.destroy
90
+ ui.msg "Deleted Chef client '#{client_name}'"
91
+ end
92
+
85
93
  def wait_for_instance_terminated(instance_id, wait_for)
86
94
  print ui.color('Waiting for instance to terminate...', :magenta)
87
95
  begin
@@ -3,31 +3,16 @@
3
3
  require 'chef/knife'
4
4
  require 'chef/knife/oci_common_options'
5
5
  require 'chef/knife/oci_helper'
6
-
7
- # Methods to extend the instance model
8
- module ServerDetails
9
- attr_accessor :compartment_name
10
- attr_accessor :image_name
11
- attr_accessor :launchtime
12
- attr_accessor :vcn_id
13
- attr_accessor :vcn_name
14
- end
15
-
16
- # Methods to extend the vnic model
17
- module VnicDetails
18
- attr_accessor :fqdn
19
- attr_accessor :subnet_name
20
- attr_accessor :vcn_id
21
- end
6
+ require 'chef/knife/oci_helper_show'
22
7
 
23
8
  class Chef
24
9
  class Knife
25
- # List OCI instances. Note that this lists all instances in a
26
- # compartment, not just those that are set up as Chef nodes.
10
+ # List details of a particular OCI instance.
27
11
  class OciServerShow < Knife
28
12
  banner 'knife oci server show (options)'
29
13
 
30
14
  include OciHelper
15
+ include OciHelperShow
31
16
  include OciCommonOptions
32
17
 
33
18
  deps do
@@ -35,60 +20,9 @@ class Chef
35
20
  end
36
21
 
37
22
  option :instance_id,
38
- long: '--instance_id LIMIT',
23
+ long: '--instance_id INSTANCE',
39
24
  description: 'The OCID of the server to display. (required)'
40
25
 
41
- def lookup_compartment_name(compartment_id)
42
- compartment = identity_client.get_compartment(compartment_id, {})
43
- rescue OCI::Errors::ServiceError => service_error
44
- raise unless service_error.service_code == 'NotAuthorizedOrNotFound'
45
- else
46
- compartment.data.name
47
- end
48
-
49
- def lookup_image_name(image_id)
50
- image = compute_client.get_image(image_id, {})
51
- rescue OCI::Errors::ServiceError => service_error
52
- raise unless service_error.service_code == 'NotAuthorizedOrNotFound'
53
- else
54
- image.data.display_name
55
- end
56
-
57
- def lookup_vcn_name(vcn_id)
58
- vcn = network_client.get_vcn(vcn_id, {})
59
- rescue OCI::Errors::ServiceError => service_error
60
- raise unless service_error.service_code == 'NotAuthorizedOrNotFound'
61
- else
62
- vcn.data.display_name
63
- end
64
-
65
- def add_server_details(server, vcn_id)
66
- server.extend ServerDetails
67
-
68
- server.launchtime = server.time_created.strftime('%a, %e %b %Y %T %Z')
69
- server.compartment_name = lookup_compartment_name(server.compartment_id)
70
- server.image_name = lookup_image_name(server.image_id)
71
- server.vcn_id = vcn_id
72
- server.vcn_name = lookup_vcn_name(vcn_id)
73
- end
74
-
75
- def add_vnic_details(vnic)
76
- vnic.extend VnicDetails
77
-
78
- begin
79
- subnet = network_client.get_subnet(vnic.subnet_id, {})
80
- rescue OCI::Errors::ServiceError => service_error
81
- raise unless service_error.service_code == 'NotAuthorizedOrNotFound'
82
- else
83
- vnic.fqdn = vnic.hostname_label + '.' + subnet.data.subnet_domain_name if
84
- subnet.data && subnet.data.subnet_domain_name && vnic.hostname_label
85
- vnic.subnet_name = subnet.data.display_name if
86
- subnet.data && subnet.data.display_name
87
- # piggyback the vcn_id from here, so we can avoid a few network calls
88
- vnic.vcn_id = subnet.data.vcn_id
89
- end
90
- end
91
-
92
26
  def run
93
27
  validate_required_params(%i[instance_id], config)
94
28
  vnic_array = []
@@ -103,10 +37,10 @@ class Chef
103
37
  raise unless service_error.service_code == 'NotAuthorizedOrNotFound'
104
38
  else
105
39
  add_vnic_details(vnic_info.data)
106
- # for now, only display information for primary vnic
107
40
  if vnic_info.data.is_primary == true
41
+ vnic_array.unshift(vnic_info.data) # make primary interface first in the array
42
+ else
108
43
  vnic_array.push(vnic_info.data)
109
- break
110
44
  end
111
45
  end
112
46
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Knife
4
4
  module OCI
5
- VERSION = '2.0.0'.freeze
5
+ VERSION = '2.0.1'.freeze
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,33 +1,33 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-oci
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oracle
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-11 00:00:00.000000000 Z
11
+ date: 2019-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oci
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '2.0'
20
- - - ">="
20
+ - - '>='
21
21
  - !ruby/object:Gem::Version
22
22
  version: 2.0.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - "~>"
27
+ - - ~>
28
28
  - !ruby/object:Gem::Version
29
29
  version: '2.0'
30
- - - ">="
30
+ - - '>='
31
31
  - !ruby/object:Gem::Version
32
32
  version: 2.0.0
33
33
  description: ''
@@ -38,19 +38,20 @@ executables: []
38
38
  extensions: []
39
39
  extra_rdoc_files: []
40
40
  files:
41
- - "./lib/chef/knife/oci_ad_list.rb"
42
- - "./lib/chef/knife/oci_common_options.rb"
43
- - "./lib/chef/knife/oci_compartment_list.rb"
44
- - "./lib/chef/knife/oci_helper.rb"
45
- - "./lib/chef/knife/oci_image_list.rb"
46
- - "./lib/chef/knife/oci_server_create.rb"
47
- - "./lib/chef/knife/oci_server_delete.rb"
48
- - "./lib/chef/knife/oci_server_list.rb"
49
- - "./lib/chef/knife/oci_server_show.rb"
50
- - "./lib/chef/knife/oci_shape_list.rb"
51
- - "./lib/chef/knife/oci_subnet_list.rb"
52
- - "./lib/chef/knife/oci_vcn_list.rb"
53
- - "./lib/knife-oci/version.rb"
41
+ - ./lib/chef/knife/oci_ad_list.rb
42
+ - ./lib/chef/knife/oci_common_options.rb
43
+ - ./lib/chef/knife/oci_compartment_list.rb
44
+ - ./lib/chef/knife/oci_helper.rb
45
+ - ./lib/chef/knife/oci_helper_show.rb
46
+ - ./lib/chef/knife/oci_image_list.rb
47
+ - ./lib/chef/knife/oci_server_create.rb
48
+ - ./lib/chef/knife/oci_server_delete.rb
49
+ - ./lib/chef/knife/oci_server_list.rb
50
+ - ./lib/chef/knife/oci_server_show.rb
51
+ - ./lib/chef/knife/oci_shape_list.rb
52
+ - ./lib/chef/knife/oci_subnet_list.rb
53
+ - ./lib/chef/knife/oci_vcn_list.rb
54
+ - ./lib/knife-oci/version.rb
54
55
  - LICENSE.txt
55
56
  homepage: https://github.com/oracle/knife-oci
56
57
  licenses:
@@ -63,17 +64,17 @@ require_paths:
63
64
  - lib
64
65
  required_ruby_version: !ruby/object:Gem::Requirement
65
66
  requirements:
66
- - - ">="
67
+ - - '>='
67
68
  - !ruby/object:Gem::Version
68
69
  version: 2.2.0
69
70
  required_rubygems_version: !ruby/object:Gem::Requirement
70
71
  requirements:
71
- - - ">="
72
+ - - '>='
72
73
  - !ruby/object:Gem::Version
73
74
  version: '0'
74
75
  requirements: []
75
76
  rubyforge_project:
76
- rubygems_version: 2.6.8
77
+ rubygems_version: 2.0.14.1
77
78
  signing_key:
78
79
  specification_version: 4
79
80
  summary: Chef Knife Plugin for Oracle Cloud Infrastructure