Esempio n. 1
0
def scale_up(username, project_name, service_name):
    service_scale, service_dict = database_update.get_service_scale_config(username, project_name, service_name)
    database_update.set_service_scale(username, project_name, service_name, int(service_scale)+1)

    true = True
    false = False
    service_dict = eval(service_dict)

    ip = schedule.random_schedule()
    client = Client(ip, config.c_version)


    container_name = service_name + "_" + str(service_scale)

    database_update.create_container(username, project_name, service_name, container_name, ip)
    
    service_dict['container_name'] = container_name + config.split_mark + project_name + config.split_mark + username
    service_dict['hostname'] = container_name + config.split_mark + project_name + config.split_mark + username
    cont = Container(client=client, options=service_dict, volume=None, network=Network(service_dict['network']))
    cont.create()
    cont.start()
Esempio n. 2
0
def delete_network(username, network):
    client = Client("114.212.189.147:2376", config.c_version).client
    Network.remove_network(client, network)
    database_update.delete_network(username, network)
Esempio n. 3
0
def create_network(username, network):
    client = Client("114.212.189.147:2376", config.c_version).client
    Network.create_network(client, network, 'overlay')
    database_update.create_network(username, network)
Esempio n. 4
0
    def from_dict(cls, username, name, service_dicts):
        project = cls(name, [])

        # for srv_dict in service_dicts:
        # if 'container_name' not in srv_dict:
        #     srv_dict['container_name'] = srv_dict['name']
        # srv_dict['hostname'] = srv_dict['container_name'] + config.split_mark + name + config.split_mark + username

        for srv_dict in service_dicts:
            if 'command' in srv_dict:
                command = srv_dict['command']
                if "{{" in command:
                    for s_dict in service_dicts:
                        before = s_dict['name']
                        after = before + config.split_mark + name + config.split_mark + username
                        before = "{{" + before + "}}"
                        command = command.replace(before, after)
                srv_dict['command'] = command

        for service_dict in sort_service_dicts(service_dicts):
            log.info('from_dicts service_dict: %s', service_dict)

            # container_name = service_dict['container_name']
            # service_dict['name'] = service_dict['name'] + config.split_mark + name + config.split_mark + username
            # service_dict['container_name'] = service_dict['container_name'] + config.split_mark + name + config.split_mark + username

            # if 'ports' in service_dict:
            #     service_dict['ports'].append('4200')
            # else:
            #     ports = ['4200']
            #     service_dict['ports'] = ports

            log.info(service_dict)

            print service_dict

            client_list = database_update.get_machines()

            vv = None
            if 'volumes' in service_dict:
                vv = Volume(service_dict['volumes'])

            # if 'host' in service_dict:
            #     if service_dict['host'] == 'all':
            #         no = 0
            #         for client in client_list:
            #             cc = Client(client, config.c_version)
            #             project.services.append(
            #                 Service(
            #                     name=service_dict['name'],
            #                     client=cc,
            #                     project=name,
            #                     username=username,
            #                     network=Network(service_dict['network']),
            #                     volume=vv,
            #                     options=service_dict
            #                 )
            #             )
            #             database_update.create_service(username, name, service_dict['name'], service_dict, service_dict['scale'])
            #             no += 1
            #         return project
            #     else:
            #         ip = service_dict['host']
            # else:
            #     # orchestration algorithm
            #     # index = random.randint(0, 1)
            #     print 'no schedule'

            if 'port' in service_dict:
                write_to_ct(service_dict['port'], service_dict['name'], name,
                            username)
                env = []
                if 'environment' in service_dict:
                    env = service_dict['environment']
                env.append('SERVICE_NAME=' + service_dict['name'] + '-' +
                           name + "-" + username)
                service_dict['environment'] = env

            if 'scale' not in service_dict:
                service_dict['scale'] = 1

            database_update.create_service(username, name,
                                           service_dict['name'], service_dict,
                                           service_dict['scale'])

            project.services.append(
                Service(name=service_dict['name'],
                        project=name,
                        username=username,
                        network=Network(service_dict['network']),
                        volume=vv,
                        options=service_dict))

        return project