Move all hardcoded paths to one config.yml file
This commit is contained in:
parent
bace02b293
commit
ff2ffe366e
9
config.yml
Normal file
9
config.yml
Normal file
@ -0,0 +1,9 @@
|
||||
examples-dir: /vagrant/examples
|
||||
|
||||
extensions-dir: /vagrant/solar/solar/extensions
|
||||
|
||||
file-system-db:
|
||||
resources-path: ./schema/resources
|
||||
storage-path: /vagrant/tmp/storage
|
||||
|
||||
template-dir: /vagrant/templates
|
@ -17,7 +17,6 @@ On create "golden" resource should be moved to special place
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import subprocess
|
||||
import os
|
||||
import sys
|
||||
import pprint
|
||||
@ -25,12 +24,12 @@ import pprint
|
||||
import textwrap
|
||||
import yaml
|
||||
|
||||
from solar import utils
|
||||
from solar import extensions
|
||||
from solar.interfaces.db import get_db
|
||||
from solar import utils
|
||||
|
||||
# NOTE: these are extensions, they shouldn't be imported here
|
||||
from solar.extensions.modules import ansible
|
||||
# Maybe each extension can also extend the CLI with parsers
|
||||
from solar.extensions.modules.discovery import Discovery
|
||||
|
||||
|
||||
@ -82,7 +81,9 @@ class Cmd(object):
|
||||
def profile(self, args):
|
||||
if args.create:
|
||||
params = {'tags': args.tags, 'id': args.id}
|
||||
profile_template_path = os.path.join(os.path.dirname(__file__), 'templates', 'profile.yml')
|
||||
profile_template_path = os.path.join(
|
||||
utils.read_config()['templates-dir'], 'profile.yml'
|
||||
)
|
||||
data = yaml.load(utils.render_template(profile_template_path, params))
|
||||
self.db.store('profiles', data)
|
||||
else:
|
||||
|
@ -1,12 +1,14 @@
|
||||
import glob
|
||||
import os
|
||||
|
||||
from solar import utils
|
||||
from solar.core.profile import Profile
|
||||
from solar.extensions.base import BaseExtension
|
||||
from solar import utils
|
||||
# Import all modules from the directory in order
|
||||
# to make subclasses for extensions work
|
||||
modules = glob.glob(os.path.join(os.path.dirname(__file__), 'modules', '*.py'))
|
||||
modules = glob.glob(
|
||||
os.path.join(utils.read_config()['extensions-dir'], 'modules', '*.py')
|
||||
)
|
||||
[__import__('%s.%s' % ('modules', os.path.basename(f)[:-3]), locals(), globals()) for f in modules]
|
||||
|
||||
|
||||
|
@ -4,6 +4,7 @@ import os
|
||||
import yaml
|
||||
|
||||
from solar.extensions import base
|
||||
from solar import utils
|
||||
|
||||
|
||||
class Discovery(base.BaseExtension):
|
||||
@ -15,9 +16,9 @@ class Discovery(base.BaseExtension):
|
||||
COLLECTION_NAME = 'nodes'
|
||||
|
||||
FILE_PATH = os.path.join(
|
||||
# TODO(pkaminski): no way we need '..' here...
|
||||
os.path.dirname(__file__), '..', '..', '..', '..',
|
||||
'examples', 'nodes_list.yaml')
|
||||
utils.read_config()['examples-dir'],
|
||||
'nodes_list.yaml'
|
||||
)
|
||||
|
||||
def discover(self):
|
||||
nodes_to_store = []
|
||||
|
@ -1,7 +1,7 @@
|
||||
import os
|
||||
|
||||
from solar import utils
|
||||
from solar.extensions import base
|
||||
from solar import utils
|
||||
|
||||
|
||||
class Resources(base.BaseExtension):
|
||||
@ -13,9 +13,8 @@ class Resources(base.BaseExtension):
|
||||
# Rewrite it to use golden resources from
|
||||
# the storage
|
||||
FILE_MASK = os.path.join(
|
||||
# TODO(pkaminski): no way we need '..' here...
|
||||
os.path.dirname(__file__), '..', '..', '..', '..',
|
||||
'examples', 'resources', '*.yml')
|
||||
utils.read_config()['examples-dir'],
|
||||
'resources', '*.yml')
|
||||
|
||||
def resources(self):
|
||||
resources = []
|
||||
|
@ -19,8 +19,8 @@ def get_files(path, pattern):
|
||||
|
||||
|
||||
class FileSystemDB(DirDBM):
|
||||
RESOURCES_PATH = './schema/resources'
|
||||
STORAGE_PATH = '/vagrant/tmp/storage/'
|
||||
RESOURCES_PATH = utils.read_config()['file-system-db']['resources-path']
|
||||
STORAGE_PATH = utils.read_config()['file-system-db']['storage-path']
|
||||
|
||||
def __init__(self):
|
||||
utils.create_dir(self.STORAGE_PATH)
|
||||
|
@ -59,3 +59,7 @@ def render_template(template_path, params):
|
||||
temp = Template(f.read())
|
||||
|
||||
return temp.render(**params)
|
||||
|
||||
|
||||
def read_config():
|
||||
return yaml_load('/vagrant/config.yml')
|
||||
|
Loading…
x
Reference in New Issue
Block a user