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

WIP: Add instance affinity group support #186

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion lib/vagrant-cloudstack/action/connect_cloudstack.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'fog'
require 'fog/cloudstack'
require 'log4r'

module VagrantPlugins
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-cloudstack/action/read_transport_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
30 changes: 16 additions & 14 deletions lib/vagrant-cloudstack/action/run_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -281,20 +281,22 @@ def compose_server_creation_options

unless @networks.empty?
nets = @networks.map(&:id).compact.join(",")
options['network_ids'] = nets unless nets.empty?
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[: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
Expand Down Expand Up @@ -351,7 +353,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

Expand Down Expand Up @@ -492,7 +494,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

Expand Down Expand Up @@ -721,7 +723,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/
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-cloudstack/action/start_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 7 additions & 7 deletions lib/vagrant-cloudstack/action/terminate_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion lib/vagrant-cloudstack/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-cloudstack/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module VagrantPlugins
module Cloudstack
VERSION = '1.5.1'
VERSION = '1.6.0'
end
end
Original file line number Diff line number Diff line change
@@ -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 }
Expand Down
4 changes: 2 additions & 2 deletions spec/vagrant-cloudstack/action/run_instance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/vagrant-cloudstack/action/terminate_instance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
26 changes: 21 additions & 5 deletions vagrant-cloudstack.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,33 @@ 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 = '[email protected]'
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 = '[email protected]'
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.'

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'
Expand Down