Esempio n. 1
0
 def load_using_host(self, hd):
     
     dbconfig = DBConfig()
     db = dbconfig.get_db()
     
     table = db.get_host_domain()        
     
     expr = (table.c.provider_id == hd.provider_id) & (table.c.host_type_id == hd.host_type_id)
     expr = expr & (table.c.region_id == hd.region_id) & (table.c.data_center_id == hd.data_center_id)
     expr = expr & (table.c.az_index == hd.az_index) & (table.c.cpu == hd.cpu) 
     expr = expr & (table.c.memory == hd.memory) & (table.c.disk_size == hd.disk_size)
     expr = expr & (table.c.disk_type_id == hd.disk_type_id) & (table.c.private == hd.private)
     expr = expr & (table.c.optimized == hd.optimized) & (table.c.cost == hd.cost)  
                 
     s = table.select(expr)
     result = s.execute()
     
     print 'result.rowcount: ', result.rowcount
     
     for res in result:
         hd.id = res.id
         hd.host_id = res.host_id
         hd.node_type_uri = res.node_type_uri
     
     return hd
Esempio n. 2
0
    def load_using_request(self, r):
        dbconfig = DBConfig()
        db = dbconfig.get_db()
        
        table = db.get_host_domain()        
        
        expr = ((table.c.cpu >= (r.cpu * r.op_factor)) | ((table.c.host_id != None) & (table.c.cpu  >= r.cpu)) )
        expr = expr & ((table.c.memory >= (r.memory * r.op_factor)) | ((table.c.host_id != None) & (table.c.memory >= r.memory)))
        expr = expr & ((table.c.disk_size >= (r.disk_size * r.op_factor)) | ((table.c.host_id != None) & (table.c.disk_size >= r.disk_size)))

        
        if (r.host_type_id > 0):
            expr = expr & (table.c.host_type_id == r.host_type_id)
            
        if (r.region_id > 0):    
            expr = expr & (table.c.region_id == r.region_id)
        
        if (r.disk_type_id > 0):    
            expr = expr & (table.c.disk_type_id == r.disk_type_id)
            
        if (r.price_limit > 0):    
            expr = expr & ((table.c.cost <= r.price_limit) )
            
        if (r.private > 0):
            expr = expr & (table.c.private == r.private)
        
        if (r.optimized > 0):
            expr = expr & (table.c.optimized == r.optimized)            
                        
        s = table.select(expr)
        result = s.execute()
        
        return result
Esempio n. 3
0
    def cleanup(self):
        dbconfig = DBConfig()
        db = dbconfig.get_db()

        table = db.get_containers()
        d = table.delete()
        d.execute()
Esempio n. 4
0
 def save(self):
     dbconfig = DBConfig()
     db = dbconfig.get_db()
     
     table = db.get_hosts()
     session = db.get_session()
     
     
     qry = session.query(func.max(table.c.id).label("max_id"))
     res = qry.one()
     oid = res.max_id
     
     print "oid: ", oid
     
     if oid > -1:
         oid = oid + 1
     else:
         oid = 1
     
     i = table.insert()
     i.execute(id=oid,
               host_template_id=self.host.host_template_id,
               node_uri=self.host.node_uri,
               node_cluster_uri=self.host.node_cluster_uri)
     
     return oid
Esempio n. 5
0
    def load(self, oid):
        dbconfig = DBConfig()
        db = dbconfig.get_db()

        table = db.get_requests()
        s = table.select(table.c.id == oid)
        result = s.execute()

        for res in result:
            self.request.id = res.id
            self.request.host_type_id = res.host_type_id
            self.request.region_id = res.region_id
            self.request.cpu = res.cpu
            self.request.memory = res.memory
            self.request.disk_size = res.disk_size
            self.request.disk_type_id = res.disk_type_id
            self.request.ha_scale = res.ha_scale
            self.request.dr_scale = res.dr_scale
            self.request.op_factor = res.op_factor
            self.request.price_limit = res.price_limit
            self.request.optimized = res.optimized
            self.request.private = res.private
            self.request.image = res.image

        return self.request
Esempio n. 6
0
    def cleanup(self):
        dbconfig = DBConfig()
        db = dbconfig.get_db()

        table = db.get_requests()
        d = table.delete()
        d.execute()
