Skip to content

Commit

Permalink
convert to using chefstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
adamleff committed Mar 28, 2016
1 parent 982061f commit 9982ec1
Show file tree
Hide file tree
Showing 27 changed files with 478 additions and 473 deletions.
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
source 'https://rubygems.org'
source "https://rubygems.org"

gemspec

gem "chefstyle", git: "https://github.com/chef/chefstyle"
12 changes: 8 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'
require "bundler/gem_tasks"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec)
RuboCop::RakeTask.new(:style)

require "chefstyle"
require "rubocop/rake_task"
RuboCop::RakeTask.new(:style) do |task|
task.options << "--display-cop-names"
end

task default: [ :spec, :style ]
30 changes: 15 additions & 15 deletions knife-oraclecloud.gemspec
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

require 'knife-oraclecloud/version'
require "knife-oraclecloud/version"

Gem::Specification.new do |spec|
spec.name = 'knife-oraclecloud'
spec.name = "knife-oraclecloud"
spec.version = KnifeOracleCloud::VERSION
spec.authors = ['Chef Partner Engineering']
spec.email = ['partnereng@chef.io']
spec.summary = 'Knife plugin to interact with Oracle Cloud.'
spec.authors = ["Chef Partner Engineering"]
spec.email = ["partnereng@chef.io"]
spec.summary = "Knife plugin to interact with Oracle Cloud."
spec.description = spec.summary
spec.homepage = 'https://github.com/chef-partners/knife-oraclecloud'
spec.license = 'Apache 2.0'
spec.homepage = "https://github.com/chef-partners/knife-oraclecloud"
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 'chef', '~> 12.0'
spec.add_dependency 'knife-cloud', '~> 1.2.0'
spec.add_dependency 'oraclecloud', '~> 1.1'
spec.add_dependency "chef", "~> 12.0"
spec.add_dependency "knife-cloud", "~> 1.2.0"
spec.add_dependency "oraclecloud", "~> 1.1"

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 "bundler", "~> 1.7"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rubocop", "~> 0.35"
end
74 changes: 37 additions & 37 deletions lib/chef/knife/cloud/oraclecloud_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
# limitations under the License.
#

require 'chef/knife/cloud/exceptions'
require 'chef/knife/cloud/service'
require 'chef/knife/cloud/helpers'
require 'chef/knife/cloud/oraclecloud_service_helpers'
require 'oraclecloud'
require "chef/knife/cloud/exceptions"
require "chef/knife/cloud/service"
require "chef/knife/cloud/helpers"
require "chef/knife/cloud/oraclecloud_service_helpers"
require "oraclecloud"

class Chef
class Knife
class Cloud
class OraclecloudService < Service # rubocop:disable Metrics/ClassLength
class OraclecloudService < Service
include OraclecloudServiceHelpers

attr_reader :wait_time, :refresh_time
Expand Down Expand Up @@ -62,35 +62,35 @@ def create_server(options = {})
orchestration = create_orchestration(options)
orchestration.start
ui.msg("Orchestration #{orchestration.name_with_container} started - waiting for it to complete...")
wait_for_status(orchestration, 'ready')
wait_for_status(orchestration, "ready")
ui.msg("Orchestration started successfully.\n")
orchestration_summary(orchestration)
ui.msg('')
ui.msg("")

servers = orchestration.instances
raise CloudExceptions::ServerCreateError, 'The orchestration created more than one server, ' \
'but we were only expecting 1' if servers.length > 1
raise CloudExceptions::ServerCreateError, 'The orchestration did not create any servers' if servers.length == 0
raise CloudExceptions::ServerCreateError, "The orchestration created more than one server, " \
"but we were only expecting 1" if servers.length > 1
raise CloudExceptions::ServerCreateError, "The orchestration did not create any servers" if servers.empty?

servers.first
end

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

unless instance.orchestration.nil?
ui.error('Unable to delete this server. Delete the orchestration instead.')
ui.error("Unable to delete this server. Delete the orchestration instead.")
exit(1)
end

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

