Class: CloudProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/remote_execution/cloud_provider.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, *args) ⇒ CloudProvider

Returns a new instance of CloudProvider.



7
8
9
10
11
12
# File 'lib/remote_execution/cloud_provider.rb', line 7

def initialize(name, *args)
  @provider_name = name
  @provider = Fog::Compute.new(*args)
  @virtual_machines = Hash.new
  @instances = Array.new
end

Instance Attribute Details

#instancesObject

Returns the value of attribute instances.



5
6
7
# File 'lib/remote_execution/cloud_provider.rb', line 5

def instances
  @instances
end

#providerObject

Returns the value of attribute provider.



5
6
7
# File 'lib/remote_execution/cloud_provider.rb', line 5

def provider
  @provider
end

#provider_nameObject

Returns the value of attribute provider_name.



5
6
7
# File 'lib/remote_execution/cloud_provider.rb', line 5

def provider_name
  @provider_name
end

#virtual_machinesObject

Returns the value of attribute virtual_machines.



5
6
7
# File 'lib/remote_execution/cloud_provider.rb', line 5

def virtual_machines
  @virtual_machines
end

Instance Method Details

#create_instance(instance_type, parameters) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/remote_execution/cloud_provider.rb', line 14

def create_instance(instance_type, parameters)
  puts 'creating machine: ' + instance_type
  parameters.store(:flavor_id, instance_type.split('=>').first)
  name = ("#{@provider_name}:" + instance_type).split('=>')
  machine = @provider.servers.bootstrap(parameters)
  @instances.push(machine)
  machine_id = @provider.servers.get(machine.id)
  vm = VirtualMachine.new(machine_id.public_ip_address, parameters[:username], :keys => parameters[:private_key_path])
  @virtual_machines.store(name.last, vm)
end

#create_instances(instances_types, *parameters) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/remote_execution/cloud_provider.rb', line 25

def create_instances(instances_types, *parameters)
  threads = []
  instances_types.each do |instance_type|
    threads.push(Thread.fork do
      create_instance(instance_type, parameters[0])
    end)
  end
  threads.each do |thread|
    thread.join
  end
end

#destroyObject



37
38
39
# File 'lib/remote_execution/cloud_provider.rb', line 37

def destroy
  @instances.each { |instance| instance.destroy }
end