Getting started with the Delphix Python Module

  • 0
  • 1
  • Article
  • Updated 2 years ago
  • (Edited)
Cross-posted from my blog, http://www.therealcloudsurgeon.com/2016/04/getting-started-with-delphix-python.html

This post includes a video, in case it gets removed from this post again, here is the link: https://vimeo.com/164779308

Allo everyone. By popular demand, I going to start a short series on using the Delphix python module, "delphixpy". If you have been following my work any time over the last two years and have downloaded the Landshark environment along with Delphix Express, then you have been a recipient of the benefits of delphixpy.

In short, delphixpy is a way to call the Delphix API from within python so that you can leverage all that object oriented goodness that python provides. This also allows you to treat json as dictionaries and many other powerful things of python. I have posted three common examples for DevOps, CI/CD, and Enterprise Automation shops and did try to meticulously comment them. I have recorded an intro video where I walk you through getting your Landshark environment setup to run the scripts and run the examples against a Landshark environment so that you can easily follow along where ever you are.

There will be much more information to come very soon, we are just getting started! (I apologize in advance for my repetition of the word "neat." It is so weird, but I never realized that I even use that word!)

You can get my examples from GitHub here
You can post questions, etc on the Delphix Community Site here
Landshark and Delphix Express download and setup instructions here



Summary of preparation commands:


  1. ssh into the Landshark LinuxTarget as the delphix user.

  2. assume root: su -

  3. yum install git -y

  4. pip install virtualenv

  5. exit root (you should now be the delphix user again)

  6. git clone https://github.com/CloudSurgeon/delph...

  7. virtualenv --system-site-packages ~/landshark

  8. source ~/landshark/bin/activate

  9. pip install --upgrade -r ~/delphixpy-examples/requirements.txt

Photo of Adam Bowen

Adam Bowen, Official Rep

  • 17,418 Points 10k badge 2x thumb
  • Excited

Posted 2 years ago

  • 0
  • 1
Photo of Sergii

Sergii

  • 170 Points 100 badge 2x thumb
Hi Adam, I have an error on step 9:
Could not open requirements file: [Errno 2] No such file or directory: '/root/delphixpy-examples/requirements.txt'
Can you advise something?
Photo of Adam Bowen

Adam Bowen, Official Rep

  • 17,418 Points 10k badge 2x thumb
You are logged in as root. You missed step 5 where you exit as root. Steps 6 -9 should be completed as the delphix user, if you are following along in your Landshark environment. 
Photo of Adam Bowen

Adam Bowen, Official Rep

  • 17,418 Points 10k badge 2x thumb
I amended the instructions to be more clear.
Photo of Adam Bowen

Adam Bowen, Official Rep

  • 17,418 Points 10k badge 2x thumb
Somehow my video was pulled out of this post, I have added it back. Follow along with my video, for clarity.
Photo of Sergii

Sergii

  • 170 Points 100 badge 2x thumb
Thank you, Adam. I have this resolved with your video along with.

Now I have new one:

[delphix@linuxtarget ~]$ ./dx_snapshot_db.py --group Sources --name "dbSource"
Traceback (most recent call last):
File "./dx_snapshot_db.py", line 60, in
from docopt import docopt
ImportError: No module named docopt
[delphix@linuxtarget ~]$ ./dx_snapshot_db.py --help
Traceback (most recent call last):
File "./dx_snapshot_db.py", line 60, in
from docopt import docopt
ImportError: No module named docopt
[delphix@linuxtarget ~]$ ./dx_snapshot_db.py -h
Traceback (most recent call last):
File "./dx_snapshot_db.py", line 60, in
from docopt import docopt
ImportError: No module named docopt
Photo of Adam Bowen

Adam Bowen, Official Rep

  • 17,418 Points 10k badge 2x thumb
It seems now you have skipped step 9. Step 9 installs docopt. If you did Step 9, can you repeat it and post your output?
Photo of Sergii

Sergii

  • 170 Points 100 badge 2x thumb
I have step 9 repeated and you can see the output bellow and in uploaded image.

[delphix@linuxtarget ~]$ pip install --upgrade -r ~/delphixpy-examples/requirements.txt
Downloading/unpacking setuptools from https://pypi.python.org/packages/15/b... (from -r /home/delphix/delphixpy-examples/requirements.txt (line 1))
Downloading setuptools-21.0.0-py2.py3-none-any.whl (509kB): 509kB downloaded
Downloading/unpacking pip from https://pypi.python.org/packages/31/6... (from -r /home/delphix/delphixpy-examples/requirements.txt (line 2))
Downloading pip-8.1.1-py2.py3-none-any.whl (1.2MB): 1.2MB downloaded
Downloading/unpacking docopt (from -r /home/delphix/delphixpy-examples/requirements.txt (line 3))
Downloading docopt-0.6.2.tar.gz
Running setup.py (path:/u02/tmp/pip_build_delphix/docopt/setup.py) egg_info for package docopt

Downloading/unpacking delphixpy from https://pypi.python.org/packages/ab/4... (from -r /home/delphix/delphixpy-examples/requirements.txt (line 4))
Downloading delphixpy-1.7.0.0.tar.gz (3.9MB): 3.9MB downloaded
Running setup.py (path:/u02/tmp/pip_build_delphix/delphixpy/setup.py) egg_info for package delphixpy

Installing collected packages: setuptools, pip, docopt, delphixpy
Found existing installation: setuptools 7.0
Uninstalling setuptools:
Cleaning up...
Exception:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/pip/basecommand.py", line 122, in main
status = self.run(options, args)
Photo of Adam Bowen

Adam Bowen, Official Rep

  • 17,418 Points 10k badge 2x thumb
Yep. I covered this in my video, as well (@3:35)

You got this error message because you were missing step 8.
Photo of Sergii

Sergii

  • 170 Points 100 badge 2x thumb
Thank you! I have it done.

(landshark) [delphix@linuxtarget ~]$ ./dx_snapshot_db.py --group Sources --name "dbSource"
{'--all': False,
'--all_dbs': False,
'--config': './dxtools.conf',
'--debug': False,
'--engine': None,
'--group': 'Sources',
'--help': False,
'--host': None,
'--logdir': './dx_snapshot_db.log',
'--name': 'dbSource',
'--object_type': None,
'--parallel': None,
'--poll': '10',
'--usebackup': False,
'--version': False,
'-d': None}
INFO: Welcome to dx_snapshot_db.py, version v.0.0.010
INFO: Executing against the default Delphix Engine in the dxtools.conf: Delphix5Demo
INFO: Delphix5Demo: Syncing dbSource
INFO: Delphix5Demo: dbSource: RUNNING
INFO: Delphix5Demo: 1 jobs running. 0 jobs waiting to run
INFO: Delphix5Demo: dbSource: COMPLETED
INFO: Delphix5Demo: 0 jobs running. 0 jobs waiting to run
INFO: script took 0.2 minutes to get this far.
(landshark) [delphix@linuxtarget ~]$
Photo of Adam Bowen

Adam Bowen, Official Rep

  • 17,418 Points 10k badge 2x thumb
Supreme.