Esempio n. 7
0
    def save(self):
        dbconfig = DBConfig()
        db = dbconfig.get_db()

        table = db.get_requests()
        session = db.get_session()

        qry = session.query(func.max(table.c.id).label("max_id"))
        res = qry.one()
        oid = res.max_id

        print "oid: ", oid

        if oid > -1:
            oid = oid + 1
        else:
            oid = 1

        i = table.insert()
        i.execute(id=oid,
                  host_type_id=self.request.host_type_id,
                  region_id=self.request.region_id,
                  cpu=self.request.cpu,
                  memory=self.request.memory,
                  disk_size=self.request.disk_size,
                  disk_type_id=self.request.disk_type_id,
                  ha_scale=self.request.ha_scale,
                  dr_scale=self.request.dr_scale,
                  op_factor=self.request.op_factor,
                  price_limit=self.request.price_limit,
                  private=self.request.private,
                  optimized=self.request.optimized,
                  image=self.request.image)

        return oid
Esempio n. 8
0
 def save(self):
     dbconfig = DBConfig()
     db = dbconfig.get_db()
     
     table = db.get_containers()
     session = db.get_session()
     
     
     qry = session.query(func.max(table.c.id).label("max_id"))
     res = qry.one()
     oid = res.max_id
     
     print "oid: ", oid
     
     if oid > -1:
         oid = oid + 1
     else:
         oid = 1
     
     i = table.insert()
     i.execute(id=oid,
               host_id=self.container.host_id,
               cpu=self.container.cpu,
               memory=self.container.memory,
               disk_size=self.container.disk_size,
               request_id=self.container.request_id,
               service_uri=self.container.service_uri,
               container_uri=self.container.container_uri)
     
     return oid
Esempio n. 9
0
    def save(self):
        dbconfig = DBConfig()
        db = dbconfig.get_db()

        table = db.get_containers()
        session = db.get_session()

        qry = session.query(func.max(table.c.id).label("max_id"))
        res = qry.one()
        oid = res.max_id

        print "oid: ", oid

        if oid > -1:
            oid = oid + 1
        else:
            oid = 1

        i = table.insert()
        i.execute(id=oid,
                  host_id=self.container.host_id,
                  cpu=self.container.cpu,
                  memory=self.container.memory,
                  disk_size=self.container.disk_size,
                  request_id=self.container.request_id,
                  service_uri=self.container.service_uri,
                  container_uri=self.container.container_uri)

        return oid
Esempio n. 10
0
 def delete(self, oid):
     dbconfig = DBConfig()
     db = dbconfig.get_db()
     
     table = db.get_containers()
     s = table.delete(table.c.id == oid)
     s.execute()
Esempio n. 11
0
    def load(self,oid):
        dbconfig = DBConfig()
        db = dbconfig.get_db()
        
        table = db.get_requests()
        s = table.select(table.c.id == oid)
        result = s.execute()

        for res in result:
            self.request.id = res.id
            self.request.host_type_id = res.host_type_id
            self.request.region_id = res.region_id
            self.request.cpu = res.cpu
            self.request.memory = res.memory
            self.request.disk_size = res.disk_size
            self.request.disk_type_id = res.disk_type_id
            self.request.ha_scale = res.ha_scale
            self.request.dr_scale = res.dr_scale
            self.request.op_factor = res.op_factor
            self.request.price_limit = res.price_limit
            self.request.optimized = res.optimized
            self.request.private = res.private
            self.request.image = res.image
            
        return self.request
Esempio n. 12
0
 def cleanup(self):
     dbconfig = DBConfig()
     db = dbconfig.get_db()
             
     table = db.get_requests()        
     d = table.delete()
     d.execute()
Esempio n. 13
0
 def cleanup(self):
     dbconfig = DBConfig()
     db = dbconfig.get_db()
             
     table = db.get_containers()        
     d = table.delete()
     d.execute()
Esempio n. 14
0
    def delete(self, oid):
        dbconfig = DBConfig()
        db = dbconfig.get_db()

        table = db.get_containers()
        s = table.delete(table.c.id == oid)
        s.execute()
Esempio n. 15
0
    def save(self):
        dbconfig = DBConfig()
        db = dbconfig.get_db()

        table = db.get_hosts()
        session = db.get_session()

        qry = session.query(func.max(table.c.id).label("max_id"))
        res = qry.one()
        oid = res.max_id

        print "oid: ", oid

        if oid > -1:
            oid = oid + 1
        else:
            oid = 1

        i = table.insert()
        i.execute(id=oid,
                  host_template_id=self.host.host_template_id,
                  node_uri=self.host.node_uri,
                  node_cluster_uri=self.host.node_cluster_uri)

        return oid
