Esempio n. 1
0
def reset_landscape_server():
    """
    Resets the landscaper server connection back to the one specified in the
    config file.
    """
    global HOST, PORT

    HOST = config.get("LANDSCAPE", "host")
    PORT = config.get("LANDSCAPE", "port")
Esempio n. 2
0
def get_telemetry(telemetry=None, host=None, port=None):
    """
    Factory function which returns a telemetry class either using the arguments
    provided or from a configuration file.
    :param telemetry: The string name of the telemetry class to return.
    :param host: IP of the telemetry server.
    :param port: Port for the telemetry server
    :return: A telemetry class derived from the Telemetry abstract class.
    """
    if not telemetry:
        telemetry = ConfigHelper.get("DEFAULT", "telemetry")

    if telemetry == "snap":
        LOG.debug('snap telemetry')
        host = ConfigHelper.get('SNAP', 'host')
        port = ConfigHelper.get('SNAP', 'port')
        user = ConfigHelper.get('SNAP', 'user')
        password = ConfigHelper.get('SNAP', 'password')
        dbname = ConfigHelper.get('SNAP', 'dbname')
        return Snap(host, port, user, password, dbname)
    elif telemetry == "prometheus":
        LOG.debug('prometheus telemetry')
        host = ConfigHelper.get('PROMETHEUS', 'PROMETHEUS_HOST')
        port = ConfigHelper.get('PROMETHEUS', 'PROMETHEUS_PORT')
        return (host, port)
    else:
        msg = "No telemetry class for the type: {}".format(telemetry)
        raise AttributeError(msg)
Esempio n. 3
0
def get_info_graph(info_graph=None, landscape=None):
    """
    Factory function which returns an info graph class either using the
    arguments provided or from a configuration file.
    :param info_graph: The name of the info graph to use.
    :param landscape: A graph of the landscape.
    :return: Returns info graph based on the infograph type supplied either
    directly or from the INI file.
    """
    if not info_graph:
        info_graph = ConfigHelper.get("DEFAULT", "iaas")

    if info_graph == "openstack":
        return OpenStackInfoGraph(landscape)
    else:
        msg = "No infograph subclass for type {}".format(info_graph)
        raise AttributeError(msg)
Esempio n. 4
0
"""
Graph Database Base class and factory.
"""
import time
import requests
from networkx.readwrite import json_graph
from config_helper import ConfigHelper as config
import infograph
import json
import os
import analytics_engine.common as common

LOG = common.LOG
# HOST = '10.1.24.14'
# PORT = 9001
config.get("LANDSCAPE", "host")
config.get("LANDSCAPE", "port")

def get_graph():
    """
    Retrieves the entire landscape graph.
    :return: Landscape as a networkx graph.
    """
    landscape = _get("/graph")
    landscape.raise_for_status()  # Raise an exception if we get an error.

    nx_graph = json_graph.node_link_graph(landscape.json())
    return infograph.get_info_graph(landscape=nx_graph)


def get_subgraph(node_id, timestamp=None, timeframe=0):
Esempio n. 5
0
import os
import time
import datetime
import requests
from werkzeug.utils import secure_filename
try:
    from ..model.wallpapers_model import wallpapers as wallpapers_table
    from ..config_helper import ConfigHelper
except:
    import sys
    sys.path.append('../')
    sys.path.append('../../')
    from config_helper import ConfigHelper
    from model.wallpapers_model import wallpapers as wallpapers_table

WALLPAPERS_PATH = ConfigHelper.get('BASE_PATH') + '/wallpapers/'

base_url = "https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=2"
r = requests.get(base_url)
url = 'https://www.bing.com' + r.json()['images'][0]['url'].split('&')[0]
date_raw = str(r.json()['images'][0]['startdate'])
date = date_raw[:4] + '-' + date_raw[4:6] + '-' + date_raw[6:]
copyright = r.json()['images'][0]['copyright']
copyrightlink = r.json()['images'][0]['copyrightlink']

img_data = requests.get(url=url).content

folder_path = WALLPAPERS_PATH
if not os.path.exists(folder_path):
    os.makedirs(folder_path)
filename = str(date) + '.jpg'