Skip to content

Commit

Permalink
Fix for handling of config values for Chef 16
Browse files Browse the repository at this point in the history
Signed-off-by: Kapil Chouhan <kapil.chouhan@msystechnologies.com>
  • Loading branch information
Kapil Chouhan committed Jul 23, 2020
1 parent 6f87f60 commit 6b504b3
Show file tree
Hide file tree
Showing 27 changed files with 117 additions and 105 deletions.
7 changes: 0 additions & 7 deletions .expeditor/verify.pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ expeditor:
timeout_in_minutes: 30

steps:
- label: run-specs-ruby-2.5
command:
- .expeditor/run_linux_tests.sh rake
expeditor:
executor:
docker:
image: ruby:2.5-buster
- label: run-specs-ruby-2.6
command:
- .expeditor/run_linux_tests.sh rake
Expand Down
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ end

group :test do
gem "chef"
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.6")
gem "chef-zero", "~> 14"
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.7")
gem "chef-zero", "~> 15"
end
gem "chefstyle", "~> 1.0"
gem "rake", ">= 10.0"
Expand Down
2 changes: 1 addition & 1 deletion knife-vrealize.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
spec.files = Dir["lib/**/*"] + %w{LICENSE}
spec.require_paths = ["lib"]

spec.required_ruby_version = ">= 2.5"
spec.required_ruby_version = ">= 2.6"

spec.add_dependency "knife-cloud", ">= 1.2.0", "< 5.0"
spec.add_dependency "vmware-vra", "~> 2"
Expand Down
4 changes: 2 additions & 2 deletions lib/chef/knife/cloud/vra_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#
# Author:: Chef Partner Engineering (<partnereng@chef.io>)
# Copyright:: 2015-2019, Chef Software, Inc.
# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -30,7 +30,7 @@ class Cloud
class VraService < Service
include VraServiceHelpers
def initialize(options = {})
super(options)
super(config: options)

@username = options[:username]
@password = options[:password]
Expand Down
16 changes: 8 additions & 8 deletions lib/chef/knife/cloud/vra_service_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#
# Author:: Chef Partner Engineering (<partnereng@chef.io>)
# Copyright:: 2015-2019, Chef Software, Inc.
# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -27,16 +27,16 @@ module VraServiceHelpers
include Chef::Knife::Cloud::Helpers

