Beispiel #1
0
def remove_image(image_id):
    global server_pointer
    ip = available_nodes[server_pointer].get_ip()
    #if the choosen node is not local, send a request to the chosen node to remove an instance with the image_id
    if ip != "localhost":
        url = 'http://' + ip + ':5001' + '/remove_image'
        form_data = {'image_id' : image_id}
        params = urllib.urlencode(form_data)
        response = urllib2.urlopen(url, params)
        result = json.load(response)
    else:
        #if the chosen node is the local node, remove an instance with with the image_id straight from docker
        removables = docker.get_instance_ids_by_id(image_id)
        for index, removable in enumerate(removables):
            removed = [docker.rm('-f', removables[index])]
        #update main load balancer to remove the container from the chosen instance
        lb_port = _add_load_balancer(image_id, None)
        update_main_load_balancer(image_id, "127.0.0.1", str(lb_port))
    #update the server pointer to the previous server. If it goes down to zero, set it to the last one on the list.
    for removable in removables:
        _remove_container_from_record(image_id, removable)
    server_pointer -= 1
    if server_pointer == 0:
        server_pointer = len(available_nodes) - 1

    success_containers = docker.rmi(image_id)
    success_load_balancer = docker.rmi(haproxy_prefix + image_id)
    success_volume = docker.remove_volume(image_id)
    success_network = docker.remove_network(image_id)
    merger.remove_app_data(image_id)
    success = success_containers and success_load_balancer and success_volume and success_network    
    return str(success) + '\n', 200
Beispiel #2
0
def remove_instance_from_cluster(image_id):
    global server_pointer
    ip = available_nodes[server_pointer].get_ip()
    #if the choosen node is not local, send a request to the chosen node to remove an instance with the image_id
    if ip != "localhost":
        url = 'http://' + ip + ':5001' + '/remove'
        form_data = {'image_id' : image_id}
        params = urllib.urlencode(form_data)
        response = urllib2.urlopen(url, params)
        result = json.load(response)
        #update the main load balancer to remove the container from the chosen instance
        main_lb_ip = docker.get_ip_by_name(main_lb_image_label)
        removed = True
        lb_port = result['lb_port']
        container_id = result['container_id']        
        update_main_load_balancer(image_id, ip, str(lb_port))
    else:
        #if the chosen node is the local node, remove an instance with with the image_id straight from docker
        removables = docker.get_instance_ids_by_id(image_id)
        removed = docker.rm('-f', removables[-1])
        #update main load balancer to remove the container from the chosen instance
        lb_port = _add_load_balancer(image_id, port)
        update_main_load_balancer(image_id, "127.0.0.1", str(lb_port))
    #update the server pointer to the previous server. If it goes down to zero, set it to the last one on the list.
    _remove_container_from_record(image_id, container_id)
    server_pointer -= 1
    if server_pointer == 0:
        server_pointer = len(available_nodes) - 1
Beispiel #3
0
def remove():
    image_id = request.form['image_id']
    removables = docker.get_instances_ids_by_id(image_id)
    container_id = docker.rm('-f', removables[-1])
    if container_id:
        lb_port = update_load_balancer(image_id)
        return jsonify({'lb_port': lb_port, 'container_id': container_id})
    else:
        return "[ERROR] Container Could not be removed. Check your parameters"
Beispiel #4
0
def _remove_current_load_balancer(load_balancer_instance, image_id):
    docker.stop(load_balancer_instance)
    docker.rm(load_balancer_instance)
    docker.rmi(haproxy_prefix + image_id)
Beispiel #5
0
def remove_instance(container_id):
    docker.stop(container_id)
    success = docker.rm(container_id)
    return str(success) + '\n', 200