def getVmTypes(self, req): ca = CloudAdmin() r = "" for type in ca.getInstanceTypeSize(): r += """{"name" : "%s" , "cpus" : "%s" , "memory" : "%s" , "disc" : "%s"},""" % ( type[1], type[2], type[3], type[4]) return atmo_util.jsoner("\"success\"", "\"\"", "[" + r[:-1] + "]")
def checkEc2ResourceQuota(self,newly_requested_cpu=0,newly_requested_mem=0): # return true / false # get user quota / no quota info means no quota (unlimited use) p = User_resource_quotas.objects.filter(userid=self.userid) if p.count() == 0 : cpu_limit = mem_limit = -1 else : cpu_limit = p[0].cpu mem_limit = p[0].memory # get current instances and total resource uses / sum all cpus and all mem if (cpu_limit != -1) and (mem_limit != -1) : ca = CloudAdmin() machine_types = ca.getInstanceTypeSize() euca_conn = self.euca.make_connection() try : reservations = euca_conn.get_all_instances() except Exception, ex: euca.disaply_error_and_exit('%s' % ex) # reservation current_cpu_use = current_mem_use = 0 for reservation in reservations: for instance in reservation.instances: for mt in machine_types : if instance.instance_type == mt[1] : current_cpu_use += int(mt[2]) current_mem_use += int(mt[3]) if (cpu_limit >= current_cpu_use+newly_requested_cpu) and (mem_limit >= current_mem_use+newly_requested_mem): quotaAvailability = { "result" : "available" } else : quotaAvailability = { "result" : "unavailable", "current_cpu": current_cpu_use, "current_mem": current_mem_use, "limit_cpu" : cpu_limit, "limit_mem": mem_limit }
def convertMachineTypeStringToNum(self, machine_type): ca = CloudAdmin() machine_types = ca.getInstanceTypeSize() return_value = None for mt in machine_types: if machine_type == mt[1]: return_value = {"cpu": mt[2], "mem": mt[3]} return return_value
def convertMachineTypeStringToNum(self,machine_type): ca = CloudAdmin() machine_types = ca.getInstanceTypeSize() return_value = None; for mt in machine_types: if machine_type == mt[1] : return_value = {"cpu":mt[2],"mem":mt[3]} return return_value
def checkEc2ResourceQuota(self, newly_requested_cpu=0, newly_requested_mem=0): # return true / false # get user quota / no quota info means no quota (unlimited use) p = User_resource_quotas.objects.filter(userid=self.userid) if p.count() == 0: cpu_limit = mem_limit = -1 else: cpu_limit = p[0].cpu mem_limit = p[0].memory # get current instances and total resource uses / sum all cpus and all mem if (cpu_limit != -1) and (mem_limit != -1): ca = CloudAdmin() machine_types = ca.getInstanceTypeSize() euca_conn = self.euca.make_connection() try: reservations = euca_conn.get_all_instances() except Exception, ex: euca.disaply_error_and_exit('%s' % ex) # reservation current_cpu_use = current_mem_use = 0 for reservation in reservations: for instance in reservation.instances: for mt in machine_types: if instance.instance_type == mt[1]: current_cpu_use += int(mt[2]) current_mem_use += int(mt[3]) if (cpu_limit >= current_cpu_use + newly_requested_cpu) and ( mem_limit >= current_mem_use + newly_requested_mem): quotaAvailability = {"result": "available"} else: quotaAvailability = { "result": "unavailable", "current_cpu": current_cpu_use, "current_mem": current_mem_use, "limit_cpu": cpu_limit, "limit_mem": mem_limit }
def getVmTypes(self,req) : ca = CloudAdmin() r = "" for type in ca.getInstanceTypeSize() : r += """{"name" : "%s" , "cpus" : "%s" , "memory" : "%s" , "disc" : "%s"},""" % (type[1],type[2],type[3],type[4]) return atmo_util.jsoner("\"success\"","\"\"", "["+r[:-1]+"]")