예제 #1
0
def scale(name,uuid,templateid,env,cpushare,memory,scaleconstant):
    uuids=[uuid]
    
    imageprofile = getImageProfile(templateid)
    for num in range(1,scaleconstant):
        uuid=install_container(name+'-ins'+str(num),templateid,env,cpushare,memory,False,False)
        uuids.append(uuid)
    port = imageprofile['port']
    if( port) :    
        addip(name,uuids)
예제 #2
0
def install_container(name,
                      templateid,
                      env,
                      cpushare,
                      memory,
                      portmap=False,
                      setnginx=True):
    imageprofile = getImageProfile(templateid)
    nodes = get_node_to_deploy()
    nodeindex = get_node_pack(nodes, memory, 1)
    port = imageprofile['port']
    if (port):
        portmap = True
    if (not env):
        env = {
            'constraint:node=': nodes[nodeindex]['Name']
        }
    else:
        env['constraint:node='] = nodes[nodeindex]['Name']
    env['TERM'] = 'xterm'
    if (imageprofile['updatemysql']):
        extrahosts = {'mysql': config.get("DOCKER_CONF", "mysql_machine")}
    else:
        extrahosts = None
    hostconfig = client.create_host_config(
        publish_all_ports=portmap,
        mem_limit=memory,
        cap_drop=imageprofile['permissiondrop'],
        cap_add=imageprofile['permissionadd'],
        links=imageprofile['links'],
        extra_hosts=extrahosts)
    try:
        containerid = client.create_container(name=name,
                                              image=imageprofile['Id'],
                                              command=imageprofile['cmd'],
                                              environment=env,
                                              detach=True,
                                              cpu_shares=cpushare,
                                              host_config=hostconfig)
    except docker.errors as e:
        print(e)
        return
    # Update the db -- container in created state.....
    try:
        response = client.start(container=containerid['Id'])
        # @UnusedVariable
        # Update the db -- container in running state
    except docker.errors as e:
        print(e)
    if (port and setnginx):
        container = Container(containerid)
        container.addipbyconf()
    return containerid
예제 #3
0
def install_container(name,templateid,mount_hostvolumes,env,cpushare,memory,portmap=True):
    imageprofile = getImageProfile(templateid)
    nodes = get_node_to_deploy();
    nodeindex = get_node_pack(nodes,memory,1);
    if(not env):
		env = {'constraint:node=':nodes[nodeindex]['Name']};
    else:
		env['constraint:node='] =nodes[nodeindex]['Name'];
    if(imageprofile['updatemysql'] ):
		extrahosts = {'mysql':config.get("DOCKER_CONF","mysql_machine")}
    else :
               extrahosts = None;
    if  (imageprofile['mountdestdir']):
        bindconfig1 ={}
        bindconfig1['bind'] = imageprofile['mountdestdir'];
        bindconfig1['mode'] ='rw' ;
        binds = {}
        binds[mount_hostvolumes] = bindconfig1;
        
        hostconfig = client.create_host_config(binds = binds,publish_all_ports = portmap,mem_limit = memory,links  = imageprofile['links'],cap_drop=imageprofile['permissiondrop'],cap_add=imageprofile['permissionadd'],extra_hosts=extrahosts);
        print(hostconfig);
        try: 
            containerid = client.create_container(name=name ,image = imageprofile['Id'] , command = imageprofile['cmd'] ,
                                 volumes = [imageprofile['mountdestdir']] , environment = env , detach = True ,cpu_shares=cpushare,
                                 host_config = hostconfig );
            print (containerid );
        except docker.errors as e:
            print (e);
    else :
        hostconfig = client.create_host_config(publish_all_ports = portmap,mem_limit = memory,cap_drop=imageprofile['permissiondrop'],cap_add=imageprofile['permissionadd'],links  = imageprofile['links'],extra_hosts=extrahosts);
        try: 
            containerid = client.create_container(name=name,image = imageprofile['Id'] , command = imageprofile['cmd'],
                                  environment = env , detach = True ,cpu_shares=cpushare,
                                 host_config = hostconfig );
            print (containerid );
        except docker.errors as e:
            print (e);        
    # Update the db -- container in created state.....
    print ('db update');
    try:                     
        response = client.start(container = containerid['Id']);
        print (response) ;
        # Update the db -- container in running state
    except docker.errors as e:
        print(e);
    
    port = imageprofile['port'];
    if( port) :
          container = Container(containerid);    
          container.addipbyconf();    
    return containerid;
