In this article we will cover installing “PyFi” which is Project FiFo’s Python based console client that enables remote interaction and control of your FiFo cloud via the FiFo API. This is incredibly useful tool and can be used as an alternative method to orchestrate your FiFo cloud via your own in-house web interface. Alternatively you could integrate PyFi scripted workflows with your existing backend systems to deploy or control your virtual machine instances.
For the purposes of this guide, we will be covering installing “PyFi” via the recommended “pip” install method that can be used on any operating system. We will also briefly cover manual setup via a git clone install method. Most Operating System installations should be very similar providing you have Python installed.
Python pip install method
First lets download and install “pip”, a package management system tool for installing and managing Python packages.
curl -O https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py python ez_setup.py curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py python get-pip.py sudo pip install --egg pyfi
Now that its installed we first run PyFi to create a generic config file and then secondly, edit the file and save our credentials. Once that is done we can successfully interact via FiFo’s API.
root@localhost:~# fifo vms list fifo client is not configured creating an example config at: /root/.fifo root@localhost:~# vi ~/.fifo
filename : .fifo
[GENERAL] active = fifo_default [fifo_default] host = 10.1.1.111 user = peterpan pass = fairydust
The first time you successfully authenticate with FiFo, an authentication token will be added to your pyfi “.fifo” configuration file as shown below.
[GENERAL] active = fifo_default [fifo_default] host = 10.1.1.111 user = peterpan pass = fairydust token = 616dec22-e85b-4262-9388-5cd8fac48d45
You will now be able to connect to your fifo host via the API and interact with your SmartOS cloud. Pretty cool huh?
root@localhost:~# fifo vms list UUID hypervisor alias state ------------------------------------ -------------------- ---------- --------------- 1719e2fb-32a5-4784-b9ab-cb053ef4a392 smartosn1 ubuntu-12.04-test running 2aa40c28-1199-4dfa-9051-8b3b744dc233 smartosn2 megastore2 running 5d28ed86-2794-4909-9cbf-e97e362c749b smartosn2 be:gitlab running 5daed30b-26b3-4717-ac02-dc2346020607 smartosn2 home-webserver running 5edc0bbc-312d-4893-8069-20874e430243 smartosn2 znc running 62d6cb0a-0535-4549-9f81-19c48cec0163 smartosn1 onyxit-confluence running 82730c01-deb0-428b-8780-d90944fa2466 smartosn2 megastore running 8833f427-1d11-4a00-8e36-790b09bb3fe9 smartosn1 pkgin-proxy running 89819a99-6692-4e32-9e10-c28e6aa3980a smartosn2 plex running 9bfcde12-917f-4530-ad37-effa26666ca3 smartosn2 observium running a4a238fe-4bfe-4edc-8f0d-5d72158b718e smartosn1 2k8foundation running b24a9b19-6da2-49eb-a823-750815172422 smartosn1 teamfortress stopped eaf0f5a0-4956-4eff-a535-9f84980f92a5 smartosn2 pxeboot stopped f2facd4c-946d-4b65-a859-138274529ad2 smartosn1 dsapi-server running f8bd1553-e010-4729-b5de-4dea260848c2 smartosn2 fifo-dev running fbae8217-e78e-4d3f-8dd9-af4599ab63fb smartosn2 minecraft-jdk7 running fe55ed16-06bd-4c24-84c8-a68d3db75776 smartosn1 Request Tracker running
Git clone method
Lets grab the files we will need by cloning the files directly from pyfi’s project page on github.
Run: git clone https://github.com/project-fifo/pyfi.git
macmini-mark:Downloads marks$ git clone https://github.com/project-fifo/pyfi.git Cloning into 'pyfi'... remote: Counting objects: 269, done. remote: Compressing objects: 100% (127/127), done. remote: Total 269 (delta 144), reused 242 (delta 118) Receiving objects: 100% (269/269), 45.18 KiB, done. Resolving deltas: 100% (144/144), done. macmini-mark:Downloads marks$ cd pyfi/
Now we install and configure it.
Run: python setup.py build build_scripts
macmini-mark:pyfi marks$ python setup.py build build_scripts running build running build_py creating build creating build/lib creating build/lib/fifo copying fifo/__init__.py -> build/lib/fifo copying fifo/helper.py -> build/lib/fifo creating build/lib/fifo/api copying fifo/api/__init__.py -> build/lib/fifo/api copying fifo/api/dataset.py -> build/lib/fifo/api copying fifo/api/dtrace.py -> build/lib/fifo/api copying fifo/api/group.py -> build/lib/fifo/api copying fifo/api/hypervisor.py -> build/lib/fifo/api copying fifo/api/iprange.py -> build/lib/fifo/api copying fifo/api/network.py -> build/lib/fifo/api copying fifo/api/package.py -> build/lib/fifo/api copying fifo/api/user.py -> build/lib/fifo/api copying fifo/api/vm.py -> build/lib/fifo/api copying fifo/api/wiggle.py -> build/lib/fifo/api running build_scripts creating build/scripts-2.7 copying and adjusting bin/fifo -> build/scripts-2.7 changing mode of build/scripts-2.7/fifo from 644 to 755
Then we run it and it will auto create a generic configuration file called .fifo in your home directory. This file is used so that you can authenticate with your fifo host without needing to supply authentication details and host you want to connect to via the command line every time. You then edit this file and put in your username, password and FiFo host ip. Once done you will need to call the client by using the full python path as shown below:
Run: PYTHONPATH=build/lib python build/scripts-2.7/fifo vms list
macmini-mark:pyfi marks$ PYTHONPATH=build/lib python build/scripts-2.7/fifo vms list fifo client is not configured creating an example config at: /Users/marks/.fifo
Ok, phew!, we have now covered quite extensively how to install the tool so lets move on to actually using it.
PyFi in practice
We will now demonstrate some use case examples. There are many ways to use the client but the most common will probably be to control your existing machines as well as deploying new ones.
Help Options
usage: fifo [-h] [--config CONFIG] [--host HOST] [--user USER] [--password PASSWORD] [--version] {hypervisors,vms,packages,datasets,networks,ipranges,dtrace,users,groups} ... FiFo API client. positional arguments: {hypervisors,vms,packages,datasets,networks,ipranges,dtrace,users,groups} sub commands hypervisors hypervisor related commands vms vm related commands packages package related commands datasets dataset related commands networks network related commands ipranges iprange related commands dtrace dtrace related commands users user related commands groups group related commands optional arguments: -h, --help show this help message and exit -c --config CONFIG Selects the network config to use --host HOST The host to use (dns or ip no https://) -u --user USER The user to log in with. -p --password PASSWORD The password to log in with. --version show program's version number and exit
Oct 03, 2013 @ 23:05:00
tried but:
on openindiana
./fifo vms list
/usr/bin/env: python2: No such file or directory
tried to remove 2 or to add 2.6
but
bash-4.2$ ./fifo vms list
Traceback (most recent call last):
File “./fifo”, line 6, in
import argparse
ImportError: No module named argparse
Maybe I fail something on install procedure
Oct 04, 2013 @ 08:02:00
Hi Paolo, I just installed on another OS, and this is what I used when running the command. Let me know if it solves your issue.
PYTHONPATH=build/lib python build/scripts-2.7/fifo vms list
Oct 04, 2013 @ 15:53:00
Yes now with the addition of argparse and PYTHONPATH
It works well !!
Thank you
Paolo
Oct 04, 2013 @ 08:28:00
I also think it requires Python 2.7 for the “argparse” dependency. On OpenIndiana 151a5 I got it to run by installing “argparse” via easy_install
1) easy_install argparse
2) PYTHONPATH=build/lib python build/scripts-2.6/fifo -h
Also have a look at:
https://pypi.python.org/pypi/argparse
https://pypi.python.org/pypi/setuptools/1.1.6