class CORL::Machine::AWS

Public Instance Methods

create(options = {}) click to toggle source
Calls superclass method
   # File lib/CORL/machine/AWS.rb
48 def create(options = {})
49   super do |config|
50     # Keypair initialization
51     if key_pair = compute.key_pairs.get(keypair_name)
52       key_pair.destroy
53     end
54     compute.key_pairs.create(
55       :name       => keypair_name,
56       :public_key => Util::Disk.read(node.public_key)
57     )
58     config[:key_name] = keypair_name
59   end
60 end
create_image(options = {}) click to toggle source
Calls superclass method
   # File lib/CORL/machine/AWS.rb
75 def create_image(options = {})
76   super do |image_name, config, success|
77     image_name        = image_name.gsub(/[^A-Za-z0-9\(\)\.\-\_\/]+/, '_')
78     image_description = config.get(:description, "CORL backup image")
79 
80     data     = compute.create_image(server.identity, image_name, image_description)
81     image_id = data.body['imageId']
82 
83     Fog.wait_for do
84       compute.describe_images('ImageId' => image_id).body['imagesSet'].first['imageState'] == 'available'
85     end
86 
87     if image_id
88       node[:image] = image_id
89       success      = true
90     end
91     success
92   end
93 end
destroy(options = {}) click to toggle source
Calls superclass method
    # File lib/CORL/machine/AWS.rb
 97 def destroy(options = {})
 98   super do |config|
 99     unless config.get(:stop, false)
100       # Keypair destruction
101       if key_pair = compute.key_pairs.get(keypair_name)
102         key_pair.destroy
103       end
104     end
105     true
106   end
107 end
ensure_security_group(group_name, from_port, to_port = nil, options = {}) click to toggle source
    # File lib/CORL/machine/AWS.rb
118 def ensure_security_group(group_name, from_port, to_port = nil, options = {})
119   config         = Config.ensure(options)
120   security_group = compute.security_groups.get(group_name)
121   cidrip         = config.get(:cidrip, '0.0.0.0/0')
122   protocol       = config.get(:protocol, 'tcp')
123   to_port        = from_port if to_port.nil?
124 
125   if security_group.nil?
126     security_group = compute.security_groups.create(
127       :name        => group_name,
128       :description => config.get(:description, "Opening port range: #{from_port} to #{to_port}")
129     )
130     raise unless security_group # TODO: Better error class
131   end
132 
133   authorized = false
134   if security_group.ip_permissions
135     authorized = security_group.ip_permissions.detect do |ip_permission|
136       ip_permission['ipRanges'].first && ip_permission['ipRanges'].first['cidrIp'] == cidrip &&
137       ip_permission['fromPort'] == from_port &&
138       ip_permission['ipProtocol'] == protocol &&
139       ip_permission['toPort'] == to_port
140     end
141   end
142   unless authorized
143     security_group.authorize_port_range(Range.new(from_port, to_port))
144   end
145 
146   if server
147     server.groups = [ group_name ] | server.groups
148     server.save
149   end
150 end
init_server() click to toggle source
Calls superclass method
   # File lib/CORL/machine/AWS.rb
21 def init_server
22   super do
23     myself.plugin_name = @server.id
24 
25     node[:id]           = plugin_name
26     node[:public_ip]    = @server.public_ip_address
27     node[:private_ip]   = @server.private_ip_address
28     node[:machine_type] = @server.flavor_id
29     node[:image]        = @server.image_id
30     node.user           = @server.username unless node.user
31 
32     @server.private_key_path = node.private_key if node.private_key
33     @server.public_key_path  = node.public_key if node.public_key
34   end
35 end
init_ssh(ssh_port) click to toggle source
   # File lib/CORL/machine/AWS.rb
39 def init_ssh(ssh_port)
40   # Security group initialization
41   if compute && ssh_port != 22
42     ensure_security_group("CORL_SSH_#{ssh_port}", ssh_port)
43   end
44 end
keypair_name() click to toggle source
    # File lib/CORL/machine/AWS.rb
112 def keypair_name
113   "CORL_#{node.plugin_name}"
114 end
reload(options = {}) click to toggle source
Calls superclass method
   # File lib/CORL/machine/AWS.rb
64 def reload(options = {})
65   super do |config|
66     success = server.reboot
67 
68     server.wait_for { ready? } if success
69     success
70   end
71 end
set_connection() click to toggle source
Calls superclass method
   # File lib/CORL/machine/AWS.rb
12 def set_connection
13   require 'unf'
14   super
15   Kernel.load File.join(File.dirname(__FILE__), '..', '..', 'core', 'mod', 'fog_aws_server.rb')
16 end