Esempio n. 1
0
def get_service_placements(vm_ips):
    service_to_deployment = {}
    for vm_ip in vm_ips:
        ssh_client = remote_exec.get_client(vm_ip)
        docker_container_id_cmd = 'docker ps | tr -s \' \' | cut -d \' \' -f1 | tail -n +2'
        docker_container_image_cmd = 'docker ps | tr -s \' \' | cut -d \' \' -f2 | tail -n +2'
        _, stdout1, _ = ssh_client.exec_command(docker_container_id_cmd)
        container_ids = stdout1.read().splitlines()
        _, stdout2, _ = ssh_client.exec_command(docker_container_image_cmd)
        service_names = stdout2.read().splitlines()

        zipped_name_id = zip(service_names, container_ids)

        #Assume that the container ids and the service names are ordered in the same way
        for service_name, container_id in zipped_name_id:
            if service_name[-4:] == '.git':
                service_name = service_name[service_name.index('/') + 1:]
            identifier_tuple = (vm_ip, container_id)
            if service_name == 'postgres:9.4':
                service_name = 'library/postgres:9.4'
            if service_name == 'osalpekar/spark-image-compressor':
                service_name = 'osalpekar/spark-image-compress...'
            if service_name not in service_to_deployment:
                service_to_deployment[service_name] = [identifier_tuple]
            else:
                service_to_deployment[service_name].append(identifier_tuple)
        remote_exec.close_client(ssh_client)
    return service_to_deployment
Esempio n. 2
0
def get_vm_to_service(vm_ips, orchestrator='quilt'):
    if orchestrator == 'quilt':
        vm_to_service = {}
        for vm_ip in vm_ips:
            ssh_client = remote_exec.get_client(vm_ip)
            docker_container_id_cmd = 'docker ps | tr -s \' \' | cut -d \' \' -f1 | tail -n +2'
            docker_container_image_cmd = 'docker ps | tr -s \' \' | cut -d \' \' -f2 | tail -n +2'
            _, stdout1, _ = ssh_client.exec_command(docker_container_image_cmd)
            service_names = stdout1.read().splitlines()

            #Assume that the container ids and the service names are ordered in the same way
            for service in service_names:
                if service == 'osalpekar/spark-image-compressor':
                    service = 'osalpekar/spark-image-compress...'
                if service == 'postgres:9.4':
                    service = 'library/postgres:9.4'
                if service in quilt_blacklist or service in service_blacklist:
                    continue
                if vm_ip in vm_to_service:
                    vm_to_service[vm_ip].append(service)
                else:
                    vm_to_service[vm_ip] = [service]
            remote_exec.close_client(ssh_client)
        return vm_to_service

    endpoint_list = v1.list_namespaced_endpoints("default").items
    vm_ip_numbers = vm_ips
    vm_to_service = {}
    port_to_service = {}

    # For every service port, map that port to service_name 
    all_services = v1.list_service_for_all_namespaces().items
    for service in all_services:
        service_name = service.metadata.name
        if service_name == 'osalpekar/spark-image-compressor':
            service_name = 'osalpekar/spark-image-compress...'
        if service_name in quilt_blacklist or service_name in service_blacklist:
            continue
        for port_info in service.spec.ports:
            port_to_service[port_info.port] = service_name

    #For every endpoint (exposed pod), look up to see if its ports are shared with a service
    for endpoint in endpoint_list:
        for subset in endpoint.subsets:
            for address in subset.addresses:
                index = -1
                if address.ip in vm_ip_numbers:
                    index = vm_ip_numbers.index(address.ip)
                if index != -1:
                    for port_info in subset.ports:
                        port_number = port_info.port
                        if port_number not in port_to_service:
                            continue
                        if vm_ip_numbers[index] not in vm_to_service:
                            vm_to_service[vm_ip_numbers[index]] = [port_to_service[port_number]]
                        else:
                            vm_to_service[vm_ip_numbers[index]].append(port_to_service[port_number])

    return vm_to_service
