def __init__(self, portal): """ Initialize the portal template class. """ self.portal = portal # Shared modules self.json = json self.base64 = base64 self.OrderedDict = OrderedDict # Configuration / logger self.conf = config.parse() self.log = logger.create(__name__, self.conf.portal.log) # URL panel self.panel = self.get_query_key('panel') # Threaded API responses self._response = {} # Template data self._tdata = {} # Response filter self.filter = APIFilter()
def __init__(self, error=None, status=500, exception=False): # Configuration / logger self.conf = config.parse() self.log = logger.create(__name__, self.conf.server.log) # Store the response status code self.status = status # Construct the JSON error object self.error_object = { 'message': ERR_MESSAGE.get(self.status, 'An unknown error has occurred, please contact your administrator'), 'code': self.status, 'error': error if not isinstance(error, (list, dict)) else json.dumps(error) } # If an error message is provided if error and isinstance(error, (str, unicode, basestring)): self.log.error(error) # If providing a stack trace for debugging and debugging is enabled if exception and self.conf.server.debug: self.error_object.update({ 'debug': self._extract_trace() })
def __init__(self, transport, buff_size=16384, socket_timeout=5.0, progress=None, sanitize=_sh_quote): # Config / logger self.conf = config.parse() self.log = logger.create(__name__, self.conf.server.log) """ Create an scp1 client. @param transport: an existing paramiko L{Transport} @type transport: L{Transport} @param buff_size: size of the scp send buffer. @type buff_size: int @param socket_timeout: channel socket timeout in seconds @type socket_timeout: float @param progress: callback - called with (filename, size, sent) during transfers @param sanitize: function - called with filename, should return safe or escaped string. Uses _sh_quote by default. @type progress: function(string, int, int) """ self.transport = transport self.buff_size = buff_size self.socket_timeout = socket_timeout self.channel = None self.preserve_times = False self._progress = progress self._recv_dir = '' self._rename = False self._utime = None self.sanitize = sanitize self._dirtimes = {}
def __init__(self): # Configuration / logger objects self.conf = config.parse() self.log = logger.create(__name__, self.conf.utils.log) # Cache manager self.cache = CacheManager()
def __init__(self): # Target filter object / filter map self._object = None # Configuration / logger self.conf = config.parse() self.log = logger.create(__name__, self.conf.portal.log)
def __init__(self): # Configuration / logger self.conf = config.parse() self.log = logger.create(__name__, self.conf.server.log) # SocketIO client / web socket parameters self.socket_io = None self.web_socket = None
def __init__(self, args): # Configuration / logger / feedback handler self.conf = config.parse() self.log = logger.create(__name__, self.conf.server.log) self.fb = Feedback() # Actions mapper self.actions = { 'start': self._start, 'stop': self._stop, 'restart': self._restart, 'status': self._status } # Services mapper self.services = { 'portal': { 'apache': True, 'label': 'portal' }, 'api': { 'apache': True, 'label': 'API server' }, 'socket': { 'apache': False, 'pid': self.conf.socket.pid, 'label': 'API socket proxy', 'start': ['nohup', 'node', self.conf.socket.exe, self.conf.socket.host, self.conf.socket.port, self.conf.socket.proto ] }, 'scheduler': { 'apache': False, 'pid': self.conf.scheduler.pid, 'label': 'API scheduler', 'start': ['nohup', 'python', self.conf.scheduler.exe ] } } # Target action / service self.action = None self.service = None # Argument parser self.ap = self._parse_args(args) # Server distribution and Apache service name self.distro = platform.linux_distribution()[0]
def __init__(self, args): """ Initialize the schedule manager and store any command line arguments. """ # Configuration / logger self.conf = config.parse() self.log = logger.create(__name__, self.conf.scheduler.log) # Modules / threads self.modules = {} self.threads = [] # Load all scheduler modules self._load_modules()
def __init__(self, child): """ Class constructor. :param child: Child class object :type child: class object """ # Define the logger name log_name = '%s.%s' % (__name__, child.__class__.__name__) # Running utilities on the server if os.path.isfile(S_CONF): self.conf = config.parse() self.log = logger.create(log_name, self.conf.utils.log) # Agent Configuration elif (os.path.isfile(A_CONF)): self.conf = AgentConfig().get() self.log = logger.create(log_name, self.conf.agent.log) # Raise an exception if neither the server nor agent configuration is found else: raise Exception('Could not locate the server or agent configuration')
def __init__(self): self.feedback = Feedback() # Configuration / logger self.conf = config.parse() self.log = logger.create('bootstrap', '%s/log/bootstrap.log' % L_BASE) # Bootstrap parameters self.params = BootstrapParams() # Server configuration file self.server_conf = self.params.file['config']['server_conf'][1] # Database connection self._connection = None
def __init__(self, name): self.class_name = 'cloudscape' if not name else name # Authentication flag self.authenticated = False # Raw request self.request_raw = None # Request / API objects / application controllers self.request = None self.api = None self.controller = {} # User object self.user = {} # Initialize the configuration object and logger self.conf = config.parse() self.log = logger.create(self.class_name, self.conf.portal.log)
def __init__(self, name): # Module name self.name = name # Configuration and logger self.conf = config.parse() self.log = logger.create(name, self.conf.scheduler.log) # Internal API user / token self.api_user = None self.api_group = None self.api_token = None # Time / datetime / JSON module self.time = time self.datetime = datetime self.json = json # Endpoints self.endpoints = self._load_endpoints() # Module initialized self.log.info('Initialized scheduler module: %s' % name)
def __init__(self, name=None, endpoint=None, utils=False, acl=None): """ Initialize the APIBase class. @param name: The module name used for the logger @type name: str @param endpoint: The endpoint being accessed @type endpoint: str @param utils: Any external utilities required by this API endpoint @type utils: list @param acl: The ACL gateway generated during request initialization @type acl: ACLGateway @param cache: The CacheManager class instance @param cache: CacheManager """ # Class base / configuration / internal logger self.class_name = __name__ if not name else name self.conf = config.parse() self.log_int = logger.create(self.class_name, self.conf.server.log) # External utilities / utilities object / cache manager / objects manager / ACL gateway self.utils = utils self.util = None self.cache = CacheManager() self.objects = ObjectsManager() self.acl = acl # SocketIO client / Cache Manager self.socket = SocketResponse().construct() # Request attributes self.request_raw = None # Raw request object self.action = None # Request action self.data = None # Any request data self.endpoint = endpoint # Request endpoint
""" SCP_STATUS = { 0: 'Success', 1: 'End of file', 2: 'File not found', 3: 'Permission denied', 4: 'Failure', 5: 'Bad message', 6: 'No connection', 7: 'Connection lost', 8: 'Operation unsupported' } # Configuration and logger objects CONFIG = AgentConfig().get() LOG = logger.create('cloudscape.agent.win.scp', CONFIG.log.sshd) """ SCP Exception """ class SCPException(Exception): def __init__(self, status, message): self.status = status super(Exception, self).__init__(message) """ SCP Server Base class for the SCPInterface, used to handle sending and receiving data from the SCP client. """ class SCPServer:
from cloudscape.common.vars import A_RUNNING, A_ERROR, A_STOPPED, \ C_HOME, C_BASE, A_PID, A_CFLAG, A_START, A_STOP, A_RESTART, A_STATUS, \ A_EXECPKG, A_EXECPY, A_EXECWIN, A_SYSINFO, FORMULA_DIR # CloudScape Libraries from cloudscape.common import logger from cloudscape.common.utils import format_action from cloudscape.common.feedback import Feedback from cloudscape.client.manager import APIConnect from cloudscape.agent.config import AgentConfig from cloudscape.agent.linux.collector import AgentCollector from cloudscape.agent.formula import AgentFormulaExec, AgentFormulaParse # Configuration and logger objects CONFIG = AgentConfig().get() LOG = logger.create('cloudscape.agent.linux.api', CONFIG.log.agent) """ CloudScape Agent Handler Class """ class AgentHandler: def __init__(self, args=None): # API connection and client attributes self.api = None self.client = None # Set the any passed arguments and the arguments parser self.args = args self.ap = self._set_args()
# CloudScape Libraries from cloudscape.common import config from cloudscape.common import logger from cloudscape.common.vars import T_BASE from cloudscape.engine.api.base import APIBase from cloudscape.common.utils import JSONTemplate from cloudscape.engine.api.auth.key import APIKey from cloudscape.engine.api.auth.acl import ACLGateway from cloudscape.common.utils import valid, invalid from cloudscape.engine.api.auth.token import APIToken from cloudscape.engine.api.app.auth.models import DBAuthEndpoints from cloudscape.engine.api.app.user.models import DBUserDetails # Configuration / Logger CONF = config.parse() LOG = logger.create('cloudscape.engine.api.core.request', CONF.server.log) def dispatch(request): """ The entry point for all API requests. Called for all endpoints from the Django URLs file. Creates a new instance of the EndpointManager class, and returns any HTTP response to the client that opened the API request. :param request: The Django request object :type request: object :rtype: object """ try: # Return the response from the endpoint handler return EndpointManager(request).handler()
from cloudscape.common import config from cloudscape.common import logger from cloudscape.common.vars import T_BASE from cloudscape.engine.api.base import APIBase from cloudscape.common.http import HEADER, PATH, JSONError, JSONException, HTTP_GET from cloudscape.common.utils import JSONTemplate from cloudscape.engine.api.auth.key import APIKey from cloudscape.common.utils import valid, invalid, truncate from cloudscape.engine.api.auth.acl import ACLGateway from cloudscape.engine.api.auth.token import APIToken from cloudscape.engine.api.app.user.models import DBUser from cloudscape.engine.api.app.gateway.models import DBGatewayUtilities # Configuration / Logger CONF = config.parse() LOG = logger.create(__name__, CONF.server.log) def dispatch(request): """ The entry point for all API requests. Called for all endpoints from the Django URLs file. Creates a new instance of the EndpointManager class, and returns any HTTP response to the client that opened the API request. :param request: The Django request object :type request: object :rtype: object """ try: # Return the response from the request manager return RequestManager(request).handler()
import win32pdh import platform import netifaces from datetime import timedelta # CloudScape Libraries from cloudscape.common import logger from cloudscape.common.collection import Collection from cloudscape.agent.config import AgentConfig # CloudScape Libraries from cloudscape.agent.win.collector.base import CollectorBase # Configuration and logger objects CONFIG = AgentConfig().get() LOG = logger.create('cloudscape.agent.win.collector', CONFIG.log.agent) """ Windows Collector Interface """ class CollectorInterface(CollectorBase): # Class constructor def __init__(self): super(CollectorInterface, self).__init__() """ Define Partition Name """ def _part_name(self, part): if part['properties']['Bootable']: return 'BOOT' else:
from cloudscape.common import config from cloudscape.common import logger from cloudscape.common.http import HEADER, PATH from cloudscape.common.utils import invalid, valid from cloudscape.common.vars import T_USER, T_HOST from cloudscape.common.collection import Collection from cloudscape.engine.api.objects.manager import ObjectsManager from cloudscape.engine.api.app.user.models import DBUser from cloudscape.engine.api.app.group.models import DBGroupDetails, DBGroupMembers from cloudscape.engine.api.app.gateway.models import DBGatewayACLAccessGlobal, DBGatewayACLAccessObject, \ DBGatewayUtilities, DBGatewayACLKeys, \ DBGatewayACLObjects # Configuration / Logger / Objects Manager CONF = config.parse() LOG = logger.create('cloudscape.engine.api.auth.acl', CONF.server.log) OBJECTS = ObjectsManager() def get_obj_def(obj_type): """ Retrieve the object definition for a specific type. """ return [x for x in list(DBGatewayACLObjects.objects.all().values()) if x['type'] == obj_type][0] class ACLAuthObjects(object): """ Parent class used to construct a list of objects that a user is authorized to access. """ def __init__(self, user, obj_type, path, method): # ACL user object / object type / object utility / cache manager
import sys import json import base64 import tarfile import subprocess # CloudScape Libraries from cloudscape.common import logger from cloudscape.common.vars import SYS_TYPE, FORMULA_DIR, FORMULA_LOG, np from cloudscape.common.utils import FileSec, pyexec from cloudscape.client.manager import APIConnect from cloudscape.agent.config import AgentConfig # Configuration and logger objects CONFIG = AgentConfig().get() LOG = logger.create('cloudscape.agent.formula', CONFIG.agent.log) """ Agent Formula Parser Privileged class file used to parse the result logs from a formula package run. Looks for either a successful or failed package run, and reports back to the API server. """ class AgentFormulaParse(object): """ Parse Formula Results """ def parse(self): # Formula log files if not os.path.isdir(FORMULA_LOG): os.mkdir(FORMULA_LOG)
# Django Libraries from django.template import RequestContext, Context, loader from django.http import HttpResponse, HttpResponseServerError, HttpResponseRedirect # CloudScape Libraries from cloudscape.common import config from cloudscape.common import logger from cloudscape.common.vars import L_BASE from cloudscape.portal.ui.base import PortalBase # Module class name MOD_CLASS = 'AppModule' # Configuration / Logger CONF = config.parse() LOG = logger.create(__name__, CONF.portal.log) def dispatch(request): """ Method used to handle incoming portal requests. """ try: # Return the response from the endpoint handler return RequestManager(request).handler() # Critical server error except Exception as e: LOG.exception('Internal server error: %s' % str(e)) # Get the exception data
import os import sys import time import atexit import string import random from importlib import import_module # CloudScape Libraries from cloudscape.common import logger from cloudscape.agent.config import AgentConfig # Configuration and logger CONFIG = AgentConfig().get() LOG = logger.create('cloudscape.agent.win.service', CONFIG.log.service) """ Process Base Class A class wrapper used to dynamically inherit the parent class of the process being spawned. """ def _process(base): class _Process(base): # Initialize the subprocess class def __init__(self, proc): super(_Process, self).__init__() LOG.info('[%s]: > Initializing process base class: _Process(%s)' % (proc['name'], proc['class'])) # Register the final exit function
def __init__(self): # Configuration / logger objects self.conf = config.parse() self.log = logger.create(__name__, self.conf.server.log)
from cloudscape.common.vars import W_BASE, W_HOME, L_BASE, L_HOME, F_INSTALL, F_UNINSTALL, \ F_UPDATE, A_LINUX, A_WINDOWS, F_MANAGED, F_UNMANAGED, np # CloudScape Libraries from cloudscape.common import logger from cloudscape.common import config from cloudscape.common.utils import valid, invalid from cloudscape.common.formatter import Formatter from cloudscape.common.collection import Collection from cloudscape.engine.api.core import host as host_utils from cloudscape.engine.api.app.host.models import DBHostDetails, DBHostGroups from cloudscape.engine.api.app.formula.models import DBFormulaDetails, DBFormulaTemplates # Configuration and logger objects CONFIG = config.parse() LOG = logger.create(__name__, CONFIG.utils.log) # Indent String def _i(s, t=0): tab = (' ' * 4) * t return '%s%s' % (tab, s) """ Formula Variable Mapper Merge globally defined variables with system and package parameters, and the runtime parameters supplied to the formula parser. Used when rendering templates, as well as when parsing out strings from formula manifest groups. """ class FormulaMap: def __init__(self, params, sys, pkg):