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)
Example #2
0

"""
Problems and Incompatibilities

1. When should get_container_state return "Suspended"
2. note incompatible IPAddress -> IpAddress
3. note Name field has no leading '/' character as in docker

Extensions to current CCSAPI: Talk to Dave ???

GET   /{version}/containers/new (launch wizard screen for containers and groups)
"""

APP_NAME=os.environ['APP_NAME'] if 'APP_NAME' in os.environ else 'ccs'
GROUP_STORE=FileGroupStore(False)
BINDING_STORE=FileBindingStore(False)
# Only reset the GROUP_STORE if we determine it is out of sync with the current docker instances
for group in GROUP_STORE.list_groups():
    if len(get_group_instances(group)) < group.get("NumberInstances", {}).get("Min", 0):
        GROUP_STORE.reset()
        break

HTML_TEMPLATE=\
'''
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>IBM CCS Emulator</title>
</head>