Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,15 @@ Code is tested and style checked with tox, you can run the tox tests individuall
* create pull request


## Documentation

CLI command should have a more human readable style of documentation.
Manager methods should have a decent docblock describing any parameters and what the method does.

Docs are generated with [Sphinx](https://docs.readthedocs.io/en/latest/intro/getting-started-with-sphinx.html) and once Sphinx is setup, you can simply do

`make html` in the softlayer-python/docs directory, which should generate the HTML in softlayer-python/docs/_build/html for testing.




192 changes: 192 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
# Makefile for Sphinx documentation
#

# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
PAPER =
BUILDDIR = build

# User-friendly check for sphinx-build
ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1)
$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/)
endif

# Internal variables.
PAPEROPT_a4 = -D latex_paper_size=a4
PAPEROPT_letter = -D latex_paper_size=letter
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
# the i18n builder cannot share the environment and doctrees with the others
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source

.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest coverage gettext

help:
@echo "Please use \`make <target>' where <target> is one of"
@echo " html to make standalone HTML files"
@echo " dirhtml to make HTML files named index.html in directories"
@echo " singlehtml to make a single large HTML file"
@echo " pickle to make pickle files"
@echo " json to make JSON files"
@echo " htmlhelp to make HTML files and a HTML help project"
@echo " qthelp to make HTML files and a qthelp project"
@echo " applehelp to make an Apple Help Book"
@echo " devhelp to make HTML files and a Devhelp project"
@echo " epub to make an epub"
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
@echo " latexpdf to make LaTeX files and run them through pdflatex"
@echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx"
@echo " text to make text files"
@echo " man to make manual pages"
@echo " texinfo to make Texinfo files"
@echo " info to make Texinfo files and run them through makeinfo"
@echo " gettext to make PO message catalogs"
@echo " changes to make an overview of all changed/added/deprecated items"
@echo " xml to make Docutils-native XML files"
@echo " pseudoxml to make pseudoxml-XML files for display purposes"
@echo " linkcheck to check all external links for integrity"
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
@echo " coverage to run coverage check of the documentation (if enabled)"

