From 950a22ffada7ba2fdaa3589521736c7643578e40 Mon Sep 17 00:00:00 2001 From: Stephen Hoekstra Date: Mon, 5 Aug 2019 10:37:34 +0200 Subject: [PATCH 1/5] Switch to fog-cloudstack Signed-off-by: Stephen Hoekstra --- .../action/connect_cloudstack.rb | 2 +- .../action/read_transport_info.rb | 2 +- lib/vagrant-cloudstack/action/run_instance.rb | 8 ++++---- lib/vagrant-cloudstack/action/start_instance.rb | 2 +- .../action/terminate_instance.rb | 14 +++++++------- .../action/retrieve_public_ip_port_spec.rb | 2 +- .../vagrant-cloudstack/action/run_instance_spec.rb | 4 ++-- .../action/terminate_instance_spec.rb | 2 +- vagrant-cloudstack.gemspec | 3 +-- 9 files changed, 19 insertions(+), 20 deletions(-) diff --git a/lib/vagrant-cloudstack/action/connect_cloudstack.rb b/lib/vagrant-cloudstack/action/connect_cloudstack.rb index 945ae451..891292a1 100644 --- a/lib/vagrant-cloudstack/action/connect_cloudstack.rb +++ b/lib/vagrant-cloudstack/action/connect_cloudstack.rb @@ -1,4 +1,4 @@ -require 'fog' +require 'fog/cloudstack' require 'log4r' module VagrantPlugins diff --git a/lib/vagrant-cloudstack/action/read_transport_info.rb b/lib/vagrant-cloudstack/action/read_transport_info.rb index 15259637..35610d39 100644 --- a/lib/vagrant-cloudstack/action/read_transport_info.rb +++ b/lib/vagrant-cloudstack/action/read_transport_info.rb @@ -24,7 +24,7 @@ def retrieve_public_ip_port(cloudstack, domain_config, machine) if not pf_ip_address and pf_ip_address_id and pf_public_port begin response = cloudstack.list_public_ip_addresses({:id => pf_ip_address_id}) - rescue Fog::Compute::Cloudstack::Error => e + rescue Fog::Cloudstack::Compute::Error => e raise Errors::FogError, :message => e.message end diff --git a/lib/vagrant-cloudstack/action/run_instance.rb b/lib/vagrant-cloudstack/action/run_instance.rb index 03100350..ad21ba8c 100644 --- a/lib/vagrant-cloudstack/action/run_instance.rb +++ b/lib/vagrant-cloudstack/action/run_instance.rb @@ -263,7 +263,7 @@ def create_vm end raise - rescue Fog::Compute::Cloudstack::Error => e + rescue Fog::Cloudstack::Compute::Error => e raise Errors::FogError, :message => e.message end @@ -351,7 +351,7 @@ def enable_static_nat(rule) @env[:ui].warn(" -- Failed to enable static nat: #{resp['enablestaticnatresponse']['errortext']}") return end - rescue Fog::Compute::Cloudstack::Error => e + rescue Fog::Cloudstack::Compute::Error => e raise Errors::FogError, :message => e.message end @@ -492,7 +492,7 @@ def apply_port_forwarding_rule(rule) sleep 2 end end - rescue Fog::Compute::Cloudstack::Error => e + rescue Fog::Cloudstack::Compute::Error => e raise Errors::FogError, :message => e.message end @@ -721,7 +721,7 @@ def apply_firewall_rule(acl_name, options, response_string, type_string) sleep 2 end end - rescue Fog::Compute::Cloudstack::Error => e + rescue Fog::Cloudstack::Compute::Error => e if e.message =~ /The range specified,.*conflicts with rule/ @env[:ui].warn(" -- Failed to create firewall rule: #{e.message}") elsif e.message =~ /Default ACL cannot be modified/ diff --git a/lib/vagrant-cloudstack/action/start_instance.rb b/lib/vagrant-cloudstack/action/start_instance.rb index ee173b08..a12ded64 100644 --- a/lib/vagrant-cloudstack/action/start_instance.rb +++ b/lib/vagrant-cloudstack/action/start_instance.rb @@ -47,7 +47,7 @@ def call(env) :timeout => domain_config.instance_ready_timeout end end - rescue Fog::Compute::Cloudstack::Error => e + rescue Fog::Cloudstack::Compute::Error => e raise Errors::FogError, :message => e.message end diff --git a/lib/vagrant-cloudstack/action/terminate_instance.rb b/lib/vagrant-cloudstack/action/terminate_instance.rb index 7308bf3b..31fde487 100644 --- a/lib/vagrant-cloudstack/action/terminate_instance.rb +++ b/lib/vagrant-cloudstack/action/terminate_instance.rb @@ -66,7 +66,7 @@ def remove_volumes(env) resp = env[:cloudstack_compute].detach_volume({:id => volume_id}) job_id = resp['detachvolumeresponse']['jobid'] wait_for_job_ready(env, job_id) - rescue Fog::Compute::Cloudstack::Error => e + rescue Fog::Cloudstack::Compute::Error => e if e.message =~ /Unable to execute API command detachvolume.*entity does not exist/ env[:ui].warn(I18n.t('vagrant_cloudstack.detach_volume_failed', message: e.message)) else @@ -98,13 +98,13 @@ def remove_security_groups(env) end env[:ui].info('Deleted egress rules') - rescue Fog::Compute::Cloudstack::Error => e + rescue Fog::Cloudstack::Compute::Error => e raise Errors::FogError, :message => e.message end begin env[:cloudstack_compute].delete_security_group({:id => security_group_id}) - rescue Fog::Compute::Cloudstack::Error => e + rescue Fog::Cloudstack::Compute::Error => e env[:ui].warn("Couldn't delete group right now.") env[:ui].warn('Waiting 30 seconds to retry') sleep 30 @@ -127,7 +127,7 @@ def remove_generated_ssh_key(env) begin response = env[:cloudstack_compute].delete_ssh_key_pair(name: sshkeyname) env[:ui].warn(I18n.t('vagrant_cloudstack.ssh_key_pair_no_success_removing', name: sshkeyname)) unless response['deletesshkeypairresponse']['success'] == 'true' - rescue Fog::Compute::Cloudstack::Error => e + rescue Fog::Cloudstack::Compute::Error => e env[:ui].warn(I18n.t('vagrant_cloudstack.errors.fog_error', :message => e.message)) end sshkeyname_file.delete @@ -149,7 +149,7 @@ def remove_portforwarding(env) resp = env[:cloudstack_compute].delete_port_forwarding_rule({:id => rule_id}) job_id = resp['deleteportforwardingruleresponse']['jobid'] wait_for_job_ready(env, job_id) - rescue Fog::Compute::Cloudstack::Error => e + rescue Fog::Cloudstack::Compute::Error => e if e.message =~ /Unable to execute API command deleteportforwardingrule.*entity does not exist/ env[:ui].warn(" -- Failed to delete portforwarding rule: #{e.message}") else @@ -183,7 +183,7 @@ def remove_static_nat(env) resp = env[:cloudstack_compute].request(options) job_id = resp['disablestaticnatresponse']['jobid'] wait_for_job_ready(env, job_id) - rescue Fog::Compute::Cloudstack::Error => e + rescue Fog::Cloudstack::Compute::Error => e raise Errors::FogError, :message => e.message end end @@ -216,7 +216,7 @@ def remove_firewall_rules(env) resp = env[:cloudstack_compute].request(options) job_id = resp[response_string]['jobid'] wait_for_job_ready(env, job_id) - rescue Fog::Compute::Cloudstack::Error => e + rescue Fog::Cloudstack::Compute::Error => e if e.message =~ /Unable to execute API command deletefirewallrule.*entity does not exist/ env[:ui].warn(" -- Failed to delete #{type_string}: #{e.message}") else diff --git a/spec/vagrant-cloudstack/action/retrieve_public_ip_port_spec.rb b/spec/vagrant-cloudstack/action/retrieve_public_ip_port_spec.rb index f294aa09..35e49e2d 100644 --- a/spec/vagrant-cloudstack/action/retrieve_public_ip_port_spec.rb +++ b/spec/vagrant-cloudstack/action/retrieve_public_ip_port_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' require 'vagrant-cloudstack/action/read_transport_info' require 'vagrant-cloudstack/config' -require 'fog' +require 'fog/cloudstack' describe VagrantPlugins::Cloudstack::Action::ReadTransportInfo do let(:action) {VagrantPlugins::Cloudstack::Action::ReadTransportInfo.new } diff --git a/spec/vagrant-cloudstack/action/run_instance_spec.rb b/spec/vagrant-cloudstack/action/run_instance_spec.rb index 11d784ea..4c2559cf 100644 --- a/spec/vagrant-cloudstack/action/run_instance_spec.rb +++ b/spec/vagrant-cloudstack/action/run_instance_spec.rb @@ -3,7 +3,7 @@ require 'vagrant-cloudstack/config' require 'vagrant' -require 'fog' +require 'fog/cloudstack' describe VagrantPlugins::Cloudstack::Action::RunInstance do let(:action) { VagrantPlugins::Cloudstack::Action::RunInstance.new(app, env) } @@ -510,7 +510,7 @@ expect(cloudstack_compute).to receive(:create_port_forwarding_rule) .with(create_port_forwarding_rule_parameters.merge(publicport: PF_RANDOM_START - 1)) .and_raise( - Fog::Compute::Cloudstack::Error, + Fog::Cloudstack::Compute::Error, 'The range specified, CONFLICTINGRANGE, conflicts with rule SOMERULE which has THESAME' ) end diff --git a/spec/vagrant-cloudstack/action/terminate_instance_spec.rb b/spec/vagrant-cloudstack/action/terminate_instance_spec.rb index 04e890e8..dfc66227 100644 --- a/spec/vagrant-cloudstack/action/terminate_instance_spec.rb +++ b/spec/vagrant-cloudstack/action/terminate_instance_spec.rb @@ -3,7 +3,7 @@ require 'vagrant-cloudstack/config' require 'vagrant' -require 'fog' +require 'fog/cloudstack' describe VagrantPlugins::Cloudstack::Action::TerminateInstance do let(:action) { VagrantPlugins::Cloudstack::Action::TerminateInstance.new(app, env) } diff --git a/vagrant-cloudstack.gemspec b/vagrant-cloudstack.gemspec index 6cab2068..6a7dda4c 100644 --- a/vagrant-cloudstack.gemspec +++ b/vagrant-cloudstack.gemspec @@ -15,8 +15,7 @@ Gem::Specification.new do |s| s.required_rubygems_version = '>= 1.3.6' s.rubyforge_project = 'vagrant-cloudstack' - s.add_runtime_dependency 'fog', '>= 1.32.0' - s.add_runtime_dependency 'fog-xml', '>= 0.1.2' + s.add_runtime_dependency 'fog-cloudstack', '~> 0.1.0' s.add_development_dependency 'rake', '>= 10.4', '~> 10.5' s.add_development_dependency 'rspec-core', '~> 2.14', '>= 2.14.7' From 15815067f6d695942ea5b00ba0e9ac7b07607517 Mon Sep 17 00:00:00 2001 From: Stephen Hoekstra Date: Mon, 5 Aug 2019 10:39:57 +0200 Subject: [PATCH 2/5] Add affinity_group_ids and affinity_group_names options Signed-off-by: Stephen Hoekstra --- lib/vagrant-cloudstack/action/run_instance.rb | 2 ++ lib/vagrant-cloudstack/config.rb | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/vagrant-cloudstack/action/run_instance.rb b/lib/vagrant-cloudstack/action/run_instance.rb index ad21ba8c..af8f5393 100644 --- a/lib/vagrant-cloudstack/action/run_instance.rb +++ b/lib/vagrant-cloudstack/action/run_instance.rb @@ -289,6 +289,8 @@ def compose_server_creation_options options['name'] = @domain_config.name unless @domain_config.name.nil? options['ip_address'] = @domain_config.private_ip_address unless @domain_config.private_ip_address.nil? options['disk_offering_id'] = @disk_offering.id unless @disk_offering.id.nil? + options[:affinity_group_ids] = @domain_config.affinity_group_ids.delete(' ') unless @domain_config.affinity_group_ids.nil? + options[:affinity_group_names] = @domain_config.affinity_group_names.delete(' ') unless @domain_config.affinity_group_names.nil? if @domain_config.user_data != nil options['user_data'] = Base64.urlsafe_encode64(@domain_config.user_data) diff --git a/lib/vagrant-cloudstack/config.rb b/lib/vagrant-cloudstack/config.rb index e552de7f..e5ec7840 100644 --- a/lib/vagrant-cloudstack/config.rb +++ b/lib/vagrant-cloudstack/config.rb @@ -6,7 +6,7 @@ class Config < Vagrant.plugin("2", :config) INSTANCE_VAR_DEFAULT_NIL = %w(host name path port domain_id network_id network_name project_id service_offering_id service_offering_name template_id template_name zone_id zone_name keypair pf_ip_address_id pf_ip_address pf_public_port pf_public_rdp_port pf_private_port pf_trusted_networks display_name group user_data ssh_key ssh_user - ssh_network_id ssh_network_name vm_user vm_password private_ip_address).freeze + ssh_network_id ssh_network_name vm_user vm_password private_ip_address affinity_group_ids affinity_group_names).freeze INSTANCE_VAR_DEFAULT_EMPTY_ARRAY = %w(static_nat port_forwarding_rules firewall_rules security_group_ids security_group_names security_groups).freeze # Cloudstack api host. @@ -253,6 +253,16 @@ class Config < Vagrant.plugin("2", :config) # @return [String] attr_accessor :private_ip_address + # Affinity Group IDs for the instance + # + # @return [String] + attr_accessor :affinity_group_ids + + # Affinity Group Names for the instance + # + # @return [String] + attr_accessor :affinity_group_names + # flag to enable/disable expunge vm on destroy # # @return [Boolean] From e8b9f2ae1d1e45d6a6fefbfa3e739a4d52e30539 Mon Sep 17 00:00:00 2001 From: Stephen Hoekstra Date: Mon, 5 Aug 2019 10:44:13 +0200 Subject: [PATCH 3/5] Changed keys from strings to symbols Newer versions of fog seem to prefer symbols and error out when using strings; also fixed alignment and sorting. Signed-off-by: Stephen Hoekstra --- lib/vagrant-cloudstack/action/run_instance.rb | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/vagrant-cloudstack/action/run_instance.rb b/lib/vagrant-cloudstack/action/run_instance.rb index af8f5393..1777fe57 100644 --- a/lib/vagrant-cloudstack/action/run_instance.rb +++ b/lib/vagrant-cloudstack/action/run_instance.rb @@ -281,22 +281,22 @@ def compose_server_creation_options unless @networks.empty? nets = @networks.map(&:id).compact.join(",") - options['network_ids'] = nets unless nets.empty? - end - options['security_group_ids'] = @security_groups.map {|security_group| security_group.id}.join(',') unless @security_groups.empty? - options['project_id'] = @domain_config.project_id unless @domain_config.project_id.nil? - options['key_name'] = @domain_config.keypair unless @domain_config.keypair.nil? - options['name'] = @domain_config.name unless @domain_config.name.nil? - options['ip_address'] = @domain_config.private_ip_address unless @domain_config.private_ip_address.nil? - options['disk_offering_id'] = @disk_offering.id unless @disk_offering.id.nil? - options[:affinity_group_ids] = @domain_config.affinity_group_ids.delete(' ') unless @domain_config.affinity_group_ids.nil? + options[:network_ids] = nets unless nets.empty? + end + options[:affinity_group_ids] = @domain_config.affinity_group_ids.delete(' ') unless @domain_config.affinity_group_ids.nil? options[:affinity_group_names] = @domain_config.affinity_group_names.delete(' ') unless @domain_config.affinity_group_names.nil? + options[:disk_offering_id] = @disk_offering.id unless @disk_offering.id.nil? + options[:ip_address] = @domain_config.private_ip_address unless @domain_config.private_ip_address.nil? + options[:key_name] = @domain_config.keypair unless @domain_config.keypair.nil? + options[:name] = @domain_config.name unless @domain_config.name.nil? + options[:project_id] = @domain_config.project_id unless @domain_config.project_id.nil? + options[:security_group_ids] = @security_groups.map {|security_group| security_group.id}.join(',') unless @security_groups.empty? if @domain_config.user_data != nil - options['user_data'] = Base64.urlsafe_encode64(@domain_config.user_data) - if options['user_data'].length > 2048 + options[:user_data] = Base64.urlsafe_encode64(@domain_config.user_data) + if options[:user_data].length > 2048 raise Errors::UserdataError, - :userdataLength => options['user_data'].length + :userdataLength => options[:user_data].length end end options From 7bd8380a5ab3884b6b825c3fe7f3f40210b51ff9 Mon Sep 17 00:00:00 2001 From: Stephen Hoekstra Date: Mon, 5 Aug 2019 10:45:13 +0200 Subject: [PATCH 4/5] Bump version Signed-off-by: Stephen Hoekstra --- lib/vagrant-cloudstack/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vagrant-cloudstack/version.rb b/lib/vagrant-cloudstack/version.rb index 6b493eab..a72d8a03 100644 --- a/lib/vagrant-cloudstack/version.rb +++ b/lib/vagrant-cloudstack/version.rb @@ -1,5 +1,5 @@ module VagrantPlugins module Cloudstack - VERSION = '1.5.1' + VERSION = '1.6.0' end end From 6197c0e09a2e4b4d795062872beba2f3b3a99347 Mon Sep 17 00:00:00 2001 From: Stephen Hoekstra Date: Mon, 5 Aug 2019 10:45:48 +0200 Subject: [PATCH 5/5] Update gem metadata Signed-off-by: Stephen Hoekstra --- vagrant-cloudstack.gemspec | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/vagrant-cloudstack.gemspec b/vagrant-cloudstack.gemspec index 6a7dda4c..7494628b 100644 --- a/vagrant-cloudstack.gemspec +++ b/vagrant-cloudstack.gemspec @@ -6,9 +6,26 @@ Gem::Specification.new do |s| s.version = VagrantPlugins::Cloudstack::VERSION s.platform = Gem::Platform::RUBY s.license = 'MIT' - s.authors = ['Mitchell Hashimoto', 'Carl Loa Odin', 'Tor-Åke Fransson', 'Olle Lundberg', 'Roeland Kuipers', 'Yuichi Uemura', 'Atsushi Sasaki', 'Nicolas Brechet', 'Peter Jönsson', 'Christophe Roux', 'Andrei Chiriaev', 'Miguel Ferreira', 'Timothy van Zadelhoff', 'Geurt Schimmel', 'Bob van den Heuvel'] - s.email = 'int-toolkit@schubergphilis.com' - s.homepage = 'https://github.com/missioncriticalcloud/vagrant-cloudstack/' + s.authors = [ + 'Andrei Chiriaev', + 'Atsushi Sasaki', + 'Bob van den Heuvel', + 'Carl Loa Odin', + 'Christophe Roux', + 'Geurt Schimmel', + 'Miguel Ferreira', + 'Mitchell Hashimoto', + 'Nicolas Brechet', + 'Olle Lundberg', + 'Peter Jönsson', + 'Roeland Kuipers', + 'Stephen Hoekstra', + 'Timothy van Zadelhoff', + 'Tor-Åke Fransson', + 'Yuichi Uemura', + ] + s.email = 'int-cloud@schubergphilis.com' + s.homepage = 'https://github.com/MissionCriticalCloud/vagrant-cloudstack/' s.summary = 'Enables Vagrant to manage machines in Cloudstack.' s.description = 'Provides a cloudstack provider in Vagrant via which Vagrant can manage machines in CloudStack.'