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

Added basic support for an openstack cloud provider. #332

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
source "http://rubygems.org"

gem 'chef', "~> 10.16"
gem 'fog', "~> 1.2"
gem 'excon', "~> 0.21.0" # v0.22 breaks EC2 calls
gem 'fog', "~> 1.19"
gem 'excon', "~> 0.31.0" # v0.22 breaks EC2 calls
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment no longer valid

gem 'formatador', "~> 0.2"
gem 'gorillib', "~> 0.5.0"
gem 'rbvmomi'
Expand Down
24 changes: 13 additions & 11 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ GEM
multi_json (>= 1.1)
diff-lcs (1.2.5)
erubis (2.7.0)
excon (0.21.0)
excon (0.31.0)
ffi (1.9.0)
fog (1.10.1)
fog (1.19.0)
builder
excon (~> 0.20)
excon (~> 0.31.0)
formatador (~> 0.2.0)
mime-types
multi_json (~> 1.0)
net-scp (~> 1.1)
net-ssh (>= 2.1.3)
nokogiri (~> 1.5.0)
nokogiri (~> 1.5)
ruby-hmac
formatador (0.2.4)
git (1.2.5)
Expand Down Expand Up @@ -82,24 +82,26 @@ GEM
rb-kqueue (>= 0.2)
lumberjack (1.0.3)
method_source (0.8.1)
mime-types (1.23)
mime-types (2.0)
mini_portile (0.5.2)
mixlib-authentication (1.3.0)
mixlib-log
mixlib-cli (1.3.0)
mixlib-config (1.1.2)
mixlib-log (1.6.0)
mixlib-shellout (1.1.0)
moneta (0.6.0)
multi_json (1.7.7)
net-scp (1.1.1)
multi_json (1.8.2)
net-scp (1.1.2)
net-ssh (>= 2.6.5)
net-ssh (2.6.7)
net-ssh (2.7.0)
net-ssh-gateway (1.2.0)
net-ssh (>= 2.6.5)
net-ssh-multi (1.1)
net-ssh (>= 2.1.4)
net-ssh-gateway (>= 0.99.0)
nokogiri (1.5.10)
nokogiri (1.6.1)
mini_portile (~> 0.5.0)
ohai (6.16.0)
ipaddress
mixlib-cli
Expand Down Expand Up @@ -175,8 +177,8 @@ DEPENDENCIES
chef (~> 10.16)
chef-zero
diff-lcs (~> 1.2.5)
excon (~> 0.21.0)
fog (~> 1.2)
excon (~> 0.31.0)
fog (~> 1.19)
formatador (~> 0.2)
gorillib (~> 0.5.0)
guard (~> 1)
Expand Down
6 changes: 3 additions & 3 deletions ironfan.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ Gem::Specification.new do |s|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<chef>, ["~> 10.16"])
s.add_runtime_dependency(%q<fog>, ["~> 1.2"])
s.add_runtime_dependency(%q<excon>, ["~> 0.21.0"])
s.add_runtime_dependency(%q<excon>, ["~> 0.31.0"])
s.add_runtime_dependency(%q<formatador>, ["~> 0.2"])
s.add_runtime_dependency(%q<gorillib>, ["~> 0.5.0"])
s.add_runtime_dependency(%q<rbvmomi>, [">= 0"])
Expand All @@ -197,7 +197,7 @@ Gem::Specification.new do |s|
else
s.add_dependency(%q<chef>, ["~> 10.16"])
s.add_dependency(%q<fog>, ["~> 1.2"])
s.add_dependency(%q<excon>, ["~> 0.21.0"])
s.add_dependency(%q<excon>, ["~> 0.31.0"])
s.add_dependency(%q<formatador>, ["~> 0.2"])
s.add_dependency(%q<gorillib>, ["~> 0.5.0"])
s.add_dependency(%q<rbvmomi>, [">= 0"])
Expand All @@ -213,7 +213,7 @@ Gem::Specification.new do |s|
else
s.add_dependency(%q<chef>, ["~> 10.16"])
s.add_dependency(%q<fog>, ["~> 1.2"])
s.add_dependency(%q<excon>, ["~> 0.21.0"])
s.add_dependency(%q<excon>, ["~> 0.31.0"])
s.add_dependency(%q<formatador>, ["~> 0.2"])
s.add_dependency(%q<gorillib>, ["~> 0.5.0"])
s.add_dependency(%q<rbvmomi>, [">= 0"])
Expand Down
7 changes: 7 additions & 0 deletions lib/chef/knife/bootstrap/ubuntu12.04-ironfan.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ set -e

