Module: Torpedo::Compute::Helper
- Defined in:
- lib/torpedo/compute/helper.rb
Class Method Summary collapse
- .get_connection ⇒ Object
- .get_flavor_ref(conn) ⇒ Object
-
.get_flavor_ref_resize(conn) ⇒ Object
flavor ref used for resize.
- .get_image_ref(conn) ⇒ Object
Class Method Details
.get_connection ⇒ Object
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 |
# File 'lib/torpedo/compute/helper.rb', line 14 def self.get_connection debug = false if ENV['DEBUG'] and ENV['DEBUG'] == 'true' then debug = true end auth_method = 'password' if ENV['NOVA_RAX_AUTH'] and ENV['NOVA_RAX_AUTH'] == '1' then auth_method = 'rax-kskey' end auth_url = ENV['NOVA_URL'] || ENV['OS_AUTH_URL'] api_key = ENV['NOVA_API_KEY'] || ENV['OS_PASSWORD'] username = ENV['NOVA_USERNAME'] || ENV['OS_USERNAME'] authtenant = ENV['NOVA_PROJECT_ID'] || ENV['OS_TENANT_NAME'] region = ENV['NOVA_REGION_NAME'] || ENV['OS_AUTH_REGION'] service_type = ENV['NOVA_SERVICE_TYPE'] || "compute" service_name = ENV['NOVA_SERVICE_NAME'] #nil by default OpenStack::Compute::Connection.new( :username => username, :api_key => api_key, :auth_url => auth_url, :region => region, :authtenant => authtenant, :is_debug => debug, :auth_method => auth_method, :service_name => service_name, :service_type => service_type ) end |
.get_flavor_ref(conn) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/torpedo/compute/helper.rb', line 69 def self.get_flavor_ref(conn) flavor_ref = FLAVOR_REF flavor_name = FLAVOR_NAME if flavor_name and not flavor_name.empty? then flavors = conn.flavors.each do |flavor| if flavor[:name] == flavor_name then flavor_ref = flavor[:id] end end elsif not flavor_ref or flavor_ref.to_s.empty? then # default to 2 (m1.small) if FLAVOR_REF and or FLAVOR_NAME aren't set flavor_ref = 2 end flavor_ref.to_s end |
.get_flavor_ref_resize(conn) ⇒ Object
flavor ref used for resize
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/torpedo/compute/helper.rb', line 90 def self.get_flavor_ref_resize(conn) flavor_ref_resize = FLAVOR_REF_RESIZE flavor_name_resize = FLAVOR_NAME_RESIZE if flavor_name_resize and not flavor_name_resize.empty? then flavors = conn.flavors.each do |flavor| if flavor[:name] == flavor_name_resize then flavor_ref_resize = flavor[:id] end end elsif not flavor_ref_resize or flavor_ref_resize.to_s.empty? then # if no flavor ref is specified for resize add one to it flavor_ref = Helper.get_flavor_ref(conn) flavor_ref_resize = flavor_ref.to_i + 1 end flavor_ref_resize.to_s end |
.get_image_ref(conn) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/torpedo/compute/helper.rb', line 47 def self.get_image_ref(conn) image_ref = IMAGE_REF image_name = IMAGE_NAME if image_name and not image_name.empty? then images = conn.images.each do |image| if image[:name] == image_name then image_ref = image[:id] end end elsif image_ref.nil? or image_ref.empty? then #take the last image if IMAGE_REF and or IMAGE_NAME aren't set images = conn.images raise "Image list is empty." if images.empty? image_ref = images.last[:id].to_s end image_ref end |