1

I am using paramiko and create some virtualenvs over ssh like so:

from paramiko import SSHClient, SSHConfig

def ssh_connect(self):
    # ssh config file
    config = SSHConfig()
    config.parse(open(settings.SSH_CONFIG))
    o = config.lookup('my_key')

    # ssh client
    ssh_client = SSHClient()
    ssh_client.load_system_host_keys()
    ssh_client.connect(o['hostname'], username=o['user'])
    return ssh_client

def create_virtualenv(self):
    ssh = self.ssh_connect()
    venv_path = '/srv/virtualenvs/%s' % self.domain
    cmd = 'virtualenv %s' % env_path
    stdin = ssh.exec_command(cmd)
    self.create_database()
    ssh.close()

Now I ran into a bit of a wall here because I want to also install Django into this newly create virtualenv with pip. I tried a postmkvirtualenv hook because I do have virtualenvwrapper installed on that server but that does not seem to run when I create a new environment using the code above.

Can anyone give me any hints as to how I can install Django in this manner?

3
  • 1
    Is it for deployment automation? Have you considered tools like ansible? Puppet and Chef are also popular choices if you don't want to reinvent the wheel. Commented Aug 28, 2012 at 0:01
  • Not for automated deployment, we have an internal system for our employees and this would simply be for launching a new environment due to lack of access to that server, I just want to simply create the environment for them over ssh like above. Commented Aug 28, 2012 at 14:14
  • @JeffC That's exactly what Ansible does... Commented Feb 2, 2013 at 4:39

1 Answer 1

1

Did you try using the workon command? This command is part of virtualenvwrapper and allows you to activate a given virtualenv, you should be able to do something like this:

def create_virtualenv(self):
    ssh = self.ssh_connect()
    venv_path = '/srv/virtualenvs/%s' % self.domain
    cmd = 'workon %s; pip install Django' % env_path
    stdin = ssh.exec_command(cmd)
    self.create_database()
    ssh.close()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.