ui.msg('Deleting the instance...')
ui.msg("Deleting the instance...")
instance.delete

ui.msg('Delete request complete.')
ui.msg("Delete request complete.")
end

def create_orchestration(options)
Expand All @@ -104,18 +104,18 @@ def create_orchestration(options)
def delete_orchestration(orchestration_id)
orchestration = get_orchestration(orchestration_id)
orchestration_summary(orchestration)
ui.msg('')
ui.msg("")

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

ui.msg('Stopping the orchestration and any instances...')
ui.msg("Stopping the orchestration and any instances...")
orchestration.stop
wait_for_status(orchestration, 'stopped')
wait_for_status(orchestration, "stopped")

ui.msg('Deleting the orchestration and any instances...')
ui.msg("Deleting the orchestration and any instances...")
orchestration.delete

ui.msg('Delete request complete.')
ui.msg("Delete request complete.")
end

def instance_request(options)
Expand Down Expand Up @@ -154,25 +154,25 @@ def get_orchestration(orchestration_id)
end

def orchestration_summary(orchestration)
msg_pair('Orchestration ID', orchestration.name_with_container)
msg_pair('Description', orchestration.description)
msg_pair('Status', orchestration.status)
msg_pair('Instance Count', orchestration.instance_count)
msg_pair("Orchestration ID", orchestration.name_with_container)
msg_pair("Description", orchestration.description)
msg_pair("Status", orchestration.status)
msg_pair("Instance Count", orchestration.instance_count)
end

def server_summary(server, _columns_with_info = nil)
msg_pair('Server Label', server.label)
msg_pair('Status', server.status)
msg_pair('Hostname', server.hostname)
msg_pair('IP Address', server.ip_address.nil? ? 'none' : server.ip_address)
msg_pair('Public IP Addresses', server.public_ip_addresses.empty? ? 'none' : server.public_ip_addresses.join(', '))
msg_pair('Image', server.image)
msg_pair('Shape', server.shape)
msg_pair('Orchestration', server.orchestration.nil? ? 'none' : server.orchestration)
msg_pair("Server Label", server.label)
msg_pair("Status", server.status)
msg_pair("Hostname", server.hostname)
msg_pair("IP Address", server.ip_address.nil? ? "none" : server.ip_address)
msg_pair("Public IP Addresses", server.public_ip_addresses.empty? ? "none" : server.public_ip_addresses.join(", "))
msg_pair("Image", server.image)
msg_pair("Shape", server.shape)
msg_pair("Orchestration", server.orchestration.nil? ? "none" : server.orchestration)
end

def wait_for_status(item, requested_status)
last_status = ''
last_status = ""

begin
Timeout.timeout(wait_time) do
Expand All @@ -186,7 +186,7 @@ def wait_for_status(item, requested_status)
end

if last_status == current_status
print '.'
print "."
else
last_status = current_status
print "\n"
Expand All @@ -197,7 +197,7 @@ def wait_for_status(item, requested_status)
end
end
rescue Timeout::Error
ui.msg('')
ui.msg("")
ui.error("Request did not complete in #{wait_time} seconds. Check the Oracle Cloud Web UI for more information.")
exit 1
end
Expand Down
2 changes: 1 addition & 1 deletion lib/chef/knife/cloud/oraclecloud_service_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def verify_ssl?
def check_for_missing_config_values!(*keys)
missing = keys.select { |x| locate_config_value(x).nil? }

unless missing.empty? # rubocop:disable Style/GuardClause
unless missing.empty?
ui.error("The following required parameters are missing: #{missing.join(', ')}")
exit(1)
end
Expand Down
29 changes: 14 additions & 15 deletions lib/chef/knife/cloud/oraclecloud_service_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,40 @@
class Chef
class Knife
class Cloud
# rubocop:disable Style/AlignParameters
module OraclecloudServiceOptions
def self.included(includer)
includer.class_eval do
option :oraclecloud_api_url,
long: '--oraclecloud-api-url API_URL',
description: 'URL for the oraclecloud API server'
long: "--oraclecloud-api-url API_URL",
description: "URL for the oraclecloud API server"

