Ejemplo n.º 1
0
def url_serve_file(handler,
                   server_name,
                   url_function,
                   module=None,
                   args=[],
                   kwargs={}):
    """Serves a file by utilizing a url. The server must have a function which returns the url. This will call that function with the supplied args and kwargs. """
    datastore_handler = handler.datastore_handler
    server_info = yield apps.get_app_info(server_name)
    state = server_info['role']

    states = yield datastore_handler.get_states_and_apps()
    state = [x for x in states if x['name'] == state] or [{
        'module': 'openvpn'
    }]
    state = state[0]

    if not module:
        module = state['module']

    cl = salt.client.LocalClient()
    url = cl.cmd(server_name,
                 module + '.' + url_function,
                 arg=args,
                 kwarg=kwargs).get(server_name)

    yield handler.serve_file('test', url_source=url)
    raise tornado.gen.Return({"data_type": "file"})
Ejemplo n.º 2
0
def salt_serve_file(handler,
                    server_name,
                    action,
                    args=[],
                    dash_user='',
                    kwargs={},
                    module=None):
    """Serves a file by using a salt module. The module function but be able to be called with range_from and range_to arguments. """
    datastore_handler = handler.datastore_handler
    server_info = yield apps.get_app_info(server_name)
    state = server_info['role']

    states = yield datastore_handler.get_states_and_apps()
    state = [x for x in states if x['name'] == state] or [{
        'module': 'openvpn'
    }]
    state = state[0]

    if not module:
        module = state['module']

    yield handler.serve_file('test',
                             salt_source={
                                 "tgt": server_name,
                                 "fun": module + '.' + action,
                                 "arg": args
                             })
    raise tornado.gen.Return({"data_type": "file"})
Ejemplo n.º 3
0
def add_service_with_presets(datastore_handler,
                             presets,
                             server,
                             name='',
                             address='',
                             port=443,
                             tags=''):
    """Creates services based on several presets and the info for the server. The info is required to get the id and the IP of the server. """

    name = name or server + '_services'
    port = port or 443
    tags = tags.split(',')

    if not address:
        #If server is a string, and address is not set, we assume the server is a salt minion and we just take the data from mine.
        minion_info = {}
        if type(server) in [str, unicode] and server:
            minion_info = yield apps.get_app_info(server)

        if not minion_info:
            raise Exception(
                "No `address` argument found, and %s did not return mine data (maybe it's not a minion?). Either use the ip address of the server or its minion id. "
                % (server))
        address = minion_info['ip4_interfaces']['eth0'][0]

    checks = []

    for preset in presets:
        preset = yield datastore_handler.get_object('service_preset',
                                                    name=preset)

        check = yield generate_check_from_preset(preset,
                                                 server,
                                                 address=address,
                                                 tags=tags,
                                                 port=int(port))
        checks.append(check)

    service = {
        "service": {
            "name": name,
            "tags": tags,
            "address": address,
            "port": int(port),
            "checks": [preset]
        }
    }
    yield add_service_with_definition(service, name)
Ejemplo n.º 4
0
def salt_serve_file_get(handler,
                        server_name,
                        action,
                        hostname,
                        backupnumber,
                        share,
                        path,
                        module=None):
    datastore_handler = handler.datastore_handler
    server_info = yield apps.get_app_info(server_name)
    state = server_info['role']

    states = yield datastore_handler.get_states_and_apps()
    state = [x for x in states if x['name'] == state] or [{
        'module': 'openvpn'
    }]
    state = state[0]

    if not module:
        module = state['module']

    kwargs = {
        'hostname': hostname,
        'backupnumber': backupnumber,
        'share': share,
        'path': path,
        'range_from': 0,
    }

    yield handler.serve_file('test',
                             salt_source={
                                 "tgt": server_name,
                                 "fun": module + '.' + action,
                                 "kwarg": kwargs
                             })
    raise tornado.gen.Return({"data_type": "file"})

    if not module:
        module = state['module']

    yield handler.serve_file('test',
                             salt_source={
                                 "tgt": server_name,
                                 "fun": module + '.' + action,
                                 "arg": args
                             })
    raise tornado.gen.Return({"data_type": "file"})