Module: Torpedo::Compute::Helper

Defined in:
lib/torpedo/compute/helper.rb

Class Method Summary collapse

Class Method Details

.get_connectionObject



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
# File 'lib/torpedo/compute/helper.rb', line 14

def self.get_connection

  if ENV['DEBUG'] and ENV['DEBUG'] == 'true' then
    ENV['EXCON_DEBUG'] = 'true'
  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

  Fog::Compute.new(
    :provider           => :openstack,
    :openstack_auth_url  => auth_url+'/tokens',
    :openstack_username => username,
    :openstack_tenant => authtenant,
    :openstack_api_key => api_key,
    :openstack_region => region,
    :openstack_service_type => service_type,
    :openstack_service_name => service_name
  )

end

.get_flavor_ref(conn) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/torpedo/compute/helper.rb', line 63

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



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/torpedo/compute/helper.rb', line 84

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



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/torpedo/compute/helper.rb', line 41

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