Esempio n. 1
0
    def before_each(self):
        self.paramiko_stub = create_paramiko_client_stub(command_stdout_rtn=[
            'total 132', 'drwxr-xr-x   2 root root  4096 Sep  2 13:36 bin'
        ])
        self.ssh_credentials = create_key_creds()

        self.ssh_client = SSHClient(client=self.paramiko_stub,
                                    host='bam',
                                    port=21,
                                    credentials=self.ssh_credentials)
Esempio n. 2
0
    def on_get(self, req, resp, tenant_id, target_id):
        target = Target.get_target(tenant_id, target_id)
        if target:
            address = target.address
            # Nova
            if 'nova' in address.as_dict().keys():
                nova_address = address.address_child

                auth = target.authentication
                try:
                    if 'rackspace' in auth:
                        cls = get_driver(Provider.RACKSPACE)
                        cls(auth['rackspace']['username'],
                            auth['rackspace']['api_key'],
                            region=nova_address.region.lower())
                        resp.status = falcon.HTTP_200
                    else:
                        raise Exception(
                            "No supported providers in target: {0}".format(
                                target.as_dict()))
                except Exception:
                    resp.status = falcon.HTTP_404
            # SSH
            else:
                ip = address.address_child
                ssh = target.authentication.get('ssh')

                creds = SSHKeyCredentials(username=ssh.get('username'),
                                          key_contents=ssh.get('private_key'))
                client = SSHClient(host=ip.address,
                                   port=ip.port,
                                   credentials=creds)
                try:
                    client.connect()
                    resp.status = falcon.HTTP_200
                    client.close()
                except SSHException:
                    resp.status = falcon.HTTP_404
        else:
            msg = 'Cannot find target: {target_id}'.format(target_id=target_id)
            resp.status = falcon.HTTP_404
            resp.body = json.dumps({'description': msg})
Esempio n. 3
0
 def unassigned_client_auto_creates_a_paramiko_client(self):
     inst = SSHClient(host='bam', port=21, credentials=self.ssh_credentials)
     expect(inst).not_to.be_none()
     expect(type(inst.client)).to.equal(paramiko.SSHClient)