def create_service_instance
Chef::Knife::Cloud::VraService.new(username: locate_config_value(:vra_username),
password: locate_config_value(:vra_password),
base_url: locate_config_value(:vra_base_url),
tenant: locate_config_value(:vra_tenant),
page_size: locate_config_value(:vra_page_size),
Chef::Knife::Cloud::VraService.new(username: config[:vra_username],
password: config[:vra_password],
base_url: config[:vra_base_url],
tenant: config[:vra_tenant],
page_size: config[:vra_page_size],
verify_ssl: verify_ssl?)
end

def verify_ssl?
!locate_config_value(:vra_disable_ssl_verify)
!config[:vra_disable_ssl_verify]
end

def wait_for_request(request, wait_time = 600, refresh_rate = 2)
Expand Down Expand Up @@ -78,7 +78,7 @@ def validate!

# rubocop:disable Style/GuardClause
def check_for_missing_config_values!(*keys)
missing = keys.select { |x| locate_config_value(x).nil? }
missing = keys.select { |x| config[x].nil? }

unless missing.empty?
ui.error("The following required parameters are missing: #{missing.join(", ")}")
Expand Down
2 changes: 1 addition & 1 deletion lib/chef/knife/cloud/vra_service_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#
# Author:: Chef Partner Engineering (<partnereng@chef.io>)
# Copyright:: 2015-2019, Chef Software, Inc.
# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
13 changes: 8 additions & 5 deletions lib/chef/knife/vra_catalog_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#
# Author:: Chef Partner Engineering (<partnereng@chef.io>)
# Copyright:: 2015-2019, Chef Software, Inc.
# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -20,19 +20,22 @@

require "chef/knife"
require "chef/knife/cloud/list_resource_command"
require_relative "cloud/vra_service"
require_relative "cloud/vra_service_helpers"
require_relative "cloud/vra_service_options"

class Chef
class Knife
class Cloud
class VraCatalogList < ResourceListCommand
include VraServiceHelpers
include VraServiceOptions

banner "knife vra catalog list"

deps do

This comment has been minimized.

Copy link
@tas50

tas50 Jul 24, 2020

Contributor

Nice fix here. This will make it all run better

require_relative "cloud/vra_service"
require_relative "cloud/vra_service_helpers"
include VraServiceHelpers
end

option :entitled,
long: "--entitled-only",
description: "only list entitled vRA catalog entries",
Expand All @@ -52,7 +55,7 @@ def before_exec_command
end

def query_resource
@service.list_catalog_items(locate_config_value(:entitled))
@service.list_catalog_items(config[:entitled])
end

def format_status_value(status)
Expand Down
27 changes: 15 additions & 12 deletions lib/chef/knife/vra_server_create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#
# Author:: Chef Partner Engineering (<partnereng@chef.io>)
# Copyright:: 2015-2019, Chef Software, Inc.
# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -21,8 +21,6 @@
require "chef/knife"
require "chef/knife/cloud/server/create_command"
require "chef/knife/cloud/server/create_options"
require_relative "cloud/vra_service"
require_relative "cloud/vra_service_helpers"
require_relative "cloud/vra_service_options"

class Chef
Expand All @@ -35,6 +33,11 @@ class VraServerCreate < ServerCreateCommand

banner "knife vra server create CATALOG_ID (options)"

deps do
require_relative "cloud/vra_service"
require_relative "cloud/vra_service_helpers"
end

option :cpus,
long: "--cpus NUM_CPUS",
description: "Number of CPUs the server should have"
Expand Down Expand Up @@ -97,22 +100,22 @@ def before_exec_command

@create_options = {
catalog_id: @name_args.first,
cpus: locate_config_value(:cpus),
memory: locate_config_value(:memory),
requested_for: locate_config_value(:requested_for),
subtenant_id: locate_config_value(:subtenant_id),
lease_days: locate_config_value(:lease_days),
notes: locate_config_value(:notes),
cpus: config[:cpus],
memory: config[:memory],
requested_for: config[:requested_for],
subtenant_id: config[:subtenant_id],
lease_days: config[:lease_days],
notes: config[:notes],
extra_params: extra_params,
wait_time: locate_config_value(:server_create_timeout),
refresh_rate: locate_config_value(:request_refresh_rate),
wait_time: config[:server_create_timeout],
refresh_rate: config[:request_refresh_rate],
}
end

def before_bootstrap
super

config[:chef_node_name] = locate_config_value(:chef_node_name) ? locate_config_value(:chef_node_name) : server.name
config[:chef_node_name] = config[:chef_node_name] ? config[:chef_node_name] : server.name
config[:bootstrap_ip_address] = hostname_for_server
end

Expand Down
11 changes: 7 additions & 4 deletions lib/chef/knife/vra_server_delete.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#
# Author:: Chef Partner Engineering (<partnereng@chef.io>)
# Copyright:: 2015-2019, Chef Software, Inc.
# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -21,20 +21,23 @@
require "chef/knife"
require "chef/knife/cloud/server/delete_options"
require "chef/knife/cloud/server/delete_command"
require_relative "cloud/vra_service"
require_relative "cloud/vra_service_helpers"
require_relative "cloud/vra_service_options"

class Chef
class Knife
class Cloud
class VraServerDelete < ServerDeleteCommand
include ServerDeleteOptions
include VraServiceHelpers
include VraServiceOptions

banner "knife vra server delete RESOURCE_ID [RESOURCE_ID] (options)"

deps do
require_relative "cloud/vra_service"
require_relative "cloud/vra_service_helpers"
include VraServiceHelpers
end

# rubocop:disable Style/GuardClause
def validate_params!
if @name_args.empty?
Expand Down
11 changes: 7 additions & 4 deletions lib/chef/knife/vra_server_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#
# Author:: Chef Partner Engineering (<partnereng@chef.io>)
# Copyright:: 2015-2019, Chef Software, Inc.
# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -21,19 +21,22 @@
require "chef/knife"
require "chef/knife/cloud/server/list_command"
require "chef/knife/cloud/server/list_options"
require_relative "cloud/vra_service"
require_relative "cloud/vra_service_helpers"
require_relative "cloud/vra_service_options"

class Chef
class Knife
class Cloud
class VraServerList < ServerListCommand
include VraServiceHelpers
include VraServiceOptions

banner "knife vra server list"

deps do
require_relative "cloud/vra_service"
require_relative "cloud/vra_service_helpers"
include VraServiceHelpers
end

def before_exec_command
@columns_with_info = [
{ label: "Resource ID", key: "id" },
Expand Down
11 changes: 7 additions & 4 deletions lib/chef/knife/vra_server_show.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#
# Author:: Chef Partner Engineering (<partnereng@chef.io>)
# Copyright:: 2015-2019, Chef Software, Inc.
# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -21,20 +21,23 @@
require "chef/knife"
require "chef/knife/cloud/server/show_options"
require "chef/knife/cloud/server/show_command"
require_relative "cloud/vra_service"
require_relative "cloud/vra_service_helpers"
require_relative "cloud/vra_service_options"

class Chef
class Knife
class Cloud
class VraServerShow < ServerShowCommand
include ServerShowOptions
include VraServiceHelpers
include VraServiceOptions

banner "knife vra server show RESOURCE_ID (options)"

deps do
require_relative "cloud/vra_service"
require_relative "cloud/vra_service_helpers"
include VraServiceHelpers
end

def validate_params!
if @name_args.empty?
ui.error("You must supply a Resource ID for a server to display.")
Expand Down
17 changes: 8 additions & 9 deletions lib/chef/knife/vro_workflow_execute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#
# Author:: Chef Partner Engineering (<partnereng@chef.io>)
# Copyright:: 2015-2019, Chef Software, Inc.
# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -60,14 +60,14 @@ class VroWorkflowExecute < Chef::Knife
default: 300

def verify_ssl?
!locate_config_value(:vro_disable_ssl_verify)
!config[:vro_disable_ssl_verify]
end

def vro_config
@vro_config ||= VcoWorkflows::Config.new(
url: locate_config_value(:vro_base_url),
username: locate_config_value(:vro_username),
password: locate_config_value(:vro_password),
url: config[:vro_base_url],
username: config[:vro_username],
password: config[:vro_password],
verify_ssl: verify_ssl?
)
end
Expand Down Expand Up @@ -105,7 +105,7 @@ def execute_workflow
end

def wait_for_workflow
wait_time = locate_config_value(:request_timeout)
wait_time = config[:request_timeout]
Timeout.timeout(wait_time) do
loop do
token = vro_client.token
Expand All @@ -120,7 +120,7 @@ def wait_for_workflow

def missing_config_parameters
%i{vro_username vro_password vro_base_url}.each_with_object([]) do |param, memo|
memo << param if locate_config_value(param).nil?
memo << param if config[param].nil?
end
end

Expand All @@ -129,7 +129,6 @@ def validate!
print_error_and_exit("The following parameters are missing but required:" \
"#{missing_config_parameters.join(", ")}")
end

print_error_and_exit("You must supply a workflow name.") if @name_args.empty?
end

Expand Down Expand Up @@ -165,7 +164,7 @@ def print_execution_log

def set_parameters
self.workflow_name = @name_args.shift
self.workflow_id = locate_config_value(:vro_workflow_id)
self.workflow_id = config[:vro_workflow_id]
self.parameters = parse_and_validate_params!(@name_args)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/knife-vrealize/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#
# Author:: Chef Partner Engineering (<partnereng@chef.io>)
# Copyright:: 2015-2019, Chef Software, Inc.
# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
#
# Author:: Chef Partner Engineering (<partnereng@chef.io>)
# Copyright:: Copyright (c) 2015 Chef Software, Inc.
# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Loading

0 comments on commit 6b504b3

Please sign in to comment.