Class: Fog::Compute::OpenNebula::Flavor

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/opennebula/models/compute/flavor.rb

Instance Method Summary collapse

Instance Method Details

#get_contextObject



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/fog/opennebula/models/compute/flavor.rb', line 141

def get_context
  return "" unless context
  if context.is_a? String
    return %Q|CONTEXT= [ #{context} ]\n|
  elsif context.is_a? Hash
    ret = ""
    context.each do |key, value|
      ret << %Q|"#{key}"="#{value}",|
    end
    ret.chop! if ret.end_with?(',')
    return %Q|CONTEXT=[ #{ret} ]\n|
  else
    return ""
  end
end

#get_cpuObject



47
48
49
50
51
# File 'lib/fog/opennebula/models/compute/flavor.rb', line 47

def get_cpu
  return "CPU=#{vcpu.to_f/10}\n" unless cpu
  return "CPU=#{vcpu}\n" if cpu.to_i > vcpu.to_i
  "CPU=#{cpu}\n"
end

#get_diskObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/fog/opennebula/models/compute/flavor.rb', line 72

def get_disk
  return "" unless disk
  ret = ""
  if disk.is_a? Array
    disk.each do |d|
      ret += "DISK=#{d}\n"
    end
  else
    ret = "DISK=#{disk}\n"
  end
  ret.gsub!(/\{/, '[')
  ret.gsub!(/\}/, ']')
  ret.gsub!(/>/,'')
  ret 
end

#get_graphicsObject



97
98
99
100
101
102
103
104
# File 'lib/fog/opennebula/models/compute/flavor.rb', line 97

def get_graphics
  return "" unless graphics 
  ret = "GRAPHICS=#{graphics}\n"
  ret.gsub!(/\{/, '[')
  ret.gsub!(/\}/, ']')
  ret.gsub!(/>/,'')
  ret 
end

#get_memoryObject



58
59
60
61
# File 'lib/fog/opennebula/models/compute/flavor.rb', line 58

def get_memory
  self.memory = 128 unless memory
  "MEMORY=#{memory}\n"
end

#get_nicObject



106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/fog/opennebula/models/compute/flavor.rb', line 106

def get_nic
  # NIC=[MODEL="virtio",NETWORK="vlan17",NETWORK_UNAME="oneadmin"]
  return "" if nic.nil?
  ret = ""
  if nic.is_a? Array
    nic.each do |n|
      ret += %Q|NIC=[MODEL="#{n.model}",NETWORK_ID="#{n.vnet.id}"]\n| unless n.vnet.nil?
    end
  end
  #ret.gsub!(/\{/, '[')
  #ret.gsub!(/\}/, ']')
  #ret.gsub!(/>/,'')
  ret 
end

#get_osObject



88
89
90
91
92
93
94
95
# File 'lib/fog/opennebula/models/compute/flavor.rb', line 88

def get_os
  return "" unless os
  ret = "OS=#{os}\n"
  ret.gsub!(/\{/, '[')
  ret.gsub!(/\}/, ']')
  ret.gsub!(/>/,'')
  ret 
end

#get_rawObject



63
64
65
66
67
68
69
70
# File 'lib/fog/opennebula/models/compute/flavor.rb', line 63

def get_raw
  return "" unless raw
  ret = "RAW=#{raw}\n"
  ret.gsub!(/\{/, '[')
  ret.gsub!(/\}/, ']')
  ret.gsub!(/>/,'')
  ret
end

#get_sched_ds_rankObject



126
127
128
129
# File 'lib/fog/opennebula/models/compute/flavor.rb', line 126

def get_sched_ds_rank
  return "" unless sched_ds_rank 
  %Q|SCHED_DS_RANK="#{sched_ds_rank.gsub(/"/){ %q(\") }}"\n|
end

#get_sched_ds_requirementsObject



121
122
123
124
# File 'lib/fog/opennebula/models/compute/flavor.rb', line 121

def get_sched_ds_requirements
  return "" unless sched_ds_requirements 
  %Q|SCHED_DS_REQUIREMENTS="#{sched_ds_requirements.gsub(/"/){ %q(\") }}"\n|
end

#get_sched_rankObject



136
137
138
139
# File 'lib/fog/opennebula/models/compute/flavor.rb', line 136

def get_sched_rank
  return "" unless sched_rank 
  %Q|SCHED_RANK="#{sched_rank.gsub(/"/){ %q(\") }}"\n|
end

#get_sched_requirementsObject



131
132
133
134
# File 'lib/fog/opennebula/models/compute/flavor.rb', line 131

def get_sched_requirements
  return "" unless sched_requirements 
  %Q|SCHED_REQUIREMENTS="#{sched_requirements.gsub(/"/){ %q(\") }}"\n|
end

#get_user_variablesObject



157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/fog/opennebula/models/compute/flavor.rb', line 157

def get_user_variables
  return "" unless user_variables
  if user_variables.is_a? String
    return %Q|#{user_variables}\n|
  elsif user_variables.is_a? Hash
    ret = ""
    user_variables.each do |key, value|
      ret << %Q|#{key}="#{value}"\n|
    end
    return ret
  else
    return ""
  end
end

#get_vcpuObject



53
54
55
56
# File 'lib/fog/opennebula/models/compute/flavor.rb', line 53

def get_vcpu
  self.vcpu = 1 unless vcpu
  "VCPU=#{vcpu}\n"
end

#to_labelObject



26
27
28
# File 'lib/fog/opennebula/models/compute/flavor.rb', line 26

def to_label
  "#{name} -- #{vcpu} VCPU - #{memory}MB Mem"
end

#to_sObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/fog/opennebula/models/compute/flavor.rb', line 30

def to_s
  "" + get_cpu \
    + get_vcpu \
    + get_memory \
    + get_disk \
    + get_nic \
    + get_os \
    + get_graphics \
    + get_raw \
    + get_sched_requirements \
    + get_sched_ds_requirements \
    + get_sched_rank \
    + get_sched_ds_rank \
    + get_context \
    + get_user_variables
end