Skip to content

Commit

Permalink
Merge pull request #491 from grycap/devel
Browse files Browse the repository at this point in the history
Fix #490
  • Loading branch information
micafer authored Nov 13, 2017
2 parents af305f1 + 7a293de commit f527350
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions IM/connectors/OpenStack.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,51 @@ def get_driver(self, auth_data):
self.driver = driver
return driver

def get_instance_type(self, sizes, radl):
"""
Get the name of the instance type to launch to LibCloud
Arguments:
- size(list of :py:class: `libcloud.compute.base.NodeSize`): List of sizes on a provider
- radl(str): RADL document with the requirements of the VM to get the instance type
Returns: a :py:class:`libcloud.compute.base.NodeSize` with the instance type to launch
"""
instance_type_name = radl.getValue('instance_type')

cpu = 1
cpu_op = ">="
if radl.getFeature('cpu.count'):
cpu = radl.getValue('cpu.count')
cpu_op = radl.getFeature('cpu.count').getLogOperator()

memory = 1
memory_op = ">="
if radl.getFeature('memory.size'):
memory = radl.getFeature('memory.size').getValue('M')
memory_op = radl.getFeature('memory.size').getLogOperator()
disk_free = 0
disk_free_op = ">="
if radl.getValue('disk.0.free_size'):
disk_free = radl.getFeature('disk.0.free_size').getValue('G')
disk_free_op = radl.getFeature('memory.size').getLogOperator()

res = None
for size in sizes:
# get the node size with the lowest price and memory (in the case
# of the price is not set)
if res is None or (size.price <= res.price and size.ram <= res.ram):
str_compare = "size.ram " + memory_op + " memory"
str_compare += " and size.vcpus " + cpu_op + " cpu "
str_compare += " and size.disk " + disk_free_op + " disk_free"
if eval(str_compare):
if not instance_type_name or size.name == instance_type_name:
res = size

if res is None:
self.log_error("No compatible size found")

return res

def concreteSystem(self, radl_system, auth_data):
image_urls = radl_system.getValue("disk.0.image.url")
if not image_urls:
Expand Down

0 comments on commit f527350

Please sign in to comment.