Class: TDLTools::CloudInst
- Inherits:
-
Object
- Object
- TDLTools::CloudInst
- Defined in:
- lib/cloud_inst.rb
Constant Summary collapse
- DC_URL =
"http://localhost:3002/api"
- NO_START =
set to true to disable creation of instances
false
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
ssh address of the instance.
-
#scp ⇒ Object
readonly
scp command to use.
-
#ssh ⇒ Object
readonly
ssh command to use.
Instance Method Summary collapse
- #cp(from, to, append = false) ⇒ Object
- #exec(cmd) ⇒ Object
-
#initialize(cloud_attributes) ⇒ CloudInst
constructor
A new instance of CloudInst.
- #launch ⇒ Object
Constructor Details
#initialize(cloud_attributes) ⇒ CloudInst
Returns a new instance of CloudInst.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/cloud_inst.rb', line 27 def initialize(cloud_attributes) # Use deltacloud to launch and setup instance @cloud_type = cloud_attributes[:type].intern @image = cloud_attributes[:image] @keyname = cloud_attributes[:keyname] @dc = DeltaCloud.new(cloud_attributes[:username], cloud_attributes[:password], DC_URL) @dc.use_driver @cloud_type @dc.instance_variable_set :@api_provider, cloud_attributes[:provider] if @cloud_type == :openstack # XXX needed for openstack @ssh = cloud_attributes[:ssh_cmd] @scp = cloud_attributes[:scp_cmd] end |
Instance Attribute Details
#address ⇒ Object (readonly)
ssh address of the instance
19 20 21 |
# File 'lib/cloud_inst.rb', line 19 def address @address end |
#scp ⇒ Object (readonly)
scp command to use
25 26 27 |
# File 'lib/cloud_inst.rb', line 25 def scp @scp end |
#ssh ⇒ Object (readonly)
ssh command to use
22 23 24 |
# File 'lib/cloud_inst.rb', line 22 def ssh @ssh end |
Instance Method Details
#cp(from, to, append = false) ⇒ Object
69 70 71 72 73 74 |
# File 'lib/cloud_inst.rb', line 69 def cp(from, to, append=false) scpf = @scp.gsub(/\[source\]/, from). gsub(/\[dst\]/, from) `#{scpf}` `#{ssh} sudo mv #{from} #{to}` end |
#exec(cmd) ⇒ Object
65 66 67 |
# File 'lib/cloud_inst.rb', line 65 def exec(cmd) `#{@ssh} #{cmd}` end |
#launch ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/cloud_inst.rb', line 46 def launch # startup cloud instance unless NO_START dc_inst = @dc.create_instance(@image, :keyname => @keyname) sleep 300 # 5 minutes end # set various propertries from the instance dc_inst = (@cloud_type == :openstack ? @dc.instances.first : @dc.instances.last) # XXX for openstack its first, for ec2 its last address = dc_inst.public_addresses.first address = dc_inst.private_addresses.first if address.nil? @address = address[:address] @ssh = @ssh.gsub(/\[address\]/, @address) @scp = @scp.gsub(/\[address\]/, @address) self end |