Esempio n. 16
0
    def load(self,oid):
        dbconfig = DBConfig()
        db = dbconfig.get_db()
        
        table = db.get_host_templates()
        s = table.select(table.c.id == oid)
        result = s.execute()

        for res in result:
            self.host_template.id = res.id
            self.host_template.name = res.name
            self.host_template.provider_id = res.provider_id
            self.host_template.host_type_id = res.host_type_id
            self.host_template.region_id = res.region_id
            self.host_template.data_center_id = res.data_center_id
            self.host_template.az_index = res.az_index
            self.host_template.cpu = res.cpu
            self.host_template.memory = res.memory
            self.host_template.disk_size = res.disk_size
            self.host_template.disk_type_id = res.disk_type_id
            self.host_template.private = res.private
            self.host_template.optimized = res.optimized            
            self.host_template.cost = res.cost
            self.host_template.node_type_uri = res.node_type_uri
            
        return self.host_template
Esempio n. 17
0
    def load(self, oid):
        dbconfig = DBConfig()
        db = dbconfig.get_db()

        table = db.get_host_templates()
        s = table.select(table.c.id == oid)
        result = s.execute()

        for res in result:
            self.host_template.id = res.id
            self.host_template.name = res.name
            self.host_template.provider_id = res.provider_id
            self.host_template.host_type_id = res.host_type_id
            self.host_template.region_id = res.region_id
            self.host_template.data_center_id = res.data_center_id
            self.host_template.az_index = res.az_index
            self.host_template.cpu = res.cpu
            self.host_template.memory = res.memory
            self.host_template.disk_size = res.disk_size
            self.host_template.disk_type_id = res.disk_type_id
            self.host_template.private = res.private
            self.host_template.optimized = res.optimized
            self.host_template.cost = res.cost
            self.host_template.node_type_uri = res.node_type_uri

        return self.host_template
Esempio n. 18
0
    def load_using_host(self, hd):

        dbconfig = DBConfig()
        db = dbconfig.get_db()

        table = db.get_host_domain()

        expr = (table.c.provider_id == hd.provider_id) & (table.c.host_type_id
                                                          == hd.host_type_id)
        expr = expr & (table.c.region_id == hd.region_id) & (
            table.c.data_center_id == hd.data_center_id)
        expr = expr & (table.c.az_index == hd.az_index) & (table.c.cpu
                                                           == hd.cpu)
        expr = expr & (table.c.memory == hd.memory) & (table.c.disk_size
                                                       == hd.disk_size)
        expr = expr & (table.c.disk_type_id
                       == hd.disk_type_id) & (table.c.private == hd.private)
        expr = expr & (table.c.optimized == hd.optimized) & (table.c.cost
                                                             == hd.cost)

        s = table.select(expr)
        result = s.execute()

        print 'result.rowcount: ', result.rowcount

        for res in result:
            hd.id = res.id
            hd.host_id = res.host_id
            hd.node_type_uri = res.node_type_uri

        return hd
Esempio n. 19
0
 def is_empty(self, host_id):
     dbconfig = DBConfig()
     db = dbconfig.get_db()
     
     table = db.get_containers() 
     s = table.select(table.c.host_id == host_id)
     result = s.execute()
     
     print "is_empty:", (result.rowcount == 0)
     return (result.rowcount == 0)
Esempio n. 20
0
    def is_empty(self, host_id):
        dbconfig = DBConfig()
        db = dbconfig.get_db()

        table = db.get_containers()
        s = table.select(table.c.host_id == host_id)
        result = s.execute()

        print "is_empty:", (result.rowcount == 0)
        return (result.rowcount == 0)
Esempio n. 21
0
 def load_all(self):
     dbconfig = DBConfig()
     db = dbconfig.get_db()
     
     table = db.get_containers()     
                 
     s = table.select()
     result = s.execute()
     
     print 'result.rowcount: ', result.rowcount
             
     return result
Esempio n. 22
0
    def load_all(self):
        dbconfig = DBConfig()
        db = dbconfig.get_db()

        table = db.get_containers()

        s = table.select()
        result = s.execute()

        print 'result.rowcount: ', result.rowcount

        return result
Esempio n. 23
0
    def load(self, oid):
        dbconfig = DBConfig()
        db = dbconfig.get_db()

        table = db.get_hosts()
        s = table.select(table.c.id == oid)
        result = s.execute()

        for res in result:
            self.host.id = res.id
            self.host.host_template_id = res.host_template_id
            self.host.node_uri = res.node_uri
            self.host.node_cluster_uri = res.node_cluster_uri

        return self.host