clean:
rm -rf $(BUILDDIR)/*

html:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."

dirhtml:
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."

singlehtml:
$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
@echo
@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."

pickle:
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
@echo
@echo "Build finished; now you can process the pickle files."

json:
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
@echo
@echo "Build finished; now you can process the JSON files."

htmlhelp:
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
@echo
@echo "Build finished; now you can run HTML Help Workshop with the" \
".hhp project file in $(BUILDDIR)/htmlhelp."

qthelp:
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
@echo
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/softlayer-python.qhcp"
@echo "To view the help file:"
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/softlayer-python.qhc"

applehelp:
$(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp
@echo
@echo "Build finished. The help book is in $(BUILDDIR)/applehelp."
@echo "N.B. You won't be able to view it unless you put it in" \
"~/Library/Documentation/Help or install it in your application" \
"bundle."

devhelp:
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
@echo
@echo "Build finished."
@echo "To view the help file:"
@echo "# mkdir -p $$HOME/.local/share/devhelp/softlayer-python"
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/softlayer-python"
@echo "# devhelp"

epub:
$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
@echo
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."

latex:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
@echo "Run \`make' in that directory to run these through (pdf)latex" \
"(use \`make latexpdf' here to do that automatically)."

latexpdf:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through pdflatex..."
$(MAKE) -C $(BUILDDIR)/latex all-pdf
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."

latexpdfja:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through platex and dvipdfmx..."
$(MAKE) -C $(BUILDDIR)/latex all-pdf-ja
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."

text:
$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
@echo
@echo "Build finished. The text files are in $(BUILDDIR)/text."

man:
$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
@echo
@echo "Build finished. The manual pages are in $(BUILDDIR)/man."

texinfo:
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo
@echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
@echo "Run \`make' in that directory to run these through makeinfo" \
"(use \`make info' here to do that automatically)."

info:
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo "Running Texinfo files through makeinfo..."
make -C $(BUILDDIR)/texinfo info
@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."

gettext:
$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
@echo
@echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."

changes:
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
@echo
@echo "The overview file is in $(BUILDDIR)/changes."

linkcheck:
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
@echo
@echo "Link check complete; look for any errors in the above output " \
"or in $(BUILDDIR)/linkcheck/output.txt."

doctest:
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
@echo "Testing of doctests in the sources finished, look at the " \
"results in $(BUILDDIR)/doctest/output.txt."

coverage:
$(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage
@echo "Testing of coverage in the sources finished, look at the " \
"results in $(BUILDDIR)/coverage/python.txt."

xml:
$(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml
@echo
@echo "Build finished. The XML files are in $(BUILDDIR)/xml."

pseudoxml:
$(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml
@echo
@echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml."
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,14 @@ To get the exact API call that this library makes, you can do the following.
For the CLI, just use the -vvv option. If you are using the REST endpoint, this will print out a curl command that you can use, if using XML, this will print the minimal python code to make the request without the softlayer library.

.. code-block:: bash

$ slcli -vvv vs list


If you are using the library directly in python, you can do something like this.

.. code-bock:: python

import SoftLayer
import logging

Expand All @@ -118,6 +120,8 @@ If you are using the library directly in python, you can do something like this.
main.main()
main.debug()



System Requirements
-------------------
* Python 2.7, 3.3, 3.4, 3.5, 3.6, or 3.7.
Expand Down
11 changes: 7 additions & 4 deletions SoftLayer/CLI/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,20 @@ def multi_option(*param_decls, **attrs):
def resolve_id(resolver, identifier, name='object'):
"""Resolves a single id using a resolver function.

:param resolver: function that resolves ids. Should return None or a list
of ids.
:param resolver: function that resolves ids. Should return None or a list of ids.
:param string identifier: a string identifier used to resolve ids
:param string name: the object type, to be used in error messages

"""
try:
return int(identifier)
except ValueError:
pass # It was worth a shot

ids = resolver(identifier)

if len(ids) == 0:
raise exceptions.CLIAbort("Error: Unable to find %s '%s'"
% (name, identifier))
raise exceptions.CLIAbort("Error: Unable to find %s '%s'" % (name, identifier))

if len(ids) > 1:
raise exceptions.CLIAbort(
Expand Down
2 changes: 2 additions & 0 deletions SoftLayer/CLI/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
('virtual:upgrade', 'SoftLayer.CLI.virt.upgrade:cli'),
('virtual:credentials', 'SoftLayer.CLI.virt.credentials:cli'),
('virtual:capacity', 'SoftLayer.CLI.virt.capacity:cli'),
('virtual:placementgroup', 'SoftLayer.CLI.virt.placementgroup:cli'),

('dedicatedhost', 'SoftLayer.CLI.dedicatedhost'),
('dedicatedhost:list', 'SoftLayer.CLI.dedicatedhost.list:cli'),
Expand Down Expand Up @@ -317,4 +318,5 @@
'vm': 'virtual',
'vs': 'virtual',
'dh': 'dedicatedhost',
'pg': 'placementgroup',
}
7 changes: 7 additions & 0 deletions SoftLayer/CLI/virt/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def _update_with_like_args(ctx, _, value):
'postinstall': like_details.get('postInstallScriptUri'),
'dedicated': like_details['dedicatedAccountHostOnlyFlag'],
'private': like_details['privateNetworkOnlyFlag'],
'placement_id': like_details.get('placementGroupId', None),
}

like_args['flavor'] = utils.lookup(like_details,
Expand Down Expand Up @@ -138,6 +139,10 @@ def _parse_create_args(client, args):
if args.get('host_id'):
data['host_id'] = args['host_id']

if args.get('placementgroup'):
resolver = SoftLayer.managers.PlacementManager(client).resolve_ids
data['placement_id'] = helpers.resolve_id(resolver, args.get('placementgroup'), 'PlacementGroup')

return data


Expand Down Expand Up @@ -190,6 +195,8 @@ def _parse_create_args(client, args):
help=('Security group ID to associate with the private interface'))
@click.option('--wait', type=click.INT,
help="Wait until VS is finished provisioning for up to X seconds before returning")
@click.option('--placementgroup',
help="Placement Group name or Id to order this guest on. See: slcli vs placementgroup list")
@click.option('--ipv6', is_flag=True, help="Adds an IPv6 address to this guest")
@environment.pass_env
def cli(env, **args):
Expand Down
47 changes: 47 additions & 0 deletions SoftLayer/CLI/virt/placementgroup/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""Manages Reserved Capacity."""
# :license: MIT, see LICENSE for more details.

import importlib
import os

import click

CONTEXT = {'help_option_names': ['-h', '--help'],
'max_content_width': 999}


class PlacementGroupCommands(click.MultiCommand):
"""Loads module for placement group related commands.

Currently the base command loader only supports going two commands deep.
So this small loader is required for going that third level.
"""

def __init__(self, **attrs):
click.MultiCommand.__init__(self, **attrs)
self.path = os.path.dirname(__file__)

def list_commands(self, ctx):
"""List all sub-commands."""
commands = []
for filename in os.listdir(self.path):
if filename == '__init__.py':
continue
if filename.endswith('.py'):
commands.append(filename[:-3].replace("_", "-"))
commands.sort()
return commands

def get_command(self, ctx, cmd_name):
"""Get command for click."""
path = "%s.%s" % (__name__, cmd_name)
path = path.replace("-", "_")
module = importlib.import_module(path)
return getattr(module, 'cli')


# Required to get the sub-sub-sub command to work.
@click.group(cls=PlacementGroupCommands, context_settings=CONTEXT)
def cli():
"""Base command for all capacity related concerns"""
pass
31 changes: 31 additions & 0 deletions SoftLayer/CLI/virt/placementgroup/create.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""Create a placement group"""

import click

from SoftLayer.CLI import environment
from SoftLayer.CLI import helpers
from SoftLayer.managers.vs_placement import PlacementManager as PlacementManager


@click.command()
@click.option('--name', type=click.STRING, required=True, prompt=True, help="Name for this new placement group.")
@click.option('--backend_router', '-b', required=True, prompt=True,
help="backendRouter, can be either the hostname or id.")
@click.option('--rule', '-r', required=True, prompt=True,
help="The keyName or Id of the rule to govern this placement group.")
@environment.pass_env
def cli(env, **args):
"""Create a placement group"""
manager = PlacementManager(env.client)
backend_router_id = helpers.resolve_id(manager.get_backend_router_id_from_hostname,
args.get('backend_router'),
'backendRouter')
rule_id = helpers.resolve_id(manager.get_rule_id_from_name, args.get('rule'), 'Rule')
placement_object = {
'name': args.get('name'),
'backendRouterId': backend_router_id,
'ruleId': rule_id
}

result = manager.create(placement_object)
click.secho("Successfully created placement group: ID: %s, Name: %s" % (result['id'], result['name']), fg='green')
Loading