Class: Lab::Drivers::FogDriver

Inherits:
VmDriver
  • Object
show all
Defined in:
lib/lab/driver/fog_driver.rb

Instance Attribute Summary

Attributes inherited from VmDriver

#credentials, #location, #os, #tools, #vmid

Instance Method Summary collapse

Methods inherited from VmDriver

#check_file_exists, #copy_from, #copy_to, #create_directory, #register, #resume, #run_command, #unregister

Constructor Details

#initialize(config, fog_config) ⇒ FogDriver

Returns a new instance of FogDriver.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/lab/driver/fog_driver.rb', line 11

def initialize(config,fog_config)
  
  super(config)
  @fog_config = fog_config

  # Soft dependency
  begin
    require 'fog'
  rescue LoadError
    raise "WARNING: Library fog not found. Could not create driver"
  end

  if @fog_config['fog_type'] == "ec2"

    # AWS / EC2 Base Credential Configuration
    @aws_cert_file = IO.read(fog_config['fog_aws_cert_file']).chomp if fog_config['fog_aws_cert_file']
    @aws_private_key_file = IO.read(fog_config['fog_aws_private_key_file']).chomp if fog_config['fog_aws_private_key_file']
    @ec2_access_key_file = IO.read(fog_config['fog_ec2_access_key_file']).chomp if fog_config['fog_ec2_access_key_file']
    @ec2_secret_access_key_file = IO.read(fog_config['fog_ec2_secret_access_key_file']).chomp if fog_config['fog_ec2_secret_access_key_file']
    
    # Instance Keys
    @ec2_instance_public_key_file = IO.read(fog_config['fog_ec2_instance_public_key_file']).chomp if fog_config['fog_ec2_instance_public_key_file']
    @ec2_instance_private_key_file = IO.read(fog_config['fog_ec2_instance_private_key_file']).chomp if fog_config['fog_ec2_instance_private_key_file']
    
    # Instance Details
    @ec2_base_ami = fog_config['fog_ec2_base_ami']
    @ec2_flavor = fog_config['fog_ec2_flavor']
    @ec2_user = fog_config['fog_ec2_user']
    @ec2_region = fog_config['fog_ec2_region']
        
    # Set up a connection
    @compute = Fog::Compute.new(
      :provider => "Aws",
      :aws_access_key_id => @aws_access_key_file,
      :aws_secret_access_key => @aws_secret_access_key_file )
  else
    raise "Unsupported fog type"
  end
end

Instance Method Details

#cleanupObject



94
95
96
# File 'lib/lab/driver/fog_driver.rb', line 94

def cleanup
  @fog_server.destroy
end

#create_snapshot(snapshot) ⇒ Object



82
83
84
# File 'lib/lab/driver/fog_driver.rb', line 82

def create_snapshot(snapshot)
  raise "unimplemented"
end

#delete_snapshot(snapshot) ⇒ Object



90
91
92
# File 'lib/lab/driver/fog_driver.rb', line 90

def delete_snapshot(snapshot)
  raise "unimplemented"
end

#pauseObject



74
75
76
# File 'lib/lab/driver/fog_driver.rb', line 74

def pause
  raise "unimplemented"
end

#resetObject



78
79
80
# File 'lib/lab/driver/fog_driver.rb', line 78

def reset
  raise "unimplemented"
end

#revert_snapshot(snapshot) ⇒ Object



86
87
88
# File 'lib/lab/driver/fog_driver.rb', line 86

def revert_snapshot(snapshot)
  raise "unimplemented"
end

#running?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/lab/driver/fog_driver.rb', line 98

def running?
  return true #TODO
end

#startObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/lab/driver/fog_driver.rb', line 51

def start
  ec2_settings = {
    :image_id => @ec2_base_ami,
    :flavor_id =>  @ec2_flavor,
    :public_key_path => @ec2_instance_public_key_file,
    :private_key_path => @ec2_instance_private_key_file,
    :username => @ec2_user}
  begin
    @fog_server = @compute.servers.bootstrap(ec2_settings)
  rescue Fog::Compute::AWS::Error => e
    raise "Couldn't authenticate to AWS - did you place keys in the creds/ directory?"
    exit
  end
end

#stopObject



66
67
68
# File 'lib/lab/driver/fog_driver.rb', line 66

def stop
  @fog_server.destroy
end

#suspendObject



70
71
72
# File 'lib/lab/driver/fog_driver.rb', line 70

def suspend
  raise "unimplemented"
end