Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from Rubocop to Chefstyle #39

Merged
merged 2 commits into from
Nov 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions .rubocop.yml

This file was deleted.

3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# frozen_string_literal: true
source "https://rubygems.org"

source 'https://rubygems.org'
gemspec
30 changes: 18 additions & 12 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
# frozen_string_literal: true
require "bundler/gem_tasks"

require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'
begin
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec)
RuboCop::RakeTask.new(:style)
RSpec::Core::RakeTask.new do |t|
t.pattern = "spec/**/*_spec.rb"
end
rescue LoadError
desc "rspec is not installed, this task is disabled"
task :spec do
abort "rspec is not installed. bundle install first to make sure all dependencies are installed."
end
end

begin
require 'github_changelog_generator/task'

GitHubChangelogGenerator::RakeTask.new :changelog do |config|
config.future_release = KnifeVrealize::VERSION
config.issues = true
require "chefstyle"
require "rubocop/rake_task"
desc "Run Chefstyle tests"
RuboCop::RakeTask.new(:style) do |task|
task.options += ["--display-cop-names", "--no-color"]
end
rescue LoadError
puts 'github_changelog_generator is not available. gem install github_changelog_generator to generate changelogs'
puts "chefstyle gem is not installed. bundle install first to make sure all dependencies are installed."
end

task default: %i[spec style]
33 changes: 16 additions & 17 deletions knife-vrealize.gemspec
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
# coding: utf-8
# frozen_string_literal: true

lib = File.expand_path('../lib', __FILE__)
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

require 'knife-vrealize/version'
require "knife-vrealize/version"

Gem::Specification.new do |spec|
spec.name = 'knife-vrealize'
spec.name = "knife-vrealize"
spec.version = KnifeVrealize::VERSION
spec.authors = ['Chef Partner Engineering']
spec.email = ['partnereng@chef.io']
spec.summary = 'Knife plugin to interact with VMware vRealize.'
spec.authors = ["Chef Software"]
spec.email = ["oss@chef.io"]
spec.summary = "Chef Infra Knife plugin to interact with VMware vRealize."
spec.description = spec.summary
spec.homepage = 'https://github.com/chef-partners/knife-vrealize'
spec.license = 'Apache 2.0'
spec.homepage = "https://github.com/chef/knife-vrealize"
spec.license = "Apache-2.0"

spec.files = `git ls-files -z`.split("\x0")
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ['lib']
spec.require_paths = ["lib"]

spec.add_dependency 'cookstyle'
spec.add_dependency 'knife-cloud', '~> 1.2.0'
spec.add_dependency 'vmware-vra', '~> 2'
spec.add_dependency 'vcoworkflows', '~> 0.2'
spec.add_dependency 'rb-readline', '~> 0.5'
spec.add_dependency "cookstyle"
spec.add_dependency "knife-cloud", "~> 1.2.0"
spec.add_dependency "vmware-vra", "~> 2"
spec.add_dependency "vcoworkflows", "~> 0.2"
spec.add_dependency "rb-readline", "~> 0.5"

spec.add_development_dependency 'bundler', '~> 1.7'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rubocop', '~> 0.35'
spec.add_development_dependency "rake", ">= 10.0"
spec.add_development_dependency "chefstyle", "~> 0.13.3"
end
54 changes: 27 additions & 27 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:: Copyright (c) 2015 Chef Software, Inc.
# Copyright:: 2015-2019, Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -18,18 +18,18 @@
# limitations under the License.
#

require 'chef/knife/cloud/exceptions'
require 'chef/knife/cloud/service'
require 'chef/knife/cloud/helpers'
require 'chef/knife/cloud/vra_service_helpers'
require 'vra'
require "chef/knife/cloud/exceptions"
require "chef/knife/cloud/service"
require "chef/knife/cloud/helpers"
require "chef/knife/cloud/vra_service_helpers"
require "vra"

class Chef
class Knife
class Cloud
class VraService < Service
include VraServiceHelpers
def initialize(options={})
def initialize(options = {})
super(options)

@username = options[:username]
Expand All @@ -51,7 +51,7 @@ def connection
)
end

def create_server(options={})
def create_server(options = {})
submitted_request = catalog_request(options).submit
ui.msg("Catalog request #{submitted_request.id} submitted.")
wait_for_request(submitted_request, options[:wait_time].to_i, options[:refresh_rate])
Expand All @@ -61,28 +61,28 @@ def create_server(options={})
raise CloudExceptions::ServerCreateError, submitted_request.completion_details if submitted_request.failed?

servers = submitted_request.resources.select(&:vm?)
raise CloudExceptions::ServerCreateError, 'The vRA request created more than one server, but we were only expecting 1' if servers.length > 1
raise CloudExceptions::ServerCreateError, 'The vRA request did not create any servers' if servers.length.zero?
raise CloudExceptions::ServerCreateError, "The vRA request created more than one server, but we were only expecting 1" if servers.length > 1
raise CloudExceptions::ServerCreateError, "The vRA request did not create any servers" if servers.length == 0

servers.first
end

def delete_server(instance_id)
server = get_server(instance_id)
server_summary(server)
ui.msg('')
ui.msg("")

if server.status == 'DELETED'
if server.status == "DELETED"
ui.warn("Server is already deleted.\n")
return
end

ui.confirm('Do you really want to delete this server')
ui.confirm("Do you really want to delete this server")

