Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
Fixed Flake8 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tombh authored and mboersma committed Nov 5, 2013
1 parent 34c70c8 commit f69b0da
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
22 changes: 13 additions & 9 deletions client/deis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1757,25 +1757,30 @@ def providers_discover(self, args):
# Check for locally booted Deis Controller VM
try:
running_vms = subprocess.check_output(
['vboxmanage', 'list', 'runningvms'],
stderr=subprocess.PIPE)
['vboxmanage', 'list', 'runningvms'],
stderr=subprocess.PIPE
)
except subprocess.CalledProcessError:
running_vms = ""
# Vagrant internally names a running VM using the folder name in which the Vagrantfile resides, eg;
# my-deis-code-folder_default_1383326629
# Vagrant internally names a running VM using the folder name in which the Vagrantfile
# resides, eg; my-deis-code-folder_default_1383326629
deis_codebase_folder = self._session.git_root().split('/')[-1]
if deis_codebase_folder in running_vms:
print("Detected locally running Deis Controller VM")
# In order for the Controller to be able to boot Vagrant VMs it needs to run commands on the host machine.
# It does this via an SSH server. In order to access that server we need to send the current user's name
# and IP address.
# In order for the Controller to be able to boot Vagrant VMs it needs to run commands
# on the host machine. It does this via an SSH server. In order to access that server
# we need to send the current user's name and IP address.
try:
user = subprocess.check_output(
"whoami",
stderr=subprocess.PIPE
).strip()
ip = subprocess.check_output(
"/sbin/ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' | head -n1",
"/sbin/ifconfig | \
grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | \
grep -Eo '([0-9]*\.){3}[0-9]*' | \
grep -v '127.0.0.1' | \
head -n1",
stderr=subprocess.PIPE,
shell=True
).strip()
Expand All @@ -1798,7 +1803,6 @@ def providers_discover(self, args):
else:
print("No Vagrant VMs detected")


def providers_info(self, args):
"""
Print information about a specific provider
Expand Down
24 changes: 12 additions & 12 deletions provider/vagrant.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,31 +72,31 @@ def build_node(node):
node['params'].setdefault('memory', '512')
template = open('/opt/deis/controller/contrib/vagrant/nodes_vagrantfile_template.rb')
raw = string.Template(template.read())
result = raw.substitute({ 'id':uid, 'memory':node['params']['memory'] })
result = raw.substitute({'id': uid, 'memory': node['params']['memory']})

# Make a folder for the VM with its own Vagrantfile. Vagrant will then create a .vagrant folder
# there too when it first gets booted.
node_dir = HOST_NODES_DIR + '/' + uid
mkdir = 'mkdir ' + node_dir
cp_tpl = 'echo "' + result.replace('"', '\\"') + '" > ' + node_dir + '/Vagrantfile'
_host_ssh(commands = [mkdir, cp_tpl], creds = node['creds'])
_host_ssh(commands=[mkdir, cp_tpl], creds=node['creds'])

# Boot the VM
_run_vagrant_command(uid, args = ['up'], creds = node['creds'])
_run_vagrant_command(uid, args=['up'], creds=node['creds'])

# Copy the layer's public SSH key to the VM so that the Controller can access it.
_run_vagrant_command(
uid,
args = [
args=[
'ssh',
'-c',
'"echo \\"' + node['ssh_public_key'] + '\\" >> /home/vagrant/.ssh/authorized_keys"'
],
creds = node['creds'],
creds=node['creds'],
)

provider_id = uid
fqdn = provider_id + '.local' # hostname is broadcast via avahi-daemon
fqdn = provider_id + '.local' # hostname is broadcast via avahi-daemon
metadata = {
'id': uid,
'fqdn': fqdn,
Expand All @@ -114,11 +114,11 @@ def destroy_node(node):

# This is useful if node creation failed. So that there's a record in the DB, but it has no
# ID associated with it.
if node['provider_id'] == None:
if node['provider_id'] is None:
return

# Shut the VM down and destroy it
_run_vagrant_command(node['provider_id'], args = ['destroy', '--force'], creds = node['creds'])
_run_vagrant_command(node['provider_id'], args=['destroy', '--force'], creds=node['creds'])
node_dir = HOST_NODES_DIR + '/' + node['provider_id']

# Sanity check before `rm -rf`
Expand All @@ -128,21 +128,21 @@ def destroy_node(node):
# Completely remove the folder that contained the VM
rm_vagrantfile = 'rm ' + node_dir + '/Vagrantfile'
rm_node_dir = 'rm -rf ' + node_dir
_host_ssh(commands = [rm_vagrantfile, rm_node_dir], creds = node['creds'])
_host_ssh(commands=[rm_vagrantfile, rm_node_dir], creds=node['creds'])


def _run_vagrant_command(node_id, args = [], creds = {}):
def _run_vagrant_command(node_id, args=[], creds={}):
"""
args: A tuple of arguments to a vagrant command line.
e.g. ['up', 'my_vm_name', '--no-provision']
"""

cd = 'cd ' + HOST_NODES_DIR + '/' + node_id
command = ['vagrant'] + [arg for arg in args if arg is not None]
return _host_ssh(commands = [cd, ' '.join(command)], creds = creds)
return _host_ssh(commands=[cd, ' '.join(command)], creds=creds)


def _host_ssh(creds = {}, commands = []):
def _host_ssh(creds={}, commands=[]):
"""
Connect to the host machine. Namely the user's local machine.
"""
Expand Down

0 comments on commit f69b0da

Please sign in to comment.