Skip to content
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
21 changes: 14 additions & 7 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
#
# Author:: Kaustubh Deorukhkar (<kaustubh@clogeny.com>)
# Copyright:: Copyright 2013-2018 Chef Software, Inc.
# Copyright:: Copyright 2013-2019 Chef Software, Inc.

require "bundler/setup"
require "bundler/gem_tasks"
require "chefstyle"
require "rubocop/rake_task"
require "rspec/core/rake_task"
begin
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 "chefstyle gem is not installed. bundle install first to make sure all dependencies are installed."
end

RuboCop::RakeTask.new
require "rspec/core/rake_task"

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

task default: [:rubocop, :spec]

begin
require "yard"
YARD::Rake::YardocTask.new(:docs)
Expand All @@ -27,3 +32,5 @@ task :console do
ARGV.clear
IRB.start
end

task default: %i{style spec}
2 changes: 1 addition & 1 deletion knife-openstack.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require "knife-openstack/version"
Gem::Specification.new do |s|
s.name = "knife-openstack"
s.version = Knife::OpenStack::VERSION
s.version = "#{s.version}-alpha-#{ENV['TRAVIS_BUILD_NUMBER']}" if ENV["TRAVIS"]
s.version = "#{s.version}-alpha-#{ENV["TRAVIS_BUILD_NUMBER"]}" if ENV["TRAVIS"]
s.authors = ["JJ Asghar"]
s.email = ["jj@chef.io"]
s.homepage = "https://github.com/chef/knife-openstack"
Expand Down
100 changes: 50 additions & 50 deletions lib/chef/knife/cloud/openstack_server_create_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,82 +27,82 @@ def self.included(includer)

# Openstack Server create params.
option :private_network,
long: "--openstack-private-network",
description: "Use the private IP for bootstrapping rather than the public IP",
boolean: true,
default: false
long: "--openstack-private-network",
description: "Use the private IP for bootstrapping rather than the public IP",
boolean: true,
default: false

option :openstack_floating_ip,
short: "-a [IP]",
long: "--openstack-floating-ip [IP]",
default: "-1",
description: "Request to associate a floating IP address to the new OpenStack node. Assumes IPs have been allocated to the project. Specific IP is optional."
short: "-a [IP]",
long: "--openstack-floating-ip [IP]",
default: "-1",
description: "Request to associate a floating IP address to the new OpenStack node. Assumes IPs have been allocated to the project. Specific IP is optional."

option :openstack_volumes,
long: "--openstack-volumes VOLUME1,VOLUME2,VOLUME3",
description: "Comma separated list of the UUID(s) of the volume(s) to attach to the server",
proc: proc { |volumes| volumes.split(",") }
long: "--openstack-volumes VOLUME1,VOLUME2,VOLUME3",
description: "Comma separated list of the UUID(s) of the volume(s) to attach to the server",
proc: proc { |volumes| volumes.split(",") }

option :openstack_scheduler_hints,
long: "--scheduler-hints HINTS",
description: "A scheduler group hint to OpenStack",
proc: proc { |i| Chef::Config[:knife][:openstack_scheduler_hints] = i }
long: "--scheduler-hints HINTS",
description: "A scheduler group hint to OpenStack",
proc: proc { |i| Chef::Config[:knife][:openstack_scheduler_hints] = i }

option :openstack_security_groups,
short: "-G X,Y,Z",
long: "--openstack-groups X,Y,Z",
description: "The security groups for this server",
default: ["default"],
proc: proc { |groups| groups.split(",") }
short: "-G X,Y,Z",
long: "--openstack-groups X,Y,Z",
description: "The security groups for this server",
default: ["default"],
proc: proc { |groups| groups.split(",") }

option :openstack_ssh_key_id,
short: "-S KEY",
long: "--openstack-ssh-key-id KEY",
description: "The OpenStack SSH keypair id",
proc: proc { |key| Chef::Config[:knife][:openstack_ssh_key_id] = key }
short: "-S KEY",
long: "--openstack-ssh-key-id KEY",
description: "The OpenStack SSH keypair id",
proc: proc { |key| Chef::Config[:knife][:openstack_ssh_key_id] = key }

option :user_data,
long: "--user-data USER_DATA",
description: "The file path containing user data information for this server",
proc: proc { |user_data| open(user_data, &:read) }
long: "--user-data USER_DATA",
description: "The file path containing user data information for this server",
proc: proc { |user_data| open(user_data, &:read) }

