Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F11726255
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
12 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/_modules/convert.py b/_modules/convert.py
index d55800a..ed55a7e 100644
--- a/_modules/convert.py
+++ b/_modules/convert.py
@@ -1,36 +1,36 @@
# -*- coding: utf-8 -*-
# -------------------------------------------------------------
# Salt — Convert execution module
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Project: Nasqueron
# Created: 2018-09-08
# Description: Functions related to data format conversions
# License: BSD-2-Clause
# -------------------------------------------------------------
import json
def to_json_from_pillar_key(key):
- '''
+ """
A function to output a pillar key in JSON.
CLI Example::
salt-call --local convert.to_json "Hello world"
- '''
+ """
data = __pillar__.get(key, {})
return to_json(data)
def to_json(data):
- '''
+ """
A function to convert data to JSON.
CLI Example::
salt-call --local convert.to_json "Hello world"
- '''
+ """
return json.dumps(data, indent=4, sort_keys=True)
diff --git a/_modules/forest.py b/_modules/forest.py
index a7c4763..ad43079 100644
--- a/_modules/forest.py
+++ b/_modules/forest.py
@@ -1,105 +1,105 @@
# -*- coding: utf-8 -*-
# -------------------------------------------------------------
# Salt — Forest execution module
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Project: Nasqueron
# Created: 2017-10-11
# Description: Functions related to forests
# License: BSD-2-Clause
# -------------------------------------------------------------
def exists(forest):
- '''
+ """
A function to check if a forest exists.
CLI Example::
salt '*' forest.exists eglide
- '''
+ """
return forest in __pillar__.get('forests', [])
def get():
- '''
+ """
A function to get the forest of the current minion
CLI Example::
salt '*' forest.get
- '''
+ """
nodes = __pillar__.get('nodes')
minion = __grains__['id']
return nodes[minion]['forest']
def list_groups(forest=None):
- '''
+ """
A function to list groups for a forest.
CLI Example::
salt '*' forest.list_groups
- '''
+ """
if forest is None:
forest = get()
groups = __pillar__.get('shellgroups_ubiquity', [])
groupsByForest = __pillar__.get('shellgroups_by_forest', {})
if forest in groupsByForest:
groups.extend(groupsByForest[forest])
return groups
def get_groups(forest=None):
'''
A function to get groups for a forest as a dictionary,
including the group properties.
CLI Example::
salt '*' forest.get_groups
'''
groups = {}
for groupname in list_groups(forest):
groups[groupname] = __pillar__['shellgroups'][groupname]
return groups
def list_users(forest=None):
- '''
+ """
A function to list groups for a forest.
CLI Example::
salt '*' forest.list_users
- '''
+ """
users = []
for group in get_groups(forest).values():
if "members" in group:
users.extend(group['members'])
return list(set(users))
def get_users(forest=None):
- '''
+ """
A function to get users for a forest as a dictionary,
including the users properties.
CLI Example::
salt '*' forest.get_users
- '''
+ """
users = {}
for username in list_users(forest):
users[username] = __pillar__['shellusers'][username]
return users
diff --git a/_modules/jails.py b/_modules/jails.py
index 155e874..98dee0c 100644
--- a/_modules/jails.py
+++ b/_modules/jails.py
@@ -1,138 +1,138 @@
# -*- coding: utf-8 -*-
# -------------------------------------------------------------
# Salt — Jails execution module
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Project: Nasqueron
# Created: 2017-10-21
# Description: Functions related to FreeBSD jails
# License: BSD-2-Clause
# -------------------------------------------------------------
import errno
def _get_all_jails():
return __pillar__.get('jails', {})
def _get_default_group():
- '''
+ """
Gets the default group to use as key to
the pillar's jails dictionary.
- '''
+ """
return __grains__['id']
def list(group=None):
- '''
+ """
A function to list the jails for the specified group.
CLI Example::
salt '*' jails.list
- '''
+ """
all_jails = _get_all_jails()
if group is None:
group = _get_default_group()
if group in all_jails:
return all_jails[group]
return []
def flatlist(group=None):
- '''
+ """
A function to list the jails for the specified group.
Output is a string, ready to pass to jail_list in rc.
CLI Example::
salt-call --local jails.flatlist ysul
- '''
+ """
return " ".join(sorted(list(group)))
def _get_hardware_network_interfaces():
return [interface for interface in __grains__['hwaddr_interfaces']]
def _get_ipv6_network_interfaces():
return [interface for interface in __grains__['ip6_interfaces']]
def guess_ipv4_network_interface():
- '''
+ """
A function tu guess to what network interface bind the
public IPv4 jail IP.
- '''
+ """
interfaces = _get_hardware_network_interfaces()
if len(interfaces) < 1:
raise OSError(errno.ENODEV, "No network interface detected.")
# Nasqueron convention assigns the ICANNN network
# to the first card.
return interfaces[0]
def guess_ipv6_network_interface():
- '''
+ """
A function tu guess to what network interface bind the
public IPv6 jail IP.
- '''
+ """
interfaces = _get_ipv6_network_interfaces()
for interface in interfaces:
ips = __grains__['ip6_interfaces'][interface]
# We want an interface with IPv6
if len(ips) < 1:
continue
# Ignore local loopback
if interface.startswith("lo"):
continue
return interface
raise OSError(errno.EAFNOSUPPORT, "No network interface detected.")
def get(jailname, group=None):
- '''
+ """
A function to get a jail pillar configuration
CLI Example::
salt-call --local jails.get mumble ysul
- '''
+ """
if group is None:
group = _get_default_group()
all_jails = _get_all_jails()
return all_jails[group][jailname]
def get_ezjail_ips_parameter(jailname, group=None):
- '''
+ """
A function to get the parameters to describe the jail
IP configuration to `ezjail-admin create` command.
CLI Example::
salt * jails.get_ezjail_ips_parameter ftp
- '''
+ """
jail = get(jailname, group)
config = [
["lo1", jail['lo']],
[guess_ipv4_network_interface(), jail['ipv4']],
[guess_ipv6_network_interface(), jail['ipv6']]
]
return ",".join(["|".join(interface) for interface in config])
diff --git a/_modules/node.py b/_modules/node.py
index b1c0b58..3bde15b 100644
--- a/_modules/node.py
+++ b/_modules/node.py
@@ -1,208 +1,208 @@
# -*- coding: utf-8 -*-
# -------------------------------------------------------------
# Salt — Node execution module
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Project: Nasqueron
# Created: 2017-10-21
# Description: Functions related to the nodes pillar entry
# License: BSD-2-Clause
# -------------------------------------------------------------
from salt.exceptions import CommandExecutionError, SaltCloudConfigError
def _get_all_nodes():
return __pillar__.get('nodes', {})
def get_all_properties(nodename=None):
- '''
+ """
A function to get a node pillar configuration.
CLI Example:
salt * node.get_all_properties
- '''
+ """
if nodename is None:
nodename = __grains__['id']
all_nodes = _get_all_nodes()
if nodename not in all_nodes:
raise CommandExecutionError(
SaltCloudConfigError(
"Node {0} not declared in pillar.".format(nodename)
)
)
return all_nodes[nodename]
def get(key, nodename=None):
- '''
+ """
A function to get a node pillar configuration key.
CLI Example:
salt * node.get hostname
- '''
+ """
return _get_property(key, nodename, None)
def _explode_key(k): return k.split(':')
def _get_first_key(k): return _explode_key(k)[0]
def _strip_first_key(k): return ':'.join(_explode_key(k)[1:])
def _get_property(key, nodename, default_value, parent=None):
if parent is None:
parent = get_all_properties(nodename)
if ':' in key:
first_key = _get_first_key(key)
if first_key in parent:
return _get_property(
_strip_first_key(key), nodename,
default_value, parent[first_key]
)
elif key in parent:
return parent[key]
return default_value
def get_list(key, nodename=None):
- '''
+ """
A function to get a node pillar configuration.
Returns a list if found, or an empty list if not found.
CLI Example:
salt * node.list network:ipv4_aliases
- '''
+ """
return _get_property(key, nodename, [])
def has(key, nodename=None):
- '''
+ """
A function to get a node pillar configuration.
Returns a boolean, False if not found.
CLI Example:
salt * node.has network:ipv6_tunnel
- '''
+ """
value = _get_property(key, nodename, False)
return bool(value)
def has_role(role, nodename=None):
- '''
+ """
A function to determine if a node has the specified role.
Returns a boolean, False if not found.
CLI Example:
salt * node.has_role devserver
- '''
+ """
return role in get_list('roles', nodename)
def filter_by_role(pillar_key, nodename=None):
- '''
+ """
A function to filter a dictionary by roles.
The dictionary must respect the following structure:
- keys are role to check the current node against
- values are list of items
If a key '*' is also present, it will be included
for every role.
Returns a list, extending all the filtered lists.
CLI Example:
salt * node.filter_by_role web_content_sls
- '''
+ """
roles = get_list('roles', nodename)
dictionary = __pillar__.get(pillar_key, {})
filtered_list = []
for role, items in dictionary.items():
if role == '*' or role in roles:
filtered_list.extend(items)
return filtered_list
def filter_by_name(pillar_key, nodename=None):
- '''
+ """
A function to filter a dictionary by node name.
The dictionary must respect the following structure:
- keys are names to check the current node against
- values are list of items
If a key '*' is also present, it will be included
for every node.
Returns a list, extending all the filtered lists.
CLI Example:
salt * node.filter_by_name mars
- '''
+ """
if nodename is None:
nodename = __grains__['id']
dictionary = __pillar__.get(pillar_key, {})
filtered_list = []
for name, items in dictionary.items():
if name == '*' or name == nodename:
filtered_list.extend(items)
return filtered_list
def has_web_content(content, nodename=None):
return content in filter_by_role('web_content_sls', nodename)
def get_wwwroot(nodename=None):
- '''
+ """
A function to determine the wwwroot folder to use.
Returns a string depending of the FQDN.
CLI Example:
salt * node.get_wwwroot
- '''
+ """
hostname = _get_property("hostname", nodename, None)
if hostname is None:
raise CommandExecutionError(
SaltCloudConfigError(
"Node {0} doesn't have a hostname property".format(nodename)
)
)
if hostname.count('.') < 2:
return "wwwroot/{0}/www".format(hostname)
fqdn = hostname.split(".")
return "wwwroot/{1}/{0}".format(
".".join(fqdn[0:-2]),
".".join(fqdn[-2:])
)
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Fri, Sep 19, 02:04 (1 d, 12 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2992048
Default Alt Text
(12 KB)
Attached To
Mode
rOPS Nasqueron Operations
Attached
Detach File
Event Timeline
Log In to Comment