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