예제 #4
0
def container_install_task(req_data, params):
    
    
    env_vars = req_data.env_vars
    image_id = int(env_vars.pop('image_profile'))
    image_profile = getImageProfile(image_id)['type']
#     env_vars['image_profile'] = None
    cont_id = db.container_data.insert(
                  name = req_data.vm_name,
                  RAM = req_data.RAM,
                  vCPU = req_data.vCPU,
                  env_vars = env_vars,
                  image_id = image_id,
                  image_profile = image_profile,
                  restart_policy = req_data.restart_policy,
                  requester_id = req_data.requester_id,
                  owner_id = req_data.owner_id,
                  purpose = req_data.purpose,
                  status = VM_STATUS_IN_QUEUE)

    add_container_users(cont_id, req_data.requester_id, req_data.owner_id, req_data.collaborators)
    add_cont_task_to_queue(cont_id, CONTAINER_TASK_CREATE, params=params, requested_by=req_data.requester_id)
예제 #5
0
def container_install_task(req_data, params):
    
    
    env_vars = req_data.env_vars
    image_id = int(env_vars.pop('image_profile'))
    image_profile = getImageProfile(image_id)['type']
#     env_vars['image_profile'] = None
    cont_id = db.container_data.insert(
                  name = req_data.vm_name,
                  RAM = req_data.RAM,
                  vCPU = req_data.vCPU,
                  env_vars = env_vars,
                  image_id = image_id,
                  image_profile = image_profile,
                  restart_policy = req_data.restart_policy,
                  requester_id = req_data.requester_id,
                  owner_id = req_data.owner_id,
                  purpose = req_data.purpose,
                  status = VM_STATUS_IN_QUEUE)

    add_container_users(cont_id, req_data.requester_id, req_data.owner_id, req_data.collaborators)
    add_cont_task_to_queue(cont_id, CONTAINER_TASK_CREATE, params=params, requested_by=req_data.requester_id)
예제 #6
0
def install_container(name,templateid,env,cpushare,memory,portmap=False,setnginx=True,restart_policy='no'):
    imageprofile = getImageProfile(templateid)
    nodes = get_node_to_deploy()
    nodeindex = get_node_pack(nodes,memory,1)
    port = imageprofile['port']
    if (port):
        portmap = True 
    if(not env):
        env = {'constraint:node=':nodes[nodeindex]['Name']}
    else:
        env['constraint:node='] =nodes[nodeindex]['Name']
    env['TERM'] = 'xterm'
    if(imageprofile['updatemysql'] ):
        extrahosts = {'mysql':config.get("DOCKER_CONF","mysql_machine_ip")}
    else :
        extrahosts = None
    ulimits=[]
    import docker.utils
    ulimits.append(docker.utils.Ulimit(Name='NPROC',Soft=500,Hard=1000))
    ulimits.append(docker.utils.Ulimit(Name='NOFILE',Soft=4000,Hard=8000))
    hostconfig = client.create_host_config(publish_all_ports = portmap,mem_limit = memory,cap_drop=imageprofile['permissiondrop'],cap_add=imageprofile['permissionadd'],links  = imageprofile['links'],extra_hosts=extrahosts,restart_policy={'Name':restart_policy,'MaximumRetryCount':5},ulimits=ulimits)
    try: 
        containerid = client.create_container(name=name,image = imageprofile['Id'] , command = imageprofile['cmd'],
                              environment = env , detach = True ,cpu_shares=cpushare,
                             host_config = hostconfig )
    except docker.errors as e:
        print (e) 
        return       
    # Update the db -- container in created state.....
    try:                     
        response = client.start(container = containerid['Id'])  # @UnusedVariable
        # Update the db -- container in running state
    except Exception as e:
        logger.debug(e)
    if( port and setnginx) :
        container = Container(containerid)    
        container.addipbyconf()    
    return containerid