option :bootstrap_network,
long: "--bootstrap-network NAME",
default: "public",
description: "Specify network for bootstrapping. Default is 'public'."
long: "--bootstrap-network NAME",
default: "public",
description: "Specify network for bootstrapping. Default is 'public'."

option :network,
long: "--no-network",
boolean: true,
default: true,
description: "Use first available network for bootstrapping if 'public' and 'private' are unavailable."
long: "--no-network",
boolean: true,
default: true,
description: "Use first available network for bootstrapping if 'public' and 'private' are unavailable."

option :network_ids,
long: "--network-ids NETWORK_ID_1,NETWORK_ID_2,NETWORK_ID_3",
description: "Comma separated list of the UUID(s) of the network(s) for the server to attach",
proc: proc { |networks| networks.split(",") }
long: "--network-ids NETWORK_ID_1,NETWORK_ID_2,NETWORK_ID_3",
description: "Comma separated list of the UUID(s) of the network(s) for the server to attach",
proc: proc { |networks| networks.split(",") }

option :availability_zone,
short: "-Z ZONE_NAME",
long: "--availability-zone ZONE_NAME",
description: "The availability zone for this server",
proc: proc { |z| Chef::Config[:knife][:availability_zone] = z }
short: "-Z ZONE_NAME",
long: "--availability-zone ZONE_NAME",
description: "The availability zone for this server",
proc: proc { |z| Chef::Config[:knife][:availability_zone] = z }

option :metadata,
short: "-M X=1",
long: "--metadata X=1",
description: "Metadata information for this server (may pass multiple times)",
proc: proc { |data| Chef::Config[:knife][:metadata] ||= {}; Chef::Config[:knife][:metadata].merge!(data.split("=")[0] => data.split("=")[1]) }
short: "-M X=1",
long: "--metadata X=1",
description: "Metadata information for this server (may pass multiple times)",
proc: proc { |data| Chef::Config[:knife][:metadata] ||= {}; Chef::Config[:knife][:metadata].merge!(data.split("=")[0] => data.split("=")[1]) }

option :secret_file,
long: "--secret-file SECRET_FILE",
description: "A file containing the secret key to use to encrypt data bag item values",
proc: proc { |sf| Chef::Config[:knife][:secret_file] = sf }
long: "--secret-file SECRET_FILE",
description: "A file containing the secret key to use to encrypt data bag item values",
proc: proc { |sf| Chef::Config[:knife][:secret_file] = sf }

option :secret,
long: "--secret ",
description: "The secret key to use to encrypt data bag item values",
proc: proc { |s| Chef::Config[:knife][:secret] = s }
long: "--secret ",
description: "The secret key to use to encrypt data bag item values",
proc: proc { |s| Chef::Config[:knife][:secret] = s }
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/chef/knife/cloud/openstack_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def initialize(options = {})
Chef::Log.debug("openstack_username #{Chef::Config[:knife][:openstack_username]}")
Chef::Log.debug("openstack_auth_url #{Chef::Config[:knife][:openstack_auth_url]}")
Chef::Log.debug("openstack_tenant #{Chef::Config[:knife][:openstack_tenant]}")
Chef::Log.debug("openstack_endpoint_type #{Chef::Config[:knife][:openstack_endpoint_type] || 'publicURL'}")
Chef::Log.debug("openstack_endpoint_type #{Chef::Config[:knife][:openstack_endpoint_type] || "publicURL"}")
Chef::Log.debug("openstack_insecure #{Chef::Config[:knife][:openstack_insecure]}")
Chef::Log.debug("openstack_region #{Chef::Config[:knife][:openstack_region]}")

Expand Down Expand Up @@ -72,6 +72,7 @@ def get_auth_params
[:openstack_api_key]
).each do |k|
next unless k.to_s.start_with?("openstack")

params[k] = Chef::Config[:knife][k]
end
params[:openstack_api_key] = Chef::Config[:knife][:openstack_password] || Chef::Config[:knife][:openstack_api_key]
Expand Down
46 changes: 23 additions & 23 deletions lib/chef/knife/cloud/openstack_service_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,39 +25,39 @@ def self.included(includer)
include FogOptions
# Openstack Connection params.
option :openstack_username,
short: "-A USERNAME",
long: "--openstack-username KEY",
description: "Your OpenStack Username",
proc: proc { |key| Chef::Config[:knife][:openstack_username] = key }
short: "-A USERNAME",
long: "--openstack-username KEY",
description: "Your OpenStack Username",
proc: proc { |key| Chef::Config[:knife][:openstack_username] = key }

