Skip to content
Open
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
1 change: 1 addition & 0 deletions .prospector.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
strictness: veryhigh
test-warnings: true
ignore-paths:
- marmoset/virt/
Expand Down
1 change: 1 addition & 0 deletions marmoset.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
"""TODO: Docstring."""

# pylint: disable-msg=import-self
import marmoset
Expand Down
1 change: 1 addition & 0 deletions marmoset/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@


def run(config_file=None):
"""Run the thing."""
cfg = config.load_config(config_file)
cli.parse(cfg)
4 changes: 2 additions & 2 deletions marmoset/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from . import config, webserver

config = config.load_config()
CONFIG = config.load_config()

app = webserver.app(config)
APP = webserver.app(config)
2 changes: 1 addition & 1 deletion marmoset/cli/installstatus_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def add_to(parser, name, **kwargs):
"""
Update the CLI parser to support installimage status updates and stats.

supports a lot of information based on a UUID. For example a list of
Supports a lot of information based on a UUID. For example a list of
all status updates a UUID got, the last update it got or some stats for it.
"""
command = parser.add_parser(name, **kwargs)
Expand Down
22 changes: 18 additions & 4 deletions marmoset/dhcp/dhcp_config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""TODO: module docstring."""
from marmoset import config as config_reader
from marmoset import validation
from .isc_dhcp_ldap_config import ISCDhcpLdapConfig

config = config_reader.load_config()

CONFIG = config_reader.load_config()


class DhcpConfig:
Expand All @@ -27,13 +29,15 @@ def set_settings(
ip_address=None,
gateway=None,
networkmask=None):
"""TODO: docstring."""
# pylint: disable-msg=too-many-arguments
self.mac = mac

if gateway is not None or allow_none_value_for_not_required_parameter:
self.gateway = gateway

if networkmask is not None or allow_none_value_for_not_required_parameter:
if networkmask is not None \
or allow_none_value_for_not_required_parameter:
self.networkmask = networkmask

if validation.is_cidr(ip_address):
Expand All @@ -42,49 +46,59 @@ def set_settings(
if self.networkmask is None:
self.networkmask = validation.get_nm_from_cidr(ip_address)

if self.gateway is None and config[
if self.gateway is None and CONFIG[
'DHCPConfig'].getboolean('force_gateway'):
self.gateway = validation.get_gw_from_cidr(ip_address)
else:
self.ip_address = ip_address

self.dhcp_hostname = config['Common'].get('FQDN')
self.dhcp_hostname = CONFIG['Common'].get('FQDN')

def add_additional_statement(self, key, value):
"""TODO: docstring."""
self.additional_statements[key] = value

def create_isc_ldap(self):
"""TODO: docstring."""
isc_dhcp_config = ISCDhcpLdapConfig(self)
isc_dhcp_config.save()

def remove_by_ipv4(self):
"""TODO: docstring."""
return ISCDhcpLdapConfig.remove_by_ipv4(self.ip_address) > 0

def remove_by_mac(self):
"""TODO: docstring."""
return ISCDhcpLdapConfig.remove_by_mac(self.mac) > 0

def remove_all(self):
"""TODO: docstring."""
ipv4_removed_count = ISCDhcpLdapConfig.remove_by_ipv4(self.ip_address)
mac_removed_count = ISCDhcpLdapConfig.remove_by_mac(self.mac)

return (ipv4_removed_count + mac_removed_count) > 0

@staticmethod
def all():
"""TODO: docstring."""
return ISCDhcpLdapConfig.get_all_db_entries()

@staticmethod
def get_by_ip(ip_address):
"""TODO: docstring."""
return ISCDhcpLdapConfig.get_by_ip(ip_address)

@staticmethod
def get_by_mac(mac):
"""TODO: docstring."""
return ISCDhcpLdapConfig.get_by_mac(mac)

@staticmethod
def exists_ipv4(ip_address):
"""TODO: docstring."""
return ISCDhcpLdapConfig.get_by_ip(ip_address) is not None

@staticmethod
def exists_mac(mac_address):
"""TODO: docstring."""
return ISCDhcpLdapConfig.get_by_mac(mac_address) is not None
20 changes: 10 additions & 10 deletions marmoset/dhcp/isc_dhcp_ldap_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from marmoset import config as config_reader
from marmoset import validation

config = config_reader.load_config()
CONFIG = config_reader.load_config()


class ISCDhcpLdapConfig:
Expand All @@ -21,13 +21,13 @@ def __init__(self, dhcp_config):

@staticmethod
def __get_server_connection():
server = Server(config['DHCPConfig'].get('ldap_server'),
port=int(config['DHCPConfig'].get('ldap_port')),
server = Server(CONFIG['DHCPConfig'].get('ldap_server'),
port=int(CONFIG['DHCPConfig'].get('ldap_port')),
get_info=ALL)

conn = Connection(server,
config['DHCPConfig'].get('ldap_bind_dn'),
config['DHCPConfig'].get('ldap_passwort'),
CONFIG['DHCPConfig'].get('ldap_bind_dn'),
CONFIG['DHCPConfig'].get('ldap_passwort'),
auto_bind=True)

return conn
Expand Down Expand Up @@ -55,7 +55,7 @@ def save(self):
self.dhcp_config.dhcp_hostname)
}

conn.add("cn=%s,%s" % (self.dhcp_config.ip_address, config['DHCPConfig'].get('ldap_client_base_dn')),
conn.add("cn=%s,%s" % (self.dhcp_config.ip_address, CONFIG['DHCPConfig'].get('ldap_client_base_dn')),
'dhcpHost',
entry_attributes)

Expand All @@ -65,7 +65,7 @@ def get_all_db_entries():
conn = ISCDhcpLdapConfig.__get_server_connection()

entry_generator = conn.extend.standard.paged_search(
search_base=config['DHCPConfig'].get('ldap_client_base_dn'),
search_base=CONFIG['DHCPConfig'].get('ldap_client_base_dn'),
search_filter='(objectClass=dhcpHost)',
search_scope=SUBTREE,
attributes=['cn'],
Expand All @@ -84,7 +84,7 @@ def __get_dn_by_ipv4(ip_address, multi=False):
"""Get a DN for a certain entry based on the provided ipv4 address."""
conn = ISCDhcpLdapConfig.__get_server_connection()
conn.search(
search_base=config['DHCPConfig'].get('ldap_client_base_dn'),
search_base=CONFIG['DHCPConfig'].get('ldap_client_base_dn'),
search_filter='(cn=%s)' %
ip_address,
search_scope=SUBTREE,
Expand Down Expand Up @@ -114,7 +114,7 @@ def __get_dn_by_mac(mac_address, multi=False):
"""Get a DN for a certain entry based on the provided MAC address."""
conn = ISCDhcpLdapConfig.__get_server_connection()
conn.search(
search_base=config['DHCPConfig'].get('ldap_client_base_dn'),
search_base=CONFIG['DHCPConfig'].get('ldap_client_base_dn'),
search_filter='(dhcpHWAddress=ethernet %s)' %
mac_address,
search_scope=SUBTREE,
Expand Down Expand Up @@ -178,7 +178,7 @@ def __get_dhcp_config(distinguished_name):

dhcp_config = DhcpConfig(mac, ip_address, gateway, networkmask)

additional_statements = config['DHCPConfig'].get('additional_statements').split(',')
additional_statements = CONFIG['DHCPConfig'].get('additional_statements').split(',')

for ldap_additional_statement in entries[
0]['attributes']['dhcpStatements']:
Expand Down
2 changes: 1 addition & 1 deletion marmoset/imagecatalog/catalog.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Module for listing all images."""
from .image import Image
import glob
import os
from .image import Image


