def __init__(self, secondary_data, tertiary_data, pkey_path='/root/.ssh/id_rsa'):
        try:
            self.secondary_ssh = paramiko.SSHClient()
            privkey = paramiko.RSAKey.from_private_key_file(pkey_path)
            self.secondary_ssh.set_missing_host_key_policy(
                paramiko.AutoAddPolicy())
            self.secondary_ssh.connect(
                secondary_data['ip'], username=secondary_data['username'], pkey=privkey)

            self.tertiary_ssh = paramiko.SSHClient()
            privkey = paramiko.RSAKey.from_private_key_file(pkey_path)
            self.tertiary_ssh.set_missing_host_key_policy(
                paramiko.AutoAddPolicy())
            self.tertiary_ssh.connect(
                tertiary_data['ip'], username=tertiary_data['username'], pkey=privkey)

            self.primary_conn = libvirt.open('qemu:///system')
            self.secondary_con = libvirt.open(
                'qemu+ssh://{}@{}/system'.format(secondary_data['username'], secondary_data['ip']))
            self.tertiary_con = libvirt.open(
                'qemu+ssh://{}@{}/system'.format(tertiary_data['username'], tertiary_data['ip']))

            self.primary_docker = client.APIClient(
                base_url='unix://var/run/docker.sock')
            self.secondary_docker = client.APIClient(
                base_url="tcp://{}:2375".format(secondary_data['ip']))
            self.tertiary_docker = client.APIClient(
                base_url="tcp://{}:2375".format(tertiary_data['ip']))
        except Exception as e:
            print("Error while initiating connection to remote hypervisor: ", e)
            raise
 def _get_pod_info(self):
     '''
     Get UUID for POD using "docker inspect" equivalent API
     '''
     from docker import client
     os.environ['DOCKER_API_VERSION'] = '1.22'
     try:
         docker_client = client.APIClient()
         if docker_client == None:
             raise Error(K8S_PARAMS_ERR_DOCKER_CONNECTION,
                         'Error creating docker client')
         container = docker_client.inspect_container(self.cni.container_id)
         self.pod_uuid = container['Config']['Labels']\
             ['io.kubernetes.pod.uid']
     except:
         # Dont report exception if pod_uuid set from argument already
         # pod-uuid will be specified in argument in case of UT
         if self.pod_uuid == None:
             raise Error(
                 K8S_PARAMS_ERR_GET_UUID,
                 'Error finding UUID for pod ' + self.cni.container_id)
     return
Example #3
0
 def _getDockerClient(self):
     if docker.version[0] == '1':
         docker_client = client.Client(**self.client_args)
     else:
         docker_client = client.APIClient(**self.client_args)
     return docker_client