Add SVN provider for downloading dependencies

Git wont allow you to download only one directory from github,
(actually there is a way - with sparse download, but it is complicated),
but svn provides quite simple and user friendly way of downloading directory
from github
This commit is contained in:
Dmitry Shulyak 2015-07-24 23:16:32 +03:00
parent 9dcf2bc4a3
commit f6b7cf7843
4 changed files with 41 additions and 2 deletions

View File

@ -20,4 +20,9 @@ input:
value:
container_name:
schema: str!
value:
value:
roles:
schema: [{value: str}]
value:
- https://github.com/stackforge/os-ansible-deployment/trunk/playbooks/roles/lxc_container_create
- https://github.com/stackforge/os-ansible-deployment/trunk/playbooks/roles/lxc_container_destroy

View File

@ -11,4 +11,10 @@ input:
value:
ssh_user:
schema: str!
value:
value:
roles:
schema: [{value: str}]
value:
- https://github.com/stackforge/os-ansible-deployment/trunk/playbooks/roles/lxc_hosts
- https://github.com/stackforge/os-ansible-deployment/trunk/playbooks/roles/pip_install
- https://github.com/stackforge/os-ansible-deployment/trunk/playbooks/roles/apt_package_pinning

View File

@ -9,10 +9,15 @@ import ansible.constants as C
from solar.core.handlers import base
from solar import errors
from solar.core.provider import SVNProvider
class AnsiblePlaybook(base.BaseHandler):
def download_roles(self, urls):
for url in urls:
SVNProvider(url, '/etc/ansible/roles').run()
def action(self, resource, action):
action_file = os.path.join(
resource.metadata['actions_path'],
@ -22,6 +27,9 @@ class AnsiblePlaybook(base.BaseHandler):
runner_cb = callbacks.PlaybookRunnerCallbacks(stats, verbose=utils.VERBOSITY)
variables = resource.args_dict()
if 'roles' in variables:
self.download_roles(variables['roles'])
remote_user = variables.get('ssh_user') or C.DEFAULT_REMOTE_USER
private_key_file = variables.get('ssh_key') or C.DEFAULT_PRIVATE_KEY_FILE
if variables.get('ip'):

View File

@ -103,3 +103,23 @@ class RemoteZipProvider(BaseProvider):
self.directory = os.path.join(directory, path)
else:
self.directory = directory
class SVNProvider(BaseProvider):
"""With git you cant checkout only directory from repo,
but with svn you can
"""
def __init__(self, url, path='.'):
self.url = url
self.path = path
def run(self):
if not os.path.exists(self.path):
os.makedirs(self.path)
if not os.path.exists(self.url.rsplit('/', 1)[-1]):
fabric.local(
'cd {path} && svn checkout {url}'.format(
path=self.path,
url=self.url))