option :openstack_password,
short: "-K SECRET",
long: "--openstack-password SECRET",
description: "Your OpenStack Password",
proc: proc { |key| Chef::Config[:knife][:openstack_password] = key }
short: "-K SECRET",
long: "--openstack-password SECRET",
description: "Your OpenStack Password",
proc: proc { |key| Chef::Config[:knife][:openstack_password] = key }

option :openstack_tenant,
short: "-T NAME",
long: "--openstack-tenant NAME",
description: "Your OpenStack Tenant NAME",
proc: proc { |key| Chef::Config[:knife][:openstack_tenant] = key }
short: "-T NAME",
long: "--openstack-tenant NAME",
description: "Your OpenStack Tenant NAME",
proc: proc { |key| Chef::Config[:knife][:openstack_tenant] = key }

option :openstack_auth_url,
long: "--openstack-api-endpoint ENDPOINT",
description: "Your OpenStack API endpoint",
proc: proc { |endpoint| Chef::Config[:knife][:openstack_auth_url] = endpoint }
long: "--openstack-api-endpoint ENDPOINT",
description: "Your OpenStack API endpoint",
proc: proc { |endpoint| Chef::Config[:knife][:openstack_auth_url] = endpoint }

option :openstack_endpoint_type,
long: "--openstack-endpoint-type ENDPOINT_TYPE",
description: "OpenStack endpoint type to use (publicURL, internalURL, adminURL)",
proc: proc { |type| Chef::Config[:knife][:openstack_endpoint_type] = type }
long: "--openstack-endpoint-type ENDPOINT_TYPE",
description: "OpenStack endpoint type to use (publicURL, internalURL, adminURL)",
proc: proc { |type| Chef::Config[:knife][:openstack_endpoint_type] = type }

option :openstack_insecure,
long: "--insecure",
description: "Ignore SSL certificate on the Auth URL",
boolean: true,
default: false,
proc: proc { |key| Chef::Config[:knife][:openstack_insecure] = key }
long: "--insecure",
description: "Ignore SSL certificate on the Auth URL",
boolean: true,
default: false,
proc: proc { |key| Chef::Config[:knife][:openstack_insecure] = key }
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/chef/knife/openstack_floating_ip_allocate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ class OpenstackFloatingIpAllocate < Command
banner "knife openstack floating_ip allocate (options)"

option :pool,
short: "-p POOL",
long: "--pool POOL",
description: "Floating IP pool to allocate from.",
proc: proc { |key| Chef::Config[:knife][:pool] = key }
short: "-p POOL",
long: "--pool POOL",
description: "Floating IP pool to allocate from.",
proc: proc { |key| Chef::Config[:knife][:pool] = key }

def execute_command
@resource = @service.allocate_address(locate_config_value(:pool))
Expand Down
8 changes: 4 additions & 4 deletions lib/chef/knife/openstack_floating_ip_associate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ class OpenstackFloatingIpAssociate < Command
banner "knife openstack floating_ip associate IP (options)"

option :instance_id,
long: "--instance-id ID",
description: "Instance id to associate it with.",
proc: proc { |key| Chef::Config[:knife][:instance_id] = key },
required: true
long: "--instance-id ID",
description: "Instance id to associate it with.",
proc: proc { |key| Chef::Config[:knife][:instance_id] = key },
required: true

def execute_command
if @name_args[0]
Expand Down
8 changes: 4 additions & 4 deletions lib/chef/knife/openstack_floating_ip_disassociate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ class OpenstackFloatingIpDisassociate < Command
banner "knife openstack floating_ip disassociate IP (options)"

option :instance_id,
long: "--instance-id ID",
description: "Instance id to disassociate with.",
proc: proc { |key| Chef::Config[:knife][:instance_id] = key },
required: true
long: "--instance-id ID",
description: "Instance id to disassociate with.",
proc: proc { |key| Chef::Config[:knife][:instance_id] = key },
required: true

def execute_command
if @name_args[0]
Expand Down
2 changes: 1 addition & 1 deletion lib/chef/knife/openstack_group_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def query_resource
@service.connection.security_groups
rescue Excon::Errors::BadRequest => e
response = Chef::JSONCompat.from_json(e.response.body)
ui.fatal("Unknown server error (#{response['badRequest']['code']}): #{response['badRequest']['message']}")
ui.fatal("Unknown server error (#{response["badRequest"]["code"]}): #{response["badRequest"]["message"]}")
raise e
end