class ImageCatalog:
Expand Down
8 changes: 4 additions & 4 deletions marmoset/imagecatalog/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def size_mb(self):
def metadata(self):
metadata = {}
try:
with open(self.metadata_path, "r") as f:
parsed_yaml = yaml.load(f)
with open(self.metadata_path, "r") as in_file:
parsed_yaml = yaml.load(in_file)
except (yaml.scanner.ScannerError, yaml.YAMLError, OSError, IOError):
parsed_yaml = {}
finally:
Expand Down Expand Up @@ -71,8 +71,8 @@ def metadata(self):
def signature(self):
signature_path = self.image_path + ".sig"
try:
with open(signature_path, "r") as f:
signature = f.read()
with open(signature_path, "r") as in_file:
signature = in_file.read()
except (IOError, OSError, UnicodeDecodeError):
signature = None
return signature
4 changes: 3 additions & 1 deletion marmoset/installimage/req_argument_parser.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""Simple module to get access to data from an http request."""


# pylint: disable=too-few-public-methods
class ReqArgumentParser:
"""Simple class to get access to data from an http request."""

def parse_args(self, req):
@staticmethod
def parse_args(req):
"""Parse arguments from a request."""
return req.form
6 changes: 3 additions & 3 deletions marmoset/installstatus/db_helper.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Module to provide a database wrapper for installimage status."""
from marmoset import config as config_reader
import sqlite3
from marmoset import config as config_reader


config = config_reader.load_config()
DB = config['Installstatus'].get('SQLiteDB')
CONFIG = config_reader.load_config()
DB = CONFIG['Installstatus'].get('SQLiteDB')


class DBHelper:
Expand Down
29 changes: 15 additions & 14 deletions marmoset/installstatus/installstatus.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
"""Module to handle everything related to installimage status."""
import datetime
from marmoset import config as config_reader
from .db_helper import DBHelper
import datetime

config = config_reader.load_config()
CONFIG = config_reader.load_config()


def convert_date(date_string):
"""
Convert the date string from database to datetime object.

:param date_string:
:return: datetime
"""
date = datetime.datetime.strptime(date_string, '%Y-%m-%d %H:%M:%S')
return date


class InstallStatus:
Expand Down Expand Up @@ -62,8 +73,8 @@ def get_stats(self):
stats['end_date'] = status_history[-1]['date']
stats['latest_status_code'] = status_history[-1]['status_code']
stats['total_steps'] = status_history[-1]['total_steps']
datetime_start = self.convert_date(stats['start_date'])
datetime_end = self.convert_date(stats['end_date'])
datetime_start = convert_date(stats['start_date'])
datetime_end = convert_date(stats['end_date'])
duration = datetime_end - datetime_start
duration = duration.total_seconds()
stats['installation_duration'] = int(duration)
Expand All @@ -81,13 +92,3 @@ def get_stats(self):
stats['status_updates'] = history_count
stats['uuid'] = self.uuid
return stats

def convert_date(self, date_string):
"""
Convert the date string from database to datetime object.

:param date_string:
:return: datetime
"""
date = datetime.datetime.strptime(date_string, '%Y-%m-%d %H:%M:%S')
return date
Loading