diff --git a/LICENSE b/LICENSE.txt similarity index 100% rename from LICENSE rename to LICENSE.txt diff --git a/README.md b/README.md deleted file mode 100644 index 1c84817..0000000 --- a/README.md +++ /dev/null @@ -1,31 +0,0 @@ -[![PyPI version](https://badge.fury.io/py/vix.svg)](https://badge.fury.io/py/vix) - -# Vix wrapper -VMware's [VIX](https://www.vmware.com/support/developer/vix-api/) library can be really useful if you want to automate VM operations. This project was written to provide an Object-Oriented interface with the VIX API. - -Tested with VMware Workstation, this wrapper should support ESXs, VMware servers and other VMware products. - -## Features -* Written for Python3, it should support Python2 as well. -* Access VIX API through [cffi](http://cffi.readthedocs.io/en/latest/), thus allowing execution over [pypy](http://pypy.org/). -* Supported operations: - * Power (turn on, turn off, suspend, etc...) - * Snapshot control - * Cloning (both full and linked) - * Finding powered on VMs (or registered, if your VMware product supports it) - * Script & command execution on guest. - * Listing directories & Processes - * Killing processes - * Deleting files & directories - * Control VMs environment - * Control shares - * Get PNG screenshots of VMs -* Deletion of VMs from host -* Registration and unregistration of VMs from hosts. - -## Licenses -vix (this project) is released under the [GPLv3](LICENSE) license. -This projects uses redistributable software developed by VMware. - -## Bugs, Features, support -Please reffer to [CONTRIBUTING](CONTRIBUTING.md). diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..84b1218 --- /dev/null +++ b/README.rst @@ -0,0 +1,53 @@ +VIX +=== + +VIX is a object oriented python wrapper for `VMware's VIX API`_. + +Installing +---------- + +Install and update using `pip`_: + +.. code-block:: text + + pip install -U vix + +Quick Example +------------- + +.. code-block:: python + + from vix import VixHost, VixError + + host = VixHost() + + try: + vm = host.open_vm(r'/home/root/VirtualMachines/Debian/Debian.vmx') + snapshot = vm.create_snapshot( + 'Testing VIX', + 'Well, this is great!', + include_memory=True + ) + print('Snapshot created!') + except VixError as ex: + print("Something went wrong :( {0}".format(ex)) + +Features +-------- + +The full VIX API was wrapped, some of the supported operations include: + +- Power on & power off VMs. +- Manage snapshots (with or without memory) +- Cloning (linked or full) +- Script & Command execution on guests + + - Executing scripts and processes + - Manage directories, files & processes + +- Control VMs environment +- Manage shared folders +- Create screenshot of guest VMs + +.. _VMware's VIX API: https://www.vmware.com/support/developer/vix-api/ +.. _pip: https://pip.pypa.io/en/stable/quickstart diff --git a/docs/conf.py b/docs/conf.py index 87ec514..7d86fd3 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,454 +1,37 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- -# -# vix documentation build configuration file, created by -# sphinx-quickstart on Sat Sep 10 21:29:58 2016. -# -# This file is execfile()d with the current directory set to its -# containing dir. -# -# Note that not all possible configuration values are present in this -# autogenerated file. -# -# All configuration values have a default; values that are commented out -# serve to show the default. - -# If extensions (or modules to document with autodoc) are in another directory, -# add these directories to sys.path here. If the directory is relative to the -# documentation root, use os.path.abspath to make it absolute, like shown here. -# import os import sys -import alabaster +import sphinx_rtd_theme + +# find the vix module sys.path.insert(0, os.path.abspath('..')) from vix import __version__ -# -- General configuration ------------------------------------------------ - -# If your documentation needs a minimal Sphinx version, state it here. -# -# needs_sphinx = '1.0' - -# Add any Sphinx extension module names here, as strings. They can be -# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom -# ones. extensions = [ - 'alabaster', 'sphinx.ext.autodoc', ] -# Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] - -# The suffix(es) of source filenames. -# You can specify multiple suffix as a list of string: -# -# source_suffix = ['.rst', '.md'] -source_suffix = '.rst' - -# The encoding of source files. -# -# source_encoding = 'utf-8-sig' +source_suffix = ['.rst'] -# The master toctree document. master_doc = 'index' # General information about the project. project = 'vix' -copyright = '2017, Naim A.' +copyright = '2018, Naim A.' author = 'Naim A.' - -# The version info for the project you're documenting, acts as replacement for -# |version| and |release|, also used in various other places throughout the -# built documents. -# -# The short X.Y version. version = __version__ -# The full version, including alpha/beta/rc tags. -release = __version__ - -# The language for content autogenerated by Sphinx. Refer to documentation -# for a list of supported languages. -# -# This is also used if you do content translation via gettext catalogs. -# Usually you set "language" from the command line for these cases. language = 'en' -# There are two options for replacing |today|: either, you set today to some -# non-false value, then it is used: -# -# today = '' -# -# Else, today_fmt is used as the format for a strftime call. -# -# today_fmt = '%B %d, %Y' - -# List of patterns, relative to source directory, that match files and -# directories to ignore when looking for source files. -# This patterns also effect to html_static_path and html_extra_path -exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] - -# The reST default role (used for this markup: `text`) to use for all -# documents. -# -# default_role = None - -# If true, '()' will be appended to :func: etc. cross-reference text. -# -# add_function_parentheses = True - -# If true, the current module name will be prepended to all description -# unit titles (such as .. function::). -# -# add_module_names = True - -# If true, sectionauthor and moduleauthor directives will be shown in the -# output. They are ignored by default. -# -# show_authors = False - -# The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' - -# A list of ignored prefixes for module index sorting. -# modindex_common_prefix = [] - -# If true, keep warnings as "system message" paragraphs in the built documents. -# keep_warnings = False - -# If true, `todo` and `todoList` produce output, else they produce nothing. todo_include_todos = True -# -- Autodoc autoclass_content = 'class' autodoc_member_order = 'bysource' - -# -- Options for HTML output ---------------------------------------------- - -# The theme to use for HTML and HTML Help pages. See the documentation for -# a list of builtin themes. -# -html_theme = 'alabaster' - -# Theme options are theme-specific and customize the look and feel of a theme -# further. For a list of options available for each theme, see the -# documentation. -# +html_theme = 'sphinx_rtd_theme' +html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] html_theme_options = { - 'github_button': 'true', - 'github_type': 'watch', - 'github_count': 'false', - 'github_banner': 'true', - 'github_user': 'naim94a', - 'github_repo': 'vix', - 'description': 'The unofficial python binding for VIX', - 'analytics_id': 'UA-11289087-19', - 'sidebar_collapse': False, - 'show_related': True, - 'fixed_sidebar': True, -} - -# Add any paths that contain custom themes here, relative to this directory. -# html_theme_path = [] -html_theme_path = [alabaster.get_path()] - -# The name for this set of Sphinx documents. -# " v documentation" by default. -# -# html_title = 'vix v' - -# A shorter title for the navigation bar. Default is the same as html_title. -# -# html_short_title = None - -# The name of an image file (relative to this directory) to place at the top -# of the sidebar. -# -# html_logo = None - -# The name of an image file (relative to this directory) to use as a favicon of -# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 -# pixels large. -# -# html_favicon = None - -# Add any paths that contain custom static files (such as style sheets) here, -# relative to this directory. They are copied after the builtin static files, -# so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] - -# Add any extra paths that contain custom files (such as robots.txt or -# .htaccess) here, relative to this directory. These files are copied -# directly to the root of the documentation. -# -# html_extra_path = [] - -# If not None, a 'Last updated on:' timestamp is inserted at every page -# bottom, using the given strftime format. -# The empty string is equivalent to '%b %d, %Y'. -# -# html_last_updated_fmt = None - -# If true, SmartyPants will be used to convert quotes and dashes to -# typographically correct entities. -# -# html_use_smartypants = True - -# Custom sidebar templates, maps document names to template names. -# -html_sidebars = { - '**': [ - 'about.html', - 'navigation.html', - 'relations.html', - 'searchbox.html', - 'donate.html', - ] + 'display_version': True, } -# Additional templates that should be rendered to pages, maps page names to -# template names. -# -# html_additional_pages = {} - -# If false, no module index is generated. -# -# html_domain_indices = True - -# If false, no index is generated. -# -# html_use_index = True - -# If true, the index is split into individual pages for each letter. -# -# html_split_index = False - -# If true, links to the reST sources are added to the pages. -# html_show_sourcelink = False - -# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. -# -# html_show_sphinx = True - -# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. -# -# html_show_copyright = True - -# If true, an OpenSearch description file will be output, and all pages will -# contain a tag referring to it. The value of this option must be the -# base URL from which the finished HTML is served. -# -# html_use_opensearch = '' - -# This is the file name suffix for HTML files (e.g. ".xhtml"). -# html_file_suffix = None - -# Language to be used for generating the HTML full-text search index. -# Sphinx supports the following languages: -# 'da', 'de', 'en', 'es', 'fi', 'fr', 'h', 'it', 'ja' -# 'nl', 'no', 'pt', 'ro', 'r', 'sv', 'tr', 'zh' -# -# html_search_language = 'en' - -# A dictionary with options for the search language support, empty by default. -# 'ja' uses this config value. -# 'zh' user can custom change `jieba` dictionary path. -# -# html_search_options = {'type': 'default'} - -# The name of a javascript file (relative to the configuration directory) that -# implements a search results scorer. If empty, the default will be used. -# -# html_search_scorer = 'scorer.js' - -# Output file base name for HTML help builder. htmlhelp_basename = 'vixdoc' - -# -- Options for LaTeX output --------------------------------------------- - -latex_elements = { - # The paper size ('letterpaper' or 'a4paper'). - # - # 'papersize': 'letterpaper', - - # The font size ('10pt', '11pt' or '12pt'). - # - # 'pointsize': '10pt', - - # Additional stuff for the LaTeX preamble. - # - # 'preamble': '', - - # Latex figure (float) alignment - # - # 'figure_align': 'htbp', -} - -# Grouping the document tree into LaTeX files. List of tuples -# (source start file, target name, title, -# author, documentclass [howto, manual, or own class]). -latex_documents = [ - (master_doc, 'vix.tex', 'vix Documentation', - 'Author', 'manual'), -] - -# The name of an image file (relative to this directory) to place at the top of -# the title page. -# -# latex_logo = None - -# For "manual" documents, if this is true, then toplevel headings are parts, -# not chapters. -# -# latex_use_parts = False - -# If true, show page references after internal links. -# -# latex_show_pagerefs = False - -# If true, show URL addresses after external links. -# -# latex_show_urls = False - -# Documents to append as an appendix to all manuals. -# -# latex_appendices = [] - -# It false, will not define \strong, \code, itleref, \crossref ... but only -# \sphinxstrong, ..., \sphinxtitleref, ... To help avoid clash with user added -# packages. -# -# latex_keep_old_macro_names = True - -# If false, no module index is generated. -# -# latex_domain_indices = True - - -# -- Options for manual page output --------------------------------------- - -# One entry per manual page. List of tuples -# (source start file, name, description, authors, manual section). -man_pages = [ - (master_doc, 'vix', 'vix Documentation', - [author], 1) -] - -# If true, show URL addresses after external links. -# -# man_show_urls = False - - -# -- Options for Texinfo output ------------------------------------------- - -# Grouping the document tree into Texinfo files. List of tuples -# (source start file, target name, title, author, -# dir menu entry, description, category) -texinfo_documents = [ - (master_doc, 'vix', 'vix Documentation', - author, 'vix', 'One line description of project.', - 'Miscellaneous'), -] - -# Documents to append as an appendix to all manuals. -# -# texinfo_appendices = [] - -# If false, no module index is generated. -# -# texinfo_domain_indices = True - -# How to display URL addresses: 'footnote', 'no', or 'inline'. -# -# texinfo_show_urls = 'footnote' - -# If true, do not generate a @detailmenu in the "Top" node's menu. -# -# texinfo_no_detailmenu = False - - -# -- Options for Epub output ---------------------------------------------- - -# Bibliographic Dublin Core info. -epub_title = project -epub_author = author -epub_publisher = author -epub_copyright = copyright - -# The basename for the epub file. It defaults to the project name. -# epub_basename = project - -# The HTML theme for the epub output. Since the default themes are not -# optimized for small screen space, using the same theme for HTML and epub -# output is usually not wise. This defaults to 'epub', a theme designed to save -# visual space. -# -# epub_theme = 'epub' - -# The language of the text. It defaults to the language option -# or 'en' if the language is not set. -# -# epub_language = '' - -# The scheme of the identifier. Typical schemes are ISBN or URL. -# epub_scheme = '' - -# The unique identifier of the text. This can be a ISBN number -# or the project homepage. -# -# epub_identifier = '' - -# A unique identification for the text. -# -# epub_uid = '' - -# A tuple containing the cover image and cover page html template filenames. -# -# epub_cover = () - -# A sequence of (type, uri, title) tuples for the guide element of content.opf. -# -# epub_guide = () - -# HTML files that should be inserted before the pages created by sphinx. -# The format is a list of tuples containing the path and title. -# -# epub_pre_files = [] - -# HTML files that should be inserted after the pages created by sphinx. -# The format is a list of tuples containing the path and title. -# -# epub_post_files = [] - -# A list of files that should not be packed into the epub file. -epub_exclude_files = ['search.html'] - -# The depth of the table of contents in toc.ncx. -# -# epub_tocdepth = 3 - -# Allow duplicate toc entries. -# -# epub_tocdup = True - -# Choose between 'default' and 'includehidden'. -# -# epub_tocscope = 'default' - -# Fix unsupported image types using the Pillow. -# -# epub_fix_images = False - -# Scale large images. -# -# epub_max_image_width = 0 - -# How to display URL addresses: 'footnote', 'no', or 'inline'. -# -# epub_show_urls = 'inline' - -# If false, no index is generated. -# -# epub_use_index = True diff --git a/docs/index.rst b/docs/index.rst index 7d22711..fc7d301 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,58 +1,38 @@ -.. vix documentation master file, created by - sphinx-quickstart on Sat Sep 10 21:29:58 2016. - You can adapt this file completely to your liking, but it should at least - contain the root `toctree` directive. - .. toctree:: :maxdepth: 2 :hidden: + installation tutorials vix VIX Python binding ================== -This is an unofficial binding of VMware's VIX API. - -The VIX project is hosted on GitHub: https://github.com/naim94a/vix. -Feel free to submit pull requests and issues. - -About ------ -VIX is a C library created by VMWare, the aim of this project is to wrap it in python. -This project allow Object-Oriented access to various VMWare products. - - -Installing ----------- - -.. code-block:: shell - - pip install vix - +An unofficial object oriented python binding for `VMware's VIX API`_. -Example usage -------------- +Features +-------- -.. code-block:: python - :caption: snapshot-demo.py +- Control a VMs power state, and get the current state. +- Manage Snapshots: Create, modify, delete. +- Create screenshots of guest VMs. +- Clone VMs - either full or linked. +- Execute on guests - from vix import VixHost, VixError + - Run commands and scripts + - List and delete files or processes - host = VixHost() - host.connect() +- Manage sharing folders with guests. - try: - vm = host.open_vm(r'~/Windows 7.vmx') +This wrapper should cover the full VIX API of VMware. If it doesn't, please +`create an issue`_. - snapshot = vm.create_snapshot( - 'Todays Snapshot', - 'Just testing vix', - include_memory=True - ) +License +------- - print("Made snapshot!") +VIX is released under the GPLv3_ license. - except VixError as ex: - print("Operatation failed: {0}".format(ex)) +.. _VMware's VIX API: https://www.vmware.com/support/developer/vix-api/ +.. _GPLv3: https://github.com/naim94a/vix/blob/master/LICENSE.txt +.. _create an issue: https://github.com/naim94a/vix/issues/new diff --git a/docs/installation.rst b/docs/installation.rst new file mode 100644 index 0000000..66036f6 --- /dev/null +++ b/docs/installation.rst @@ -0,0 +1,11 @@ +Installation +============ + +Installing is very streight forward once VMware is already installed, it's as +easy as + +.. code-block:: text + + pip install -U vix + +.. note:: You must have a VMware product installed before installing this Python VIX wrapper. diff --git a/docs/tutorials.rst b/docs/tutorials.rst index 018c919..297b344 100644 --- a/docs/tutorials.rst +++ b/docs/tutorials.rst @@ -1,5 +1,5 @@ -Tutorials -========= +Tutorial +======== Capturing screens ----------------- @@ -11,39 +11,38 @@ The VIX python binding can return a screenshot in PNG format. You can choose bet This example will demonstrate how to take screenshots from a VM every 10 seconds. .. code-block:: python - :caption: screenshots.py import time from vix import VixHost host = VixHost() - vm = host.open_vm('~/my vm.vmx') + vm = host.open_vm('/path/to/my/vm.vmx') # Must login to do some things... vm.login('root', 'toor') while True: - vm.capture_screen_image('~/IMG_{name}_{timestamp:.0f}.png'.format(name=vm.name, timestamp=time.time())) + vm.capture_screen_image('/path/to/my/screenshot_{name}_{timestamp:.0f}.png'.format(name=vm.name, timestamp=time.time())) time.sleep(10.0) Cloning Machines ---------------- + Cloning machines are usually a more useful action then capturing screenshots. It is a pretty simple task to... .. code-block:: python - :caption: snapshot.py - from vix import VixHost + from vix import VixHost - host = VixHost() - vm = host.open_vm('~/template.vmx') + host = VixHost() + vm = host.open_vm('/path/to/my/template/vm.vmx') - # Assuming that template.vmx is currently on a powered off snapshot. - snapshot = vm.snapshot_get_current() + # Assuming that template.vmx is currently on a powered off snapshot. + snapshot = vm.snapshot_get_current() - # This clone will be based of 'template.vmx' at the specified snapshot. - # Linked snapshots take less space... - cloned = vm.clone('~/cloned.vmx', snapshot=snapshot, linked=True) + # This clone will be based of 'template.vmx' at the specified snapshot. + # Linked snapshots take less space... + cloned = vm.clone('/path/to/my/cloned/vm.vmx', snapshot=snapshot, linked=True) - # Let fire up our cloned machine! + # Let fire up our cloned machine! cloned.power_on() diff --git a/docs/vix.rst b/docs/vix.rst index 348e14f..459c149 100644 --- a/docs/vix.rst +++ b/docs/vix.rst @@ -1,57 +1,59 @@ -VIX Reference +============= +API Reference ============= -VixHost class -------------- +VixHost +======= .. autoclass:: vix.VixHost :members: :undoc-members: :show-inheritance: -VixVM class ------------ +VixVM +===== .. autoclass:: vix.VixVM :members: :undoc-members: :show-inheritance: -VixSnapshot class ------------------ +VixSnapshot +=========== .. autoclass:: vix.VixSnapshot :members: :undoc-members: :show-inheritance: -VixError class ------------------- +VixError +======== .. autoexception:: vix.VixError :members: :undoc-members: :show-inheritance: +-------------------- vix Internal classes -==================== +-------------------- .. warning:: These classes shouldn't be normally dealt with. Using these classes directly may cause python to crash. -VixHandle class ---------------- +VixHandle +========= .. autoclass:: vix.VixHandle.VixHandle :members: :undoc-members: :show-inheritance: -VixJob class ------------- +VixJob +====== .. autoclass:: vix.VixJob.VixJob :members: :undoc-members: :show-inheritance: -VixBackend class ----------------- +VixBackend +========== .. autoclass:: vix.VixBackend.VixBackend :members: _get_vix_path :undoc-members: diff --git a/setup.py b/setup.py index fca4596..b6e6cfd 100644 --- a/setup.py +++ b/setup.py @@ -1,9 +1,20 @@ +import os +import re from setuptools import setup +BASE_DIR = os.path.abspath(os.path.dirname(__file__)) + +with open(os.path.join(BASE_DIR, 'README.rst'), 'rt') as fd: + long_description = fd.read() + +with open(os.path.join(BASE_DIR, 'vix', '__init__.py'), 'rt') as fd: + version = re.search(r'__version__\W*=\W*(\'|")(.+?)(\'|")', fd.read()).group(2) + setup( name='vix', - version='1.0.6', + version=version, description='VMware VIX binding for Python (unofficial)', + long_description=long_description, author='Naim A.', author_email='naim94a@gmail.com', url='https://github.com/naim94a/vix', @@ -13,6 +24,7 @@ }, license='GPLv3', classifiers=[ + 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Developers', 'Intended Audience :: Information Technology', 'Intended Audience :: System Administrators', @@ -29,5 +41,11 @@ install_requires=[ 'cffi>=1.8.2', 'six', - ] + ], + keywords='vmware python api vix', + project_urls={ + 'Documentation': 'https://naim94a.github.io/vix', + 'Source': 'https://github.com/naim94a/vix', + 'Bugs & Features': 'https://github.com/naim94a/vix/issues' + } ) diff --git a/vix/VixBackend.py b/vix/VixBackend.py index 18d5ba4..6658288 100644 --- a/vix/VixBackend.py +++ b/vix/VixBackend.py @@ -141,7 +141,9 @@ def __init__(self): VixError VixSnapshot_GetChild(VixHandle parentSnapshotHandle, int index, VixHandle *childSnapshotHandle); VixError VixSnapshot_GetParent(VixHandle snapshotHandle, VixHandle *parentSnapshotHandle); ''') - self._vix = self._ffi.dlopen(VixBackend._get_vix_path()) + + # Don't fail build for documentation. + self._vix = self._ffi.dlopen(VixBackend._get_vix_path()) if os.getenv('READTHEDOCS') is None else None @staticmethod def _get_vix_path(): diff --git a/vix/__init__.py b/vix/__init__.py index b6b0c67..ddd0f70 100644 --- a/vix/__init__.py +++ b/vix/__init__.py @@ -8,7 +8,7 @@ :license: GPLv3, see LICENSE for more details. """ -__version__ = "1.0.6" +__version__ = "1.0.7" from .VixBackend import VixBackend as _VixBackend _backend = _VixBackend()