コード例 #1
0
ファイル: getinstances.py プロジェクト: d-wack/lume-re
def getInstances(db_controller, deviceId='', deviceDatasourceId=''):
    print("Getting Instances")
    lm_fields = '?fields=id,deviceDataSourceId'
    deviceDataSources = db_controller.get_deviceDataSources(
    )  # Queries DB for deviceId and deviceDataSourceId
    instance_list = []
    for deviceDatasource in deviceDataSources:
        deviceId = str(deviceDatasource[1])
        deviceDatasourceId = str(deviceDatasource[0])
        lm_resourcePath = f'/device/devices/{deviceId}/devicedatasources/{deviceDatasourceId}/instances'
        data = lm_request(lm_resourcePath=lm_resourcePath, lm_fields=lm_fields)
        items = data['items']
        for item in items:
            instance = Instance()
            instance.instance_id = item['id']
            instance.device_datasource_id = item['deviceDataSourceId']
            if not db_controller.check_if_row_exists(row=instance):
                instance_list.append(instance)
    if len(instance_list) > 0:
        db_controller.add_many(data=instance_list)
    else:  # If instance_list = 0, that means there are no new instances
        db_controller.update_log(name="GetInstances",
                                 log_type="Info",
                                 code="300",
                                 desc="No New Instances Found")
        db_controller.session.commit()
コード例 #2
0
ファイル: Controller.py プロジェクト: Number1Tsar/Aggiestack
 def migrate_rack(rack):
     servers = dao.get_all_servers([rack])
     racks = dao.get_valid_racks()
     racks.remove(rack)
     instances_migrated = []
     servers_to_deactivate = []
     for server in servers:
         servers_to_deactivate.append(server)
         instances = dao.get_all_instances([server["Name"]])
         for instance in instances:
             flavor = instance["Flavor"]
             new_server = Controller.best_fit(flavor, racks)
             if new_server is not None:
                 instances_migrated.append(instance)
                 dao.delete_instance(instance["Name"])
                 new_instance = Instance(instance["Name"], instance["Flavor"], instance["Image"], new_server["Name"])
                 dao.create_instance(new_instance)
             else:
                 for ins in instances_migrated:
                     dao.delete_instance(ins["Name"])
                 for ins in instances_migrated:
                     roll_back_instance = Instance(ins["Name"], ins["Flavor"], ins["Image"], ins["Server"])
                     dao.create_instance(roll_back_instance)
                 raise Exception(exp.MIGRATION_NOT_POSSIBLE.format(instance["Name"]))
     for server in servers_to_deactivate:
         dao.deactivate_server(server["Name"])
コード例 #3
0
 def __init__(self, player):
     pygame.sprite.Sprite.__init__(self)
     Instance.__init__(self, field_hearts)
     self.image = pygame.Surface((200, 200))
     pygame.draw.circle(self.image, BLUE, (self.image.get_rect().x + self.image.get_width() // 2,
                                           self.image.get_rect().y + self.image.get_height() // 2), 100)
     self.rect = self.image.get_rect()
     self.image.set_alpha(60)
     self.player = player
     self.time = 0
コード例 #4
0
ファイル: Boss.py プロジェクト: ghostnoop/starship_python
    def update(self):

        Instance.update(self)

        if self.rect.x > WIDTH - self.image.get_width():
            self.rect.x -= 3

        if self.rect.y >= HEIGHT - self.image.get_height():
            self.up = True
        if self.rect.y <= 0:
            self.up = False

        if self.up:
            self.rect.y -= self.speed
        else:
            self.rect.y += self.speed
コード例 #5
0
 def object_hook(self, dct):
     if 'task_id' in dct:
         return Task(dct['task_id'], dct['m'], dct['s'],
                     dct['out_line_cost'], set(dct['predecessor_set']))
     elif 'instance_id' in dct:
         return Instance(dct['instance_id'],
                         {task.task_id: task
                          for task in dct['task_list']}, dct['q'], dct['c'])
     else:
         super().object_hook(self, dct)
コード例 #6
0
ファイル: Controller.py プロジェクト: Number1Tsar/Aggiestack
 def remove_server(server):
     instances = dao.get_all_instances([server])
     dao.deactivate_server(server)
     instances_migrated = []
     for instance in instances:
         flavor = instance["Flavor"]
         new_server = Controller.best_fit(flavor)
         if new_server is not None:
             instances_migrated.append(instance)
             dao.delete_instance(instance["Name"])
             new_instance = Instance(instance["Name"], instance["Flavor"], instance["Image"], new_server["Name"])
             dao.create_instance(new_instance)
         else:
             dao.reactivate_server(server)
             for ins in instances_migrated:
                 dao.delete_instance(ins["Name"])
             for ins in instances_migrated:
                 roll_back_instance = Instance(ins["Name"], ins["Flavor"], ins["Image"], ins["Server"])
                 dao.create_instance(roll_back_instance)
             raise Exception(exp.MIGRATION_NOT_POSSIBLE.format(instance["Name"]))
     dao.delete_server(server)
コード例 #7
0
ファイル: Controller.py プロジェクト: Number1Tsar/Aggiestack
 def create_instance_with_cache(name, flavor, image):
     rack_with_image_cached = dao.search_lookup(image)
     if rack_with_image_cached:
         server = Controller.best_fit(flavor, rack_with_image_cached)
         if server is not None:
             instance = Instance(name, flavor, image, server["Name"])
             dao.create_instance(instance)
         else:
             racks = dao.get_valid_racks()
             new_racks = [n for n in racks if n not in rack_with_image_cached]
             server = Controller.best_fit(flavor, new_racks)
             if server is not None:
                 instance = Instance(name, flavor, image, server["Name"])
                 dao.create_instance(instance)
             else:
                 raise Exception(exp.COMPATIBLE_MACHINE_UNAVAILABLE.format(name))
     else:
         server = Controller.best_fit(flavor)
         if server is not None:
             instance = Instance(name, flavor, image, server["Name"])
             dao.create_instance(instance)
         else:
             raise Exception(exp.COMPATIBLE_MACHINE_UNAVAILABLE.format(name))