Expand Down
2 changes: 1 addition & 1 deletion lib/chef/knife/openstack_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def instance_addresses(addresses)
ips.each do |ip|
version = "IPv6" if ip["version"] == 6
version = "IPv4" if ip["version"] == 4
info << "#{addresses.keys[0]}:#{version}: #{ip['addr']}"
info << "#{addresses.keys[0]}:#{version}: #{ip["addr"]}"
end
end
info.join(" ")
Expand Down
8 changes: 4 additions & 4 deletions lib/chef/knife/openstack_image_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ class OpenstackImageList < ResourceListCommand
banner "knife openstack image list (options)"

option :disable_filter,
long: "--disable-filter",
description: "Disable filtering of the image list. Currently filters names ending with 'initrd' or 'kernel'",
boolean: true,
default: false
long: "--disable-filter",
description: "Disable filtering of the image list. Currently filters names ending with 'initrd' or 'kernel'",
boolean: true,
default: false

def before_exec_command
# set resource_filters
Expand Down
1 change: 1 addition & 0 deletions lib/chef/knife/openstack_server_create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ def is_floating_ip_valid?

addresses = service.connection.addresses
return false if addresses.empty? # no floating IPs

# floating requested without value
if address.nil?
if addresses.find_index { |a| a.fixed_ip.nil? }
Expand Down
4 changes: 2 additions & 2 deletions lib/chef/knife/openstack_volume_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def query_resource
@service.connection.volumes
rescue Excon::Errors::BadRequest => e
response = Chef::JSONCompat.from_json(e.response.body)
ui.fatal("Unknown server error (#{response['badRequest']['code']}): #{response['badRequest']['message']}")
ui.fatal("Unknown server error (#{response["badRequest"]["code"]}): #{response["badRequest"]["message"]}")
raise e
end

Expand All @@ -58,7 +58,7 @@ def list(volumes)
end
rescue Excon::Errors::BadRequest => e
response = Chef::JSONCompat.from_json(e.response.body)
ui.fatal("Unknown server error (#{response['badRequest']['code']}): #{response['badRequest']['message']}")
ui.fatal("Unknown server error (#{response["badRequest"]["code"]}): #{response["badRequest"]["message"]}")
raise e
end
puts ui.list(volume_list, :uneven_columns_across, 5)
Expand Down
6 changes: 2 additions & 4 deletions spec/functional/floating_ip_list_func_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@

context "functionality" do
before do
resources = [TestResource.new("id" => "floatingip1", "instance_id" => "daed9e86-4b69-4242-993a-926a39352783", "ip" => "173.236.251.98", "fixed_ip" => "", "pool" => "test-pool"
),
TestResource.new("id" => "floatingip2", "instance_id" => "", "ip" => "67.205.60.122", "fixed_ip" => "10.10.10.1", "pool" => "test-pool"
),
resources = [TestResource.new("id" => "floatingip1", "instance_id" => "daed9e86-4b69-4242-993a-926a39352783", "ip" => "173.236.251.98", "fixed_ip" => "", "pool" => "test-pool"),
TestResource.new("id" => "floatingip2", "instance_id" => "", "ip" => "67.205.60.122", "fixed_ip" => "10.10.10.1", "pool" => "test-pool"),
]
allow(instance).to receive(:query_resource).and_return(resources)
allow(instance).to receive(:puts)
Expand Down
10 changes: 5 additions & 5 deletions spec/functional/image_list_func_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@
end

it "displays formatted list of images, filtered by default" do
expect(instance.ui).to receive(:list).with(["Name", "ID", "Snapshot",
"image01", "resource-1", "no"], :uneven_columns_across, 3)
expect(instance.ui).to receive(:list).with(%w{Name ID Snapshot
image01 resource-1 no}, :uneven_columns_across, 3)
instance.run
end

it "lists all images when disable_filter = true" do
instance.config[:disable_filter] = true
expect(instance.ui).to receive(:list).with(["Name", "ID", "Snapshot",
"image01", "resource-1", "no",
"initrd", "resource-2", "no"], :uneven_columns_across, 3)
expect(instance.ui).to receive(:list).with(%w{Name ID Snapshot
image01 resource-1 no
initrd resource-2 no}, :uneven_columns_across, 3)
instance.run
end
end
Expand Down
Loading