<%= (@config[:verbosity].to_i > 1 ? 'set -v' : '') %>

echo "deb http://apt.opscode.com/ `lsb_release -cs`-0.10 main" | sudo tee /etc/apt/sources.list.d/opscode.list

# Make sure that opscode chef is on the apt repo list.
sudo mkdir -p /etc/apt/trusted.gpg.d
gpg --keyserver keys.gnupg.net --recv-keys 83EF826A
gpg --export [email protected] | sudo tee /etc/apt/trusted.gpg.d/opscode-keyring.gpg > /dev/null

date > /etc/box_build_time

echo -e "`date` \n\n**** \n**** apt update:\n****\n"
Expand Down
39 changes: 10 additions & 29 deletions lib/chef/knife/cluster_launch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ class ClusterLaunch < Knife
:boolean => true,
:default => false

option :wait_ssh,
:long => "--[no-]wait-ssh",
:description => "Wait for the target machine to open an ssh port",
:boolean => true,
:default => true

def _run
load_ironfan
die(banner) if @name_args.empty?
Expand Down Expand Up @@ -110,10 +116,10 @@ def _run
def perform_after_launch_tasks(computer)
# Try SSH
unless config[:dry_run]
Ironfan.step(computer.name, 'trying ssh', :white)
# FIXME: This is EC2-specific, abstract it
address = computer.machine.vpc_id.nil? ? computer.machine.public_hostname : computer.machine.public_ip_address
nil until tcp_test_ssh(address){ sleep @initial_sleep_delay ||= 10 }
if config[:wait_ssh]
Ironfan.step(computer.name, 'trying ssh', :white)
nil until wait_for_ssh(computer){ sleep @initial_sleep_delay ||= 10 }
end
end

# Run Bootstrap
Expand All @@ -123,31 +129,6 @@ def perform_after_launch_tasks(computer)
end
end

def tcp_test_ssh(target)
tcp_socket = TCPSocket.new(target, 22)
readable = IO.select([tcp_socket], nil, nil, 5)
if readable
Chef::Log.debug("sshd accepting connections on #{target}, banner is #{tcp_socket.gets}")
yield
true
else
false
end
rescue Errno::ETIMEDOUT
Chef::Log.debug("ssh to #{target} timed out")
false
rescue Errno::ECONNREFUSED
Chef::Log.debug("ssh connection to #{target} refused")
sleep 2
false
rescue Errno::EHOSTUNREACH
Chef::Log.debug("ssh host #{target} unreachable")
sleep 2
false
ensure
tcp_socket && tcp_socket.close
end

def warn_or_die_on_bogus_servers(target)
ui.info("")
ui.info "Cluster has servers in a transitional or undefined state (shown as 'bogus'):"
Expand Down
35 changes: 35 additions & 0 deletions lib/chef/knife/ironfan_knife_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,41 @@ def run_bootstrap(computer)
end
end

def wait_for_ssh(computer)
ssh = Chef::Knife::Ssh.new
ssh.ui = ui
ssh.name_args = [ computer.name, "ls" ]
ssh.config[:ssh_user] = Chef::Config[:knife][:ssh_user] || config[:ssh_user]
ssh.config[:ssh_password] = config[:ssh_password]
ssh.config[:ssh_port] = Chef::Config[:knife][:ssh_port] || config[:ssh_port]
ssh.config[:ssh_gateway] = Chef::Config[:knife][:ssh_gateway] || config[:ssh_gateway]
ssh.config[:forward_agent] = Chef::Config[:knife][:forward_agent] || config[:forward_agent]
ssh.config[:identity_file] = Chef::Config[:knife][:identity_file] || config[:identity_file]
ssh.config[:manual] = true
ssh.config[:host_key_verify] = Chef::Config[:knife][:host_key_verify] || config[:host_key_verify]
ssh.config[:on_error] = :raise
session = ssh.session
return true
rescue Errno::ETIMEDOUT
Chef::Log.debug("ssh to #{computer.name} timed out")
return false
rescue Errno::ECONNREFUSED
Chef::Log.debug("ssh connection to #{computer.name} refused")
yield
return false
rescue Errno::EHOSTUNREACH
Chef::Log.debug("ssh host #{computer.name} unreachable")
yield
return false
rescue
Chef::Log.debug("something else went wrong while wating for ssh host #{computer.name}")
raise
return false
else
session && session.close
session = nil
end

#
# Utilities
#
Expand Down
2 changes: 2 additions & 0 deletions lib/ironfan/dsl/cloud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def self.receive(obj, &block)
when :virtualbox then VirtualBox
when :vsphere then Vsphere
when :rds then Rds
when :openstack then OpenStack
when :static then Static
else raise "Unsupported cloud #{obj[:name]}"
end
end
Expand Down
5 changes: 2 additions & 3 deletions lib/ironfan/dsl/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,11 @@ def wire_to(compute, full_server_cluster_v, keys)
discovery = {discovers: keys.reverse.inject(full_server_cluster_v){|hsh,key| {key => hsh}}}
(compute.facet_role || compute.cluster_role).override_attributes(discovery)

# FIXME: This is Ec2-specific and probably doesn't belong here.
client_group_v = client_group(compute)
server_group_v = security_group(full_server_cluster_v)

group_edge(compute.cloud(:ec2), client_group_v, :authorized_by_group, server_group_v)
group_edge(compute.cloud(:ec2), client_group_v, :authorize_group, server_group_v) if bidirectional
group_edge(compute, client_group_v, :authorized_by_group, server_group_v)
group_edge(compute, client_group_v, :authorize_group, server_group_v) if bidirectional

Chef::Log.debug("discovered #{announce_name} for #{cluster_name}: #{discovery}")
end
Expand Down
1 change: 1 addition & 0 deletions lib/ironfan/dsl/compute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Compute < Ironfan::Dsl
collection :run_list_items, RunListItem, :resolver => :merge_resolve, :key_method => :name
collection :clouds, Ironfan::Dsl::Cloud, :resolver => :merge_resolve, :key_method => :name
collection :volumes, Ironfan::Dsl::Volume, :resolver => :merge_resolve, :key_method => :name
collection :security_groups, Ironfan::Dsl::SecurityGroup, :resolver => :merge_resolve, :key_method => :name

# Resolve these normally (overriding on each layer)
magic :environment, Symbol, :default => :_default
Expand Down
28 changes: 2 additions & 26 deletions lib/ironfan/dsl/ec2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ class Ec2 < Cloud
magic :auto_elastic_ip, String
magic :allocation_id, String
magic :region, String, :default => ->{ default_region }
collection :security_groups, Ironfan::Dsl::Ec2::SecurityGroup, :key_method => :name
collection :security_groups, Ironfan::Dsl::SecurityGroup, :key_method => :name
magic :ssh_user, String, :default => ->{ image_info[:ssh_user] }
magic :ssh_identity_dir, String, :default => ->{ Chef::Config.ec2_key_dir }
magic :subnet, String
magic :validation_key, String, :default => ->{ IO.read(Chef::Config.validation_key) rescue '' }
magic :vpc, String
magic :dns_search_domain, String, :default => 'internal'

def domain; vpc.nil? ? 'standard' : 'vpc'; end

Expand Down Expand Up @@ -125,31 +126,6 @@ def receive_provider(obj)
end
end

class SecurityGroup < Ironfan::Dsl
field :name, String
field :group_authorized, Array, :default => []
field :group_authorized_by, Array, :default => []
field :range_authorizations, Array, :default => []

def authorize_port_range(range, cidr_ip = '0.0.0.0/0', ip_protocol = 'tcp')
range = (range .. range) if range.is_a?(Integer)
range_authorizations << [range, cidr_ip, ip_protocol]
range_authorizations.compact!
range_authorizations.uniq!
end

def authorized_by_group(other_name)
group_authorized_by << other_name.to_s
group_authorized_by.compact!
group_authorized_by.uniq!
end

def authorize_group(other_name)
group_authorized << other_name.to_s
group_authorized.compact!
group_authorized.uniq!
end
end

class ElasticLoadBalancer

Expand Down
Loading