Changes

Jump to: navigation, search

OPS435 Python Lab 8

1,369 bytes added, 12:27, 30 December 2017
INVESTIGATION 1: Extra VM Setup
Make snapshots of all your workers so that you can easily restore them to the original state after you modify them.
 
= INVESTIGATION 2: Fabric practice =
 
We will start with some basics. Fabric runs python programs on the controller and the workers. You create an "instruction" file on your controller, and execute it on the controller using the '''fab''' program. When you do that - you specify which workers you want your instructions to be executed on.
 
The instructions are stored in a python file. Let's start with a simple one named '''fabfile.py''' (the default filename for fab):
 
<source lang="python">from fabric.api import *
 
# Will get the hostname of this worker:
def getHostname():
name = run("hostname")
print(name)
</source>
 
All this will do is get the hostname of the worker and print it (on the controller). We run it on the controller like this:
 
<source lang="bash">fab --fabfile=fabfile.py -H 192.168.56.11 getHostname</source>
 
In the command above we're using the fab program to read the file fabfile.py and execute the getHostname function on the worker 192.168.56.11. Note that the IP address of your first worker will likely be different.
 
If you did all the setup right and you try to execute the command above - you will get a password prompt. That shouldn't happen, the point is for everything to be automated, and that's why you've set up SSH keys. To fix it, add the following to your fab file:
 
<source lang="python">env.user = 'root'</source>
= LAB 7 SIGN-OFF (SHOW INSTRUCTOR) =

Navigation menu