Beispiel #1
0
def script_execute(section_dict):
    helpers = Helpers()
    section_dict['file'] = helpers.listify(section_dict['file'])
    files_l = len(section_dict['file'])
    if not section_dict.get('args'):
        section_dict['args'] = [''] * files_l
    section_dict['args'] = helpers.listify(section_dict['args'])
    args_l = len(section_dict['args'])

    length_match = False
    if args_l != files_l:
        if files_l > args_l:
            if args_l == 1:
                length_match = True
                section_dict['args'] *= files_l
    else:
        length_match = True
    if not length_match:
        print "\nError: Mismatch in the number of arguments " \
                "and the number of shell scripts."
        return section_dict, None
    data = []
    for sh, args in zip(section_dict['file'], section_dict['args']):
        data.append(sh + ' ' + args)
    section_dict['script'] = data
    return section_dict, defaults.RUN_SCRIPT
Beispiel #2
0
def script_execute(section_dict):
    helpers = Helpers()
    section_dict['file'] = helpers.listify(section_dict['file'])
    files_l = len(section_dict['file'])
    if not section_dict.get('args'):
        section_dict['args'] = [''] * files_l
    section_dict['args'] = helpers.listify(section_dict['args'])
    args_l = len(section_dict['args'])

    length_match = False
    if args_l != files_l:
        if files_l > args_l:
            if args_l == 1:
                length_match = True
                section_dict['args'] *= files_l
    else:
        length_match = True
    if not length_match:
        msg = "\nError: Mismatch in the number of arguments " \
              "and the number of shell scripts."
        print msg
        if Global.trace:
            Global.logger.info(msg)
        return section_dict, None
    data = []
    for sh, args in zip(section_dict['file'], section_dict['args']):
        data.append(sh + ' ' + args)
    section_dict['script'] = data
    if Global.trace:
        Global.logger.info("Executing %s."%defaults.RUN_SCRIPT)
    return section_dict, defaults.RUN_SCRIPT
Beispiel #3
0
def post_request_handler(env, start_response):
    helpers = Helpers()
    add = re.match(r'/gdeploy/config/(.+)', env['PATH_INFO'])
    deploy = re.match(r'/gdeploy/deployconfig/(.+)', env['PATH_INFO'])
    if add:
        if env['CONTENT_TYPE'] != 'application/json':
            start_response('304 Not Modified',
                           [('Content-Type', 'application/json')])
            return ['304 Not Modified\r\n']
        if add.group(1) not in RecordList.record:
            length = int(env.get('CONTENT_LENGTH', '0'))
            body = StringIO(env['wsgi.input'].read(length))
            content = body.getvalue()
            RecordList.record[add.group(1)] = content
            start_response('201 Created',
                           [('Content-Type', 'application/json')])
            return ['201 Created\r\n']
        start_response('422 Unprocessable Entity',
                       [('Content-Type', 'application/json')])
        return ['422 Unprocessable Entity\r\n']
    elif deploy:
        content = RecordList.record.get(deploy.group(1))
        if not content:
            start_response('404 Not Found',
                           [('Content-Type', 'application/json')])
            return ['404 Not Found\r\n']
        data = literal_eval(content)
        config_file = tempfile.mkstemp()[1]
        for key, value in data.iteritems():
            helpers.write_config(key, value, config_file)
        command = 'gdeploy -c %s' % config_file
        subprocess.call(command.split(),
                        stdin=None,
                        stdout=None,
                        stderr=None,
                        shell=False)
        start_response('200 OK', [('Content-Type', 'application/json')])
        return ['200 OK\r\n']
    else:
        start_response('400 Bad Request',
                       [('Content-Type', 'application/json')])
        return ['400 Bad Request\r\n']
Beispiel #4
0
def post_request_handler(env, start_response):
    helpers = Helpers()
    add = re.match(r'/gdeploy/config/(.+)', env['PATH_INFO'])
    deploy = re.match(r'/gdeploy/deployconfig/(.+)', env['PATH_INFO'])
    if add:
        if env['CONTENT_TYPE'] != 'application/json':
            start_response('304 Not Modified', [('Content-Type',
                                                 'application/json')])
            return ['304 Not Modified\r\n']
        if add.group(1) not in RecordList.record:
            length = int(env.get('CONTENT_LENGTH', '0'))
            body = StringIO(env['wsgi.input'].read(length))
            content = body.getvalue()
            RecordList.record[add.group(1)] = content
            start_response('201 Created', [
                           ('Content-Type', 'application/json')])
            return ['201 Created\r\n']
        start_response('422 Unprocessable Entity', [
                       ('Content-Type', 'application/json')])
        return ['422 Unprocessable Entity\r\n']
    elif deploy:
        content = RecordList.record.get(deploy.group(1))
        if not content:
            start_response('404 Not Found', [('Content-Type',
                                              'application/json')])
            return ['404 Not Found\r\n']
        data = literal_eval(content)
        config_file = tempfile.mkstemp()[1]
        for key, value in data.iteritems():
            helpers.write_config(key, value, config_file)
        command = 'gdeploy -c %s' % config_file
        subprocess.call(command.split(),
                        stdin=None, stdout=None, stderr=None, shell=False)
        start_response('200 OK', [('Content-Type', 'application/json')])
        return ['200 OK\r\n']
    else:
        start_response('400 Bad Request', [('Content-Type',
                                            'application/json')])
        return ['400 Bad Request\r\n']
Beispiel #5
0
def script_execute(section_dict):
    helpers = Helpers()
    Global.ignore_errors = section_dict.get('ignore_script_errors')
    scriptargs = section_dict['file']
    if type(scriptargs) == list:
        cmd = scriptargs.pop(0)
        # Build rest of the command
        for a in scriptargs:
            cmd += "," + a
    else:
        cmd = scriptargs
    section_dict['script'] = cmd
    return section_dict, defaults.RUN_SCRIPT
Beispiel #6
0
"""
Add functions corresponding to each of the actions in the json file.
The function should be named as follows <feature name>_<action_name>
"""
from gdeploylib import defaults, Helpers, Global

helpers = Helpers()


def nfs_ganesha_create_cluster(section_dict):
    global helpers
    Global.logger.info("Creating NFS Ganesha cluster")
    cluster_nodes = get_cluster_nodes(section_dict)
    section_dict['ha_name'] = section_dict.pop('ha-name')
    if not len(cluster_nodes) == len(section_dict.get('vip')):
        msg = "Provide virtual IPs for all the hosts in "\
              "the cluster-nodes"
        print "Error: %s" % msg
        Global.logger.error(msg)
        helpers.cleanup_and_quit()
    vips, section_dict['vip_list'] = get_host_vips(section_dict, cluster_nodes)
    section_dict['value'] = "on"
    ymls = [
        defaults.GANESHA_PKG_CHECK, defaults.GANESHA_CONFIG_SERVICES,
        defaults.GANESHA_PUBKEY, defaults.COPY_SSH, defaults.SHARED_MOUNT,
        defaults.SET_AUTH_PASS, defaults.PCS_AUTH,
        defaults.GANESHA_CONF_CREATE, defaults.DEFINE_SERVICE_PORTS,
        defaults.ENABLE_GANESHA
    ]
    # Export a volume if mentioned in section, earlier we had the logic in
    # playbook to skip export if volname was not mentioned. However, if volume