Esempio n. 3
0
def get_vm_to_service(vm_ips):
    vm_to_service = {}
    for vm_ip in vm_ips:
        ssh_client = remote_exec.get_client(vm_ip)
        docker_container_id_cmd = 'docker ps | tr -s \' \' | cut -d \' \' -f1 | tail -n +2'
        docker_container_image_cmd = 'docker ps | tr -s \' \' | cut -d \' \' -f2 | tail -n +2'
        _, stdout1, _ = ssh_client.exec_command(docker_container_image_cmd)
        service_names = stdout1.read().splitlines()

        #Assume that the container ids and the service names are ordered in the same way
        for service in service_names:
            if service in quilt_blacklist:
                continue
            if vm_ip in vm_to_service:
                vm_to_service[vm_ip].append(service)
            else:
                vm_to_service[vm_ip] = [service]
        remote_exec.close_client(ssh_client)
    return vm_to_service
Esempio n. 4
0
def get_service_placements(vm_ips, orchestrator='quilt'):
    if orchestrator == 'quilt':
        service_to_deployment = {}
        for vm_ip in vm_ips:
            ssh_client = remote_exec.get_client(vm_ip)
            docker_container_id_cmd = 'docker ps | tr -s \' \' | cut -d \' \' -f1 | tail -n +2'
            docker_container_image_cmd = 'docker ps | tr -s \' \' | cut -d \' \' -f2 | tail -n +2'
            _, stdout1, _ = ssh_client.exec_command(docker_container_id_cmd)
            container_ids = stdout1.read().splitlines()
            _, stdout2, _ = ssh_client.exec_command(docker_container_image_cmd)
            service_names = stdout2.read().splitlines()

            zipped_name_id = zip(service_names, container_ids)

            #Assume that the container ids and the service names are ordered in the same way
            for service_name, container_id in zipped_name_id:
                if service_name in service_blacklist or service_name in quilt_blacklist:
                    continue
                if service_name[-4:] == '.git':
                    service_name = service_name[service_name.index('/')+1:]
                identifier_tuple = (vm_ip, container_id)
                if service_name == 'postgres:9.4':
                    service_name = 'library/postgres:9.4'
                if service_name == 'osalpekar/spark-image-compressor':
                    service_name = 'osalpekar/spark-image-compress...'
                if service_name not in service_to_deployment:
                    service_to_deployment[service_name] = [identifier_tuple]
                else:
                    service_to_deployment[service_name].append(identifier_tuple)
            remote_exec.close_client(ssh_client)
        return service_to_deployment

    # Else using Kubernetes
    pods = v1.list_namespaced_pod("default").items
    
    port_to_pod = {}
    vm_ip_numbers = vm_ips

    for pod in pods:
        index = -1
        if pod.status.pod_ip in vm_ip_numbers:
            index = vm_ip_numbers.index(pod.status.pod_ip)
        if index != -1:
            for container in pod.spec.containers:
                if container.ports:
                    for port_info in container.ports:
                        port_to_pod[port_info.container_port] = [vm_ips[index], container.name]

    service_to_vm = {}

    # For every service port, check if a service shares a port with any vms

    all_services = v1.list_service_for_all_namespaces().items
    for service in all_services:
        service_name = service.metadata.name
        if service_name[-4:] == '.git':
            service_name = service_name[service_name.index('/') + 1:]
        if service_name == 'postgres:9.4':
            service_name = 'library/postgres:9.4'
        if service_name == 'osalpekar/spark-image-compressor':
            service_name = 'osalpekar/spark-image-compress...'
        for port_info in service.spec.ports:
            if port_info.port not in port_to_pod:
                continue
            if service_name not in service_to_vm:
                service_to_vm[service_name] = [port_to_pod[port_info.port]]
            else:
                service_to_vm[service_name].append(port_to_pod[port_info.port])

    return service_to_vm