Ejemplo n.º 1
0
        else:
            #print '######## successfully stopped docker container %s ' % container_id
            pass
        delete_url = ''.join(('http://', DOCKER_REMOTE_HOST, '/containers/', container_id))
        r = requests.delete(delete_url, verify=False)
        if r.status_code != 204:
            print '######## FAILED TO DELETE url: %s status: %s text: %s' %(delete_url, r.status_code, r.text)
            pass
        else:
            #print '######## successfully deleted docker container %s ' % container_id
            pass
        if not stop_all: # Just stop one instance
            break

if __name__ == '__main__':
    GROUP_STORE=FileGroupStore(False)
    print "instance_manager started."
    while True:
        for group in GROUP_STORE.list_groups():
            desired_instances = int(group["NumberInstances"]["Desired"]) 
            instances = get_group_instances(group)
            if instances is not None:
                current_instances = len(instances)
                if desired_instances > current_instances:
                    for i in xrange(desired_instances - current_instances):
                        create_instance(group)
                elif desired_instances < current_instances:
                    for i in xrange(current_instances - desired_instances):
                        delete_instances(group, False)
        time.sleep(10)