RemoteZipProvider added for resources, with a sample in example.py

This commit is contained in:
Przemyslaw Kaminski 2015-06-19 15:31:36 +02:00
parent 477d68e604
commit a616c05eca
2 changed files with 38 additions and 2 deletions

View File

@ -10,10 +10,11 @@ from solar.core import signals
from solar.core import validation
from solar.interfaces.db import get_db
from solar.core.resource_provider import GitProvider
from solar.core.resource_provider import GitProvider, RemoteZipProvider
GIT_KEYSTONE_RESOURCE_URL = 'https://github.com/CGenie/keystone-resource'
ZIP_KEYSTONE_RESOURCE_URL = 'https://github.com/CGenie/keystone-resource/archive/master.zip'
@click.group()
@ -40,7 +41,7 @@ def deploy():
keystone_db_user = resource.create('keystone_db_user', 'resources/mariadb_keystone_user/', {'new_user_name': 'keystone', 'new_user_password': 'keystone', 'login_user': 'root'})
keystone_config1 = resource.create('keystone_config1', GitProvider(GIT_KEYSTONE_RESOURCE_URL, path='keystone_config'), {'config_dir': '/etc/solar/keystone', 'admin_token': 'admin'})
keystone_service1 = resource.create('keystone_service1', GitProvider(GIT_KEYSTONE_RESOURCE_URL, 'keystone_service'), {'port': 5001, 'admin_port': 35357})
keystone_service1 = resource.create('keystone_service1', RemoteZipProvider(ZIP_KEYSTONE_RESOURCE_URL, 'keystone_service'), {'port': 5001, 'admin_port': 35357})
keystone_config2 = resource.create('keystone_config2', GitProvider(GIT_KEYSTONE_RESOURCE_URL, 'keystone_config'), {'config_dir': '/etc/solar/keystone', 'admin_token': 'admin'})
keystone_service2 = resource.create('keystone_service2', GitProvider(GIT_KEYSTONE_RESOURCE_URL, 'keystone_service'), {'port': 5002, 'admin_port': 35358})

View File

@ -1,5 +1,8 @@
import os
import requests
import StringIO
import subprocess
import zipfile
from solar import utils
@ -50,3 +53,35 @@ class GitProvider(BaseProvider):
self.directory = os.path.join(resources_directory, path)
else:
self.directory = resources_directory
class RemoteZipProvider(BaseProvider):
"""Download & extract zip from some URL.
Assumes zip structure of the form:
<group-name>
<resource1>
<resource2>
...
"""
def __init__(self, url, path='.'):
self.url = url
self.path = path
r = requests.get(url)
s = StringIO.StringIO(r.content)
z = zipfile.ZipFile(s)
group_name = os.path.dirname(z.namelist()[0])
base_resources_directory = utils.read_config()['resources-directory']
resources_directory = os.path.join(
base_resources_directory, group_name
)
if not os.path.exists(resources_directory):
z.extractall(base_resources_directory)
if path != '.':
self.directory = os.path.join(resources_directory, path)
else:
self.directory = resources_directory