Skip to content

Commit

Permalink
Fixed the rest of the docs. Everything should look pretty now
Browse files Browse the repository at this point in the history
- Interfaces are PEP8 compliant now as well.
  • Loading branch information
GhostofGoes committed May 20, 2017
1 parent ff2f13e commit cb4cf87
Show file tree
Hide file tree
Showing 14 changed files with 609 additions and 306 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ instance/
.scrapy

# Sphinx documentation
docs/_build/
docs/build/

# PyBuilder
target/
Expand Down
5 changes: 3 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Documentation for vSphere is [here](https://pubs.vmware.com/vsphere-60/index.jsp

# Documentation
* Development guide: how to setup development environment, contribute, etc.
* Generate Sphinx docs
* Mirror Sphinx docs to ReadTheDocs automatically
* ~~Generate Sphinx docs~~
* ~~Mirror Sphinx docs to ReadTheDocs automatically~~
* Put READMEs in sub-directories with code, e.g for Vsphere, Interfaces
* Spec writing guides, how much time it takes
* Overall tutorial walkthrough and usage guide
Expand All @@ -21,6 +21,7 @@ Documentation for vSphere is [here](https://pubs.vmware.com/vsphere-60/index.jsp
* Add stuff from thesis/paper
* Triple/quadruple nested folder exercise example
* Logo or icon image for the project
* Insert terminology definitions and links into docs, e.g "Master", "Template", etc.


# Specs
Expand Down
2 changes: 1 addition & 1 deletion adles/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

__version__ = "1.1.11"
__version__ = "1.1.12"
__author__ = "Christopher Goes"
__email__ = "<[email protected]>"
__license__ = "Apache 2.0"
Expand Down
22 changes: 15 additions & 7 deletions adles/interfaces/docker_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
try:
import docker
except ImportError:
logging.error("Could not import docker module. Install it using 'pip install docker'")
logging.error("Could not import docker module. "
"Install it using 'pip install docker'")
exit(0)

import adles.utils as utils
Expand All @@ -36,7 +37,8 @@ def __init__(self, infra, spec):
:param dict spec: Dict of a parsed specification
"""
self._log = logging.getLogger('DockerInterface')
self._log.debug("Initializing DockerInterface %s", DockerInterface.__version__)
self._log.debug("Initializing DockerInterface %s",
DockerInterface.__version__)

self.infra = infra
self.spec = spec
Expand All @@ -45,10 +47,14 @@ def __init__(self, infra, spec):
self.networks = spec["networks"]
self.folders = spec["folders"]

# If needed, a wrapper class that simplifies the creation of containers will be made
# Reference: https://docker-py.readthedocs.io/en/stable/client.html#client-reference
# If needed, a wrapper class that simplifies
# the creation of containers will be made
# Reference:
# https://docker-py.readthedocs.io/en/stable/client.html#client-reference
# Initialize the Docker client
self.client = docker.DockerClient(base_url=infra.get("url", "unix:///var/run/docker.sock"),
self.client = docker.DockerClient(base_url=infra.get("url",
"unix:///var/run/"
"docker.sock"),
tls=bool(infra.get("tls", True)))

# Verify the connection to the client
Expand All @@ -61,7 +67,8 @@ def __init__(self, infra, spec):
if "registry" in self.infra:
reg = self.infra["registry"]
reg_logins = utils.read_json(reg["login-file"])
self.client.login(username=reg_logins["user"], password=reg_logins["pass"],
self.client.login(username=reg_logins["user"],
password=reg_logins["pass"],
registry=reg["url"])

# List images currently on the server
Expand All @@ -83,4 +90,5 @@ def __str__(self):
return str(self.client.info() + "\nVersion:\t" + self.client.version())

def __eq__(self, other):
return super(DockerInterface, self).__eq__(other) and self.client == other.client
return super(DockerInterface, self).__eq__(other) \
and self.client == other.client
66 changes: 44 additions & 22 deletions adles/interfaces/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def __init__(self, infra, spec):
self.thresholds = {} # Thresholds for platforms
self.groups = {} # Groups for platforms

# Select the Interface to use based on the specified infrastructure platform
# Select the Interface to use based on
# the specified infrastructure platform
for platform, config in infra.items():
if platform == "vmware-vsphere":
from .vsphere_interface import VsphereInterface
Expand All @@ -55,41 +56,47 @@ def __init__(self, infra, spec):

@time_execution
def create_masters(self):
""" Master creation phase """
""" Master creation phase. """
self._log.info("Creating Master instances for %s", self.metadata["name"])
for i in self.interfaces:
i.create_masters()

@time_execution
def deploy_environment(self):
""" Environment deployment phase """
""" Environment deployment phase. """
self._log.info("Deploying environment for %s", self.metadata["name"])
for i in self.interfaces:
i.deploy_environment()

@time_execution
def cleanup_masters(self, network_cleanup=False):
"""
Cleans up master instances
:param bool network_cleanup: If networks should be cleaned up [default: False]
Cleans up master instances.
:param bool network_cleanup: If networks should be cleaned up
[default: False]
"""
self._log.info("Cleaning up Master instances for %s", self.metadata["name"])
self._log.info("Cleaning up Master instances for %s",
self.metadata["name"])
for i in self.interfaces:
i.cleanup_masters(network_cleanup=network_cleanup)

@time_execution
def cleanup_environment(self, network_cleanup=False):
"""
Cleans up a deployed environment
:param bool network_cleanup: If networks should be cleaned up [default: False]
Cleans up a deployed environment.
:param bool network_cleanup: If networks should be cleaned up
[default: False]
"""
self._log.info("Cleaning up environment for %s", self.metadata["name"])
for i in self.interfaces:
i.cleanup_masters(network_cleanup=network_cleanup)

def _instances_handler(self, spec, obj_name, obj_type):
"""
Determines number of instances and optional prefix using specification
Determines number of instances and optional prefix using specification.
:param dict spec: Dict of folder
:param str obj_name: Name of the thing being handled
:param str obj_type: Type of the thing being handled (folder | service)
Expand All @@ -112,23 +119,30 @@ def _instances_handler(self, spec, obj_name, obj_type):
# if num < 1:
num = 1 # WORKAROUND FOR AD-GROUPS
else:
self._log.error("Unknown instances specification: %s", str(spec["instances"]))
self._log.error("Unknown instances specification: %s",
str(spec["instances"]))
num = 0

# Check if the number of instances exceeds the configured thresholds for the interface
# Check if the number of instances exceeds
# the configured thresholds for the interface
thr = self.thresholds[obj_type]
if num > thr["error"]:
self._log.error("%d instances of %s '%s' is beyond the configured %s threshold of %d",
num, obj_type, obj_name, self.__name__, thr["error"])
self._log.error("%d instances of %s '%s' is beyond the "
"configured %s threshold of %d",
num, obj_type, obj_name,
self.__name__, thr["error"])
raise Exception("Threshold exceeded")
elif num > thr["warn"]:
self._log.warning("%d instances of %s '%s' is beyond the configured %s threshold of %d",
num, obj_type, obj_name, self.__name__, thr["warn"])
self._log.warning("%d instances of %s '%s' is beyond the "
"configured %s threshold of %d",
num, obj_type, obj_name,
self.__name__, thr["warn"])
return num, prefix

def _path(self, path, name):
"""
Generates next step of the path for deployment of Masters
Generates next step of the path for deployment of Masters.
:param str path: Current path
:param str name: Name to add to the path
:return: The updated path
Expand All @@ -139,7 +153,8 @@ def _path(self, path, name):
@staticmethod
def _is_enabled(spec):
"""
Determines if a spec is enabled
Determines if a spec is enabled.
:param dict spec: Specification to check
:return: If the spec is enabled
:rtype: bool
Expand All @@ -151,7 +166,8 @@ def _is_enabled(spec):

def _determine_net_type(self, network_label):
"""
Determines the type of a network
Determines the type of a network.
:param str network_label: Name of network to determine type of
:return: Type of the network ("generic-networks" | "unique-networks")
:rtype: str
Expand All @@ -165,7 +181,9 @@ def _determine_net_type(self, network_label):

def _get_group(self, group_name):
"""
Provides a uniform way to get information about normal groups and template groups
Provides a uniform way to get information about normal groups
and template groups.
:param str group_name: Name of the group
:return: Group object
:rtype: :class:`Group`
Expand All @@ -178,12 +196,15 @@ def _get_group(self, group_name):
elif isinstance(group, list): # Template groups
return group[0]
else:
self._log.error("Unknown type for group '%s': %s", str(group_name), str(type(group)))
self._log.error("Unknown type for group '%s': %s",
str(group_name), str(type(group)))
else:
self._log.error("Could not get group '%s' from groups", group_name)

def __repr__(self):
return "%s(%s, %s)" % (str(self.__class__), str(self.spec), str(self.infra))
return "%s(%s, %s)" % (str(self.__class__),
str(self.spec),
str(self.infra))

def __str__(self):
return str([x for x in self.infra.keys()])
Expand All @@ -192,7 +213,8 @@ def __hash__(self):
return hash(str(self))

def __eq__(self, other):
return isinstance(other, self.__class__) and self.infra == other.infra and \
return isinstance(other, self.__class__) and \
self.infra == other.infra and \
self.spec == other.spec

def __ne__(self, other):
Expand Down
Loading

0 comments on commit cb4cf87

Please sign in to comment.