Esempio n. 24
0
    def load(self,oid):
        dbconfig = DBConfig()
        db = dbconfig.get_db()
        
        table = db.get_hosts()
        s = table.select(table.c.id == oid)
        result = s.execute()

        for res in result:
            self.host.id = res.id
            self.host.host_template_id = res.host_template_id
            self.host.node_uri = res.node_uri
            self.host.node_cluster_uri = res.node_cluster_uri
            
        return self.host
Esempio n. 25
0
    def load(self, oid):
        dbconfig = DBConfig()
        db = dbconfig.get_db()

        table = db.get_data_centers()
        s = table.select(table.c.id == oid)
        result = s.execute()

        for res in result:
            self.data_center.id = res.id
            self.data_center.name = res.name
            self.data_center.region_id = res.region_id
            self.data_center.data_center_uri = res.data_center_uri

        return self.data_center
Esempio n. 26
0
    def load(self,oid):
        dbconfig = DBConfig()
        db = dbconfig.get_db()
        
        table = db.get_data_centers()
        s = table.select(table.c.id == oid)
        result = s.execute()

        for res in result:
            self.data_center.id = res.id
            self.data_center.name = res.name
            self.data_center.region_id = res.region_id
            self.data_center.data_center_uri = res.data_center_uri
            
        return self.data_center
Esempio n. 27
0
    def load(self,oid):
        dbconfig = DBConfig()
        db = dbconfig.get_db()
        
        table = db.get_containers()
        s = table.select(table.c.id == oid)
        result = s.execute()

        for res in result:
            self.container.id = res.id
            self.container.host_id = res.host_id
            self.container.cpu = res.cpu
            self.container.memory = res.memory
            self.container.disk_size = res.disk_size
            self.container.request_id = res.request_id
            self.container.service_uri = res.service_uri
            self.container.container_uri = res.container_uri
            
        return self.container
Esempio n. 28
0
    def load(self, oid):
        dbconfig = DBConfig()
        db = dbconfig.get_db()

        table = db.get_containers()
        s = table.select(table.c.id == oid)
        result = s.execute()

        for res in result:
            self.container.id = res.id
            self.container.host_id = res.host_id
            self.container.cpu = res.cpu
            self.container.memory = res.memory
            self.container.disk_size = res.disk_size
            self.container.request_id = res.request_id
            self.container.service_uri = res.service_uri
            self.container.container_uri = res.container_uri

        return self.container
Esempio n. 29
0
    def load_using_request(self, r):
        dbconfig = DBConfig()
        db = dbconfig.get_db()

        table = db.get_host_domain()

        expr = ((table.c.cpu >= (r.cpu * r.op_factor)) |
                ((table.c.host_id != None) & (table.c.cpu >= r.cpu)))
        expr = expr & ((table.c.memory >= (r.memory * r.op_factor)) |
                       ((table.c.host_id != None) &
                        (table.c.memory >= r.memory)))
        expr = expr & ((table.c.disk_size >= (r.disk_size * r.op_factor)) |
                       ((table.c.host_id != None) &
                        (table.c.disk_size >= r.disk_size)))

        if (r.host_type_id > 0):
            expr = expr & (table.c.host_type_id == r.host_type_id)

        if (r.region_id > 0):
            expr = expr & (table.c.region_id == r.region_id)

        if (r.disk_type_id > 0):
            expr = expr & (table.c.disk_type_id == r.disk_type_id)

        if (r.price_limit > 0):
            expr = expr & ((table.c.cost <= r.price_limit))

        if (r.private > 0):
            expr = expr & (table.c.private == r.private)

        if (r.optimized > 0):
            expr = expr & (table.c.optimized == r.optimized)

        s = table.select(expr)
        result = s.execute()

        return result
Esempio n. 30
0
 def save(self):
     dbconfig = DBConfig()
     db = dbconfig.get_db()
     
     table = db.get_requests()
     session = db.get_session()
     
     
     qry = session.query(func.max(table.c.id).label("max_id"))
     res = qry.one()
     oid = res.max_id
     
     print "oid: ", oid
     
     if oid > -1:
         oid = oid + 1
     else:
         oid = 1
     
     i = table.insert()
     i.execute(id=oid,
               host_type_id=self.request.host_type_id,
               region_id=self.request.region_id,
               cpu=self.request.cpu,
               memory=self.request.memory,
               disk_size=self.request.disk_size,
               disk_type_id=self.request.disk_type_id,
               ha_scale=self.request.ha_scale,
               dr_scale=self.request.dr_scale,
               op_factor=self.request.op_factor,
               price_limit=self.request.price_limit,
               private=self.request.private,
               optimized=self.request.optimized,
               image=self.request.image)
     
     return oid