Exemplo n.º 1
0
def clear_resources(debug):
    start_logging(debug)

    try:
        validate_resources(raiseException=True)
    except Exception:                   #pylint: disable=W0703 
        sys.exit('ERROR: Unable to clear resources because of validation error')

    data_root = config.runtime.default.data_root

    print '\nClearing resources...'
    for resource in all_files(os.path.join(data_root, 
                                           'resources')):
        print 'Clearing %s...' % resource,
        try:
            contents = load(resource, CONTENT_TYPE_YAML,
                            'clear_resource')
            for key in contents:
                contents[key] = 'None'
            dump(contents, resource, CONTENT_TYPE_YAML,
                 'clear_resource')
            print 'Ok!'            
        except Exception as exc:        #pylint: disable=W0703            
            print '\nERROR: Failed to clear %s\n%s' % \
                (resource, exc)
Exemplo n.º 2
0
def validate_definitions():
    data_root = config.runtime.default.data_root

    print '\nValidating definitions...'
    for definition in all_files(os.path.join(data_root, 
                                             'definitions')):
        print 'Validating %s...' % definition,
        try:
            load(definition, CONTENT_TYPE_YAML,
                 'validator')
            print 'Ok!'
        except Exception as exc:        #pylint: disable=W0703            
            print '\nERROR: Failed to validate %s\n%s' % \
                (definition, exc)
Exemplo n.º 3
0
def validate_resources(raiseException=False):
    data_root = config.runtime.default.data_root

    print '\nValidating resources...'
    for resource in all_files(os.path.join(data_root, 'resources')):
        print 'Validating %s...' % resource,
        try:
            load(resource, CONTENT_TYPE_YAML, 'validator')
            print 'Ok!'
        except Exception as exc:  #pylint: disable=W0703
            print '\nERROR: Failed to validate %s\n%s' % \
                (resource, exc)
            if raiseException:
                raise exc
Exemplo n.º 4
0
def validate_nodes():
    data_root = config.runtime.default.data_root

    print '\nValidating nodes...'
    for filename in [
            x for x in all_files(os.path.join(data_root, 'nodes'))
            if x.split('/')[-1] in ['definition', 'pattern']
    ]:
        print 'Validating %s...' % filename,
        try:
            load(filename, CONTENT_TYPE_YAML, 'validator')
            print 'Ok!'
        except Exception as exc:  #pylint: disable=W0703
            print '\nERROR: Failed to validate %s\n%s' % \
                (filename, exc)
Exemplo n.º 5
0
def validate_definitions():
    data_root = config.runtime.default.data_root

    print '\nValidating definitions...'

    for definition in all_files(os.path.join(data_root, 
                                             'definitions')):
        print 'Validating %s...' % definition,
        try:
            def_data = load(definition, CONTENT_TYPE_YAML,
                            'validator')

            resources = re.findall(FUNC_RE, 
                                   str(def_data))

            # Validating plugins
            plugins = resource_plugins()
            missing_plugins = set([x for (x, _) in resources 
                                   if x not in plugins])
            if missing_plugins:
                plugins_path = os.path.join(data_root, 
                                            'plugins')
                print ''
                for plugin in missing_plugins:
                    print 'ERROR: Plugin \'%s\' configured in \'%s\' ' \
                        'is missing from \'%s\'!' % \
                        (plugin, definition, plugins_path)

            # Special validation for 'allocate' plugin
            resources_path = os.path.join(data_root, 
                                          'resources')
            resource_files = [x.split('/')[-1] 
                              for x in resources_path]
            missing_resources = [x for (y, x) in resources 
                                 if x not in resource_files and
                                 y == 'allocate']
            if missing_resources:
                if not missing_plugins:
                    print ''
                for res in missing_resources:
                    print 'ERROR: Resource file \'%s\' configured in \'%s\' ' \
                        'is missing from \'%s\'!' % \
                        (res, definition, resources_path)
            else:
                print 'Ok!'
        except Exception as exc:        #pylint: disable=W0703            
            print '\nERROR: Failed to validate %s\n%s' % \
                (definition, exc)
Exemplo n.º 6
0
def validate_nodes():
    data_root = config.runtime.default.data_root

    print '\nValidating nodes...'
    for filename in [x for x in all_files(os.path.join(data_root, 
                                                       'nodes'))
                     if x.split('/')[-1] in ['definition',
                                             'pattern']]:
        print 'Validating %s...' % filename,
        try:
            load(filename, CONTENT_TYPE_YAML,
                 'validator')
            print 'Ok!'
        except Exception as exc:        #pylint: disable=W0703            
            print '\nERROR: Failed to validate %s\n%s' % \
                (filename, exc)
Exemplo n.º 7
0
def validate_resources(raiseException=False):
    data_root = config.runtime.default.data_root

    print '\nValidating resources...'
    for resource in all_files(os.path.join(data_root, 
                                           'resources')):
        print 'Validating %s...' % resource,
        try:
            load(resource, CONTENT_TYPE_YAML,
                 'validator')
            print 'Ok!'
        except Exception as exc:        #pylint: disable=W0703 
            print '\nERROR: Failed to validate %s\n%s' % \
                (resource, exc)
            if raiseException:
                raise exc