destroy_request = server.destroy
ui.msg("Destroy request #{destroy_request.id} submitted.")
wait_for_request(destroy_request)
ui.msg('Destroy request complete.')
ui.msg("Destroy request complete.")
request_summary(destroy_request)
end

Expand All @@ -102,22 +102,22 @@ def get_server(instance_id)
connection.resources.by_id(instance_id)
end

def server_summary(server, _columns_with_info=nil)
msg_pair('Server ID', server.id)
msg_pair('Server Name', server.name)
msg_pair('IP Addresses', server.ip_addresses.nil? ? 'none' : server.ip_addresses.join(', '))
msg_pair('Status', server.status)
msg_pair('Catalog Name', server.catalog_name)
msg_pair('Owner IDs', server.owner_ids.empty? ? 'none' : server.owner_ids.join(', '))
msg_pair('Owner Names', server.owner_names.empty? ? 'none' : server.owner_names.join(', '))
def server_summary(server, _columns_with_info = nil)
msg_pair("Server ID", server.id)
msg_pair("Server Name", server.name)
msg_pair("IP Addresses", server.ip_addresses.nil? ? "none" : server.ip_addresses.join(", "))
msg_pair("Status", server.status)
msg_pair("Catalog Name", server.catalog_name)
msg_pair("Owner IDs", server.owner_ids.empty? ? "none" : server.owner_ids.join(", "))
msg_pair("Owner Names", server.owner_names.empty? ? "none" : server.owner_names.join(", "))
end

def request_summary(request)
ui.msg('')
msg_pair('Request Status', request.status)
msg_pair('Completion State', request.completion_state)
msg_pair('Completion Details', request.completion_details)
ui.msg('')
ui.msg("")
msg_pair("Request Status", request.status)
msg_pair("Completion State", request.completion_state)
msg_pair("Completion Details", request.completion_details)
ui.msg("")
end

def catalog_request(options)
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:: Copyright (c) 2015 Chef Software, Inc.
# Copyright:: 2015-2019, Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -18,7 +18,7 @@
# limitations under the License.
#

require 'chef/knife/cloud/helpers'
require "chef/knife/cloud/helpers"

class Chef
class Knife
Expand All @@ -39,10 +39,10 @@ def verify_ssl?
!locate_config_value(:vra_disable_ssl_verify)
end

def wait_for_request(request, wait_time=600, refresh_rate=2)
print 'Waiting for request to complete.'
def wait_for_request(request, wait_time = 600, refresh_rate = 2)
print "Waiting for request to complete."

last_status = ''
last_status = ""

begin
Timeout.timeout(wait_time) do
Expand All @@ -55,7 +55,7 @@ def wait_for_request(request, wait_time=600, refresh_rate=2)
end

if last_status == request.status
print '.'
print "."
else
last_status = request.status
print "\n"
Expand All @@ -66,7 +66,7 @@ def wait_for_request(request, wait_time=600, refresh_rate=2)
end
end
rescue Timeout::Error
ui.msg('')
ui.msg("")
ui.error("Request did not complete in #{wait_time} seconds. Check the Requests tab in the vRA UI for more information.")
exit 1
end
Expand All @@ -81,7 +81,7 @@ def check_for_missing_config_values!(*keys)
missing = keys.select { |x| locate_config_value(x).nil? }

unless missing.empty?
ui.error("The following required parameters are missing: #{missing.join(', ')}")
ui.error("The following required parameters are missing: #{missing.join(", ")}")
exit(1)
end
end
Expand Down
32 changes: 16 additions & 16 deletions 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:: Copyright (c) 2015 Chef Software, Inc.
# Copyright:: 2015-2019, Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -27,37 +27,37 @@ module VraServiceOptions
def self.included(includer)
includer.class_eval do
option :vra_base_url,
long: '--vra-base-url API_URL',
description: 'URL for the vRA server',
proc: proc { |url| url.sub(%r{/(\/)+$/}, '') }
long: "--vra-base-url API_URL",
description: "URL for the vRA server",
proc: proc { |url| url.sub(%r{/(\/)+$/}, "") }

option :vra_username,
long: '--vra-username USERNAME',
description: 'Username to use with the vRA API'
long: "--vra-username USERNAME",
description: "Username to use with the vRA API"

option :vra_password,
long: '--vra-password PASSWORD',
description: 'Password to use with the vRA API'
long: "--vra-password PASSWORD",
description: "Password to use with the vRA API"

option :vra_tenant,
long: '--vra-tenant TENANT',
description: 'Tenant name (organization) to use with the vRA API'
long: "--vra-tenant TENANT",
description: "Tenant name (organization) to use with the vRA API"

option :vra_disable_ssl_verify,
long: '--vra-disable-ssl-verify',
description: 'Skip any SSL verification for the vRA API',
long: "--vra-disable-ssl-verify",
description: "Skip any SSL verification for the vRA API",
boolean: true,
default: false

option :vra_page_size,
long: '--page-size NUM_OF_ITEMS',
description: 'Maximum number of items to fetch from the vRA API when pagination is forced',
long: "--page-size NUM_OF_ITEMS",
description: "Maximum number of items to fetch from the vRA API when pagination is forced",
default: 200,
proc: proc { |page_size| page_size.to_i }

option :request_refresh_rate,
long: '--request-refresh-rate SECS',
description: 'Number of seconds to sleep between each check of the request status, defaults to 2',
long: "--request-refresh-rate SECS",
description: "Number of seconds to sleep between each check of the request status, defaults to 2",
default: 2,
proc: proc { |secs| secs.to_i }
end
Expand Down
Loading