option :oraclecloud_username,
long: '--oraclecloud-username USERNAME',
description: 'Username to use with the oraclecloud API'
long: "--oraclecloud-username USERNAME",
description: "Username to use with the oraclecloud API"

option :oraclecloud_password,
long: '--oraclecloud-password PASSWORD',
description: 'Password to use with the oraclecloud API'
long: "--oraclecloud-password PASSWORD",
description: "Password to use with the oraclecloud API"

option :oraclecloud_domain,
long: '--oraclecloud-domain IDENTITYDOMAIN',
description: 'Identity domain to use with the oraclecloud API'
long: "--oraclecloud-domain IDENTITYDOMAIN",
description: "Identity domain to use with the oraclecloud API"

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

option :oraclecloud_private_cloud,
long: '--oraclecloud-private-cloud',
description: 'Indicate the --oraclecloud-api-url is a private cloud endpoint',
long: "--oraclecloud-private-cloud",
description: "Indicate the --oraclecloud-api-url is a private cloud endpoint",
boolean: true,
default: false

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
22 changes: 11 additions & 11 deletions lib/chef/knife/oraclecloud_image_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
# limitations under the License.
#

require 'chef/knife'
require 'chef/knife/cloud/list_resource_command'
require 'chef/knife/cloud/oraclecloud_service'
require 'chef/knife/cloud/oraclecloud_service_helpers'
require 'chef/knife/cloud/oraclecloud_service_options'
require "chef/knife"
require "chef/knife/cloud/list_resource_command"
require "chef/knife/cloud/oraclecloud_service"
require "chef/knife/cloud/oraclecloud_service_helpers"
require "chef/knife/cloud/oraclecloud_service_options"

class Chef
class Knife
Expand All @@ -29,15 +29,15 @@ class OraclecloudImageList < ResourceListCommand
include OraclecloudServiceHelpers
include OraclecloudServiceOptions

banner 'knife oraclecloud image list'
banner "knife oraclecloud image list"

def before_exec_command
@columns_with_info = [
{ label: 'Image Name', key: 'name' },
{ label: 'Description', key: 'description' }
{ label: "Image Name", key: "name" },
{ label: "Description", key: "description" },
]

@sort_by_field = 'name'
@sort_by_field = "name"
end

def query_resource
Expand All @@ -47,9 +47,9 @@ def query_resource
def format_status_value(status)
status = status.downcase
status_color = case status
when 'ready'
when "ready"
:green
when 'stopped'
when "stopped"
:red
else
:yellow
Expand Down
14 changes: 7 additions & 7 deletions lib/chef/knife/oraclecloud_orchestration_delete.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
# limitations under the License.
#

require 'chef/knife'
require 'chef/knife/cloud/command'
require 'chef/knife/cloud/oraclecloud_service'
require 'chef/knife/cloud/oraclecloud_service_helpers'
require 'chef/knife/cloud/oraclecloud_service_options'
require "chef/knife"
require "chef/knife/cloud/command"
require "chef/knife/cloud/oraclecloud_service"
require "chef/knife/cloud/oraclecloud_service_helpers"
require "chef/knife/cloud/oraclecloud_service_options"

class Chef
class Knife
Expand All @@ -29,11 +29,11 @@ class OraclecloudOrchestrationDelete < Command
include OraclecloudServiceHelpers
include OraclecloudServiceOptions

banner 'knife oraclecloud orchestration delete ORCHESTRATION_ID [ORCHESTRATION_ID] (options)'
banner "knife oraclecloud orchestration delete ORCHESTRATION_ID [ORCHESTRATION_ID] (options)"

def validate_params!
if @name_args.empty?
ui.error('You must supply at least one Orchestration ID to delete.')
ui.error("You must supply at least one Orchestration ID to delete.")
exit 1
end

Expand Down
Loading

0 comments on commit 9982ec1

Please sign in to comment.