-
Notifications
You must be signed in to change notification settings - Fork 102
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
Closed
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
f756cce
Added basic support for an openstack cloud provider.
e92811a
better support for public/private ip address
8788ccf
better support for public/private ip address
bee2a0d
fixed a keypair bug
cd8f930
Added some better statuses.
6f99623
fixed security groups for openstack
1b82f8f
Make the DNS search domain configurable at the cloud layer.
610cf62
Merge pull request #1 from erikmack/master
howech c72a466
Added a security_groups container to dsl/compute, and changed provide…
0ed441a
changed cluster and facet groups to use server.security_group instead…
dbd9f67
changed wait for ssh behavior to resect ssh rules
353862f
Fixed an unintended edit
b5591dc
machine state tweaks for openstack
bb88ae4
Factor out cloud-specific security group code
79f5289
Added elastic ip support for openstack. Shored up public ip address c…
06c92dd
Added a non-cloud cloud provider called 'static'
5a18c58
Merge pull request #2 from erikmack/master
howech fe78a40
Display floating IP address in public IP fields
5edcf9a
Bump excon dep
be86033
minor changes to help the world work better
1925e5e
Merge pull request #3 from howech/static-cloud
howech 1572b76
Merge pull request #4 from erikmack/master
howech File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
require 'digest/md5' | ||
|
||
module Ironfan | ||
class Dsl | ||
|
||
class Compute < Ironfan::Dsl | ||
def openstack(*attrs,&block) cloud(:openstack,*attrs,&block); end | ||
end | ||
|
||
class OpenStack < Cloud | ||
magic :availability_zones, Array, :default => ['nova'] | ||
magic :backing, String, :default => 'ebs' | ||
magic :bits, Integer, :default => ->{ flavor_info[:bits] } | ||
magic :bootstrap_distro, String, :default => ->{ image_info[:bootstrap_distro] } | ||
magic :chef_client_script, String | ||
magic :default_availability_zone, String, :default => ->{ availability_zones.first } | ||
#collection :elastic_load_balancers, Ironfan::Dsl::Ec2::ElasticLoadBalancer, :key_method => :name | ||
magic :ebs_optimized, :boolean, :default => false | ||
magic :flavor, String, :default => 't1.micro' | ||
#collection :iam_server_certificates, Ironfan::Dsl::Ec2::IamServerCertificate, :key_method => :name | ||
magic :image_id, String | ||
magic :image_name, String | ||
magic :keypair, String | ||
magic :monitoring, String | ||
magic :mount_ephemerals, Hash, :default => {} | ||
magic :permanent, :boolean, :default => false | ||
magic :placement_group, String | ||
magic :provider, Whatever, :default => Ironfan::Provider::OpenStack | ||
magic :elastic_ip, String | ||
magic :auto_elastic_ip, String | ||
magic :allocation_id, String | ||
magic :region, String, :default => ->{ default_region } | ||
collection :security_groups, Ironfan::Dsl::OpenStack::SecurityGroup, :key_method => :name | ||
magic :ssh_user, String, :default => ->{ image_info[:ssh_user] } | ||
magic :ssh_identity_dir, String, :default => ->{ Chef::Config.openstack_key_dir } | ||
magic :subnet, String | ||
magic :validation_key, String, :default => ->{ IO.read(Chef::Config.validation_key) rescue '' } | ||
magic :vpc, String | ||
|
||
def domain; vpc.nil? ? 'standard' : 'vpc'; end | ||
|
||
def image_info | ||
bit_str = "#{self.bits.to_i}-bit" # correct for legacy image info. | ||
keys = [region, bit_str, backing, image_name] | ||
info = Chef::Config[:openstack_image_info][ keys ] | ||
ui.warn("Can't find image for #{[region, bit_str, backing, image_name].inspect}") if info.blank? | ||
return info || {} | ||
end | ||
|
||
def image_id | ||
result = read_attribute(:image_id) || image_info[:image_id] | ||
end | ||
|
||
def ssh_key_name(computer) | ||
keypair ? keypair.to_s : computer.server.cluster_name | ||
end | ||
|
||
def default_region | ||
default_availability_zone ? default_availability_zone.gsub(/^(\w+-\w+-\d)[a-z]/, '\1') : nil | ||
end | ||
|
||
def to_display(style,values={}) | ||
return values if style == :minimal | ||
|
||
values["Flavor"] = flavor | ||
values["AZ"] = default_availability_zone | ||
return values if style == :default | ||
|
||
values["Public IP"] = elastic_ip if elastic_ip | ||
values | ||
end | ||
|
||
def flavor_info | ||
if not Chef::Config[:openstack_flavor_info].has_key?(flavor) | ||
ui.warn("Unknown machine image flavor '#{flavor}'") | ||
list_flavors | ||
return nil | ||
end | ||
Chef::Config[:openstack_flavor_info][flavor] | ||
end | ||
|
||
def implied_volumes | ||
result = [] | ||
if backing == 'ebs' | ||
result << Ironfan::Dsl::Volume.new(:name => 'root') do | ||
device '/dev/sda1' | ||
fstype 'ext4' | ||
keep false | ||
mount_point '/' | ||
end | ||
end | ||
return result unless (mount_ephemerals and (flavor_info[:ephemeral_volumes] > 0)) | ||
|
||
layout = { 0 => ['/dev/sdb','/mnt'], | ||
1 => ['/dev/sdc','/mnt2'], | ||
2 => ['/dev/sdd','/mnt3'], | ||
3 => ['/dev/sde','/mnt4'] } | ||
( 0 .. (flavor_info[:ephemeral_volumes]-1) ).each do |idx| | ||
dev, mnt = layout[idx] | ||
ephemeral = Ironfan::Dsl::Volume.new(:name => "ephemeral#{idx}") do | ||
attachable 'ephemeral' | ||
fstype 'ext3' | ||
device dev | ||
mount_point mnt | ||
mount_options 'defaults,noatime' | ||
tags({:bulk => true, :local => true, :fallback => true}) | ||
end | ||
ephemeral_attrs = mount_ephemerals.clone | ||
if ephemeral_attrs.has_key?(:disks) | ||
disk_attrs = mount_ephemerals[:disks][idx] || { } | ||
ephemeral_attrs.delete(:disks) | ||
ephemeral_attrs.merge!(disk_attrs) | ||
end | ||
ephemeral.receive! ephemeral_attrs | ||
result << ephemeral | ||
end | ||
result | ||
end | ||
|
||
def receive_provider(obj) | ||
if obj.is_a?(String) | ||
write_attribute :provider, Gorillib::Inflector.constantize(Gorillib::Inflector.camelize(obj.gsub(/\./, '/'))) | ||
else | ||
super(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 | ||
end | ||
end | ||
end | ||
|
||
Chef::Config[:openstack_flavor_info] ||= {} | ||
Chef::Config[:openstack_flavor_info].merge!({ | ||
# 32-or-64: m1.small, m1.medium, t1.micro, c1.medium | ||
't1.micro' => { :price => 0.02, :bits => 64, :ram => 686, :cores => 1, :core_size => 0.25, :inst_disks => 0, :inst_disk_size => 0, :ephemeral_volumes => 0 }, | ||
'm1.small' => { :price => 0.08, :bits => 64, :ram => 1740, :cores => 1, :core_size => 1, :inst_disks => 1, :inst_disk_size => 160, :ephemeral_volumes => 1 }, | ||
'm1.medium' => { :price => 0.165, :bits => 64, :ram => 3840, :cores => 2, :core_size => 1, :inst_disks => 1, :inst_disk_size => 410, :ephemeral_volumes => 1 }, | ||
'c1.medium' => { :price => 0.17, :bits => 64, :ram => 1740, :cores => 2, :core_size => 2.5, :inst_disks => 1, :inst_disk_size => 350, :ephemeral_volumes => 1 }, | ||
# | ||
'm1.large' => { :price => 0.32, :bits => 64, :ram => 7680, :cores => 2, :core_size => 2, :inst_disks => 1, :inst_disk_size => 850, :ephemeral_volumes => 2, }, | ||
'm2.xlarge' => { :price => 0.45, :bits => 64, :ram => 18124, :cores => 2, :core_size => 3.25, :inst_disks => 1, :inst_disk_size => 420, :ephemeral_volumes => 1, }, | ||
'c1.xlarge' => { :price => 0.64, :bits => 64, :ram => 7168, :cores => 8, :core_size => 2.5, :inst_disks => 1, :inst_disk_size => 1690, :ephemeral_volumes => 4, }, | ||
'm1.xlarge' => { :price => 0.66, :bits => 64, :ram => 15360, :cores => 4, :core_size => 2, :inst_disks => 1, :inst_disk_size => 1690, :ephemeral_volumes => 4, }, | ||
}) | ||
|
||
Chef::Config[:openstack_image_info] ||= {} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment no longer valid