Any thoughts on a data uploading method.
Clint Byrum
clint at ubuntu.com
Thu May 31 18:09:29 UTC 2012
Excerpts from Robert Steckroth's message of 2012-05-31 09:36:48 -0700:
> Hey gang, I have developed a awesome new Django charm which uses a
> very generic mating charm
> for project deployment. Basically the only thing the user needs to
> copy and edit the project charms config.yaml file (below).
> There needs to be a charm for every django project one wants to
> deploy. Also, the Django project must be hosted
> on the internet with a repository (Only supports mercurial and
> Bitbucket right now).
\o/ This is really cool Robert! Hopefully this will be ready for review
in the main charm store soon.
> Here is the config.yaml
> As you can see I wan't to make deploying Django projects as simple as
> possible. The only problem
> that remains is in the virtual host upload. Is there a way to natively
> get this virtual host information
> onto the primary charms unit? If not, is puppet the only other way.
> The below method
> works except the --> config-get project_apache2_vhost <-- will store
> the string into one line. Then Apache2
> complains about it not having newlines.
>
> options:
> project_repo_type:
> description: |
> This is the brand of repository versioning the project uses.
> E.g. hg git svn bzr etc...
> type: string
> default: 'hg'
> project_repo_url:
> description: |
> The url of the project repository.
> E.g. https://bitbucket.org/ubernostrum/django-registration
> ssh://user@your-site.com/project
> type: string
> default: 'https://surgemcgee@bitbucket.org/surgemcgee/mmrn_site'
> project_repo_username:
> description: |
> The password of the project repository.
> type: string
> default: 'surgemcgee'
> project_repo_password:
> description: |
> The password of the project repository.
> type: string
> default: 'n0nsense'
> project_apache2_vhost:
> description: |
> The entire virtual host for this django project.
> type: string
> default: '
>
>
> <VirtualHost *:80>
> # ServerAdmin bob at localhost
>
> DocumentRoot /home/sites/
> ServerName www.budtvnetwork.com
> # ServerAlias www.budtv1.com budtv1.com *.budtv1.com
> budtvnetwork.com *.budtvnetwork.com
> # DirectoryIndex index.html
> <Directory />
> Options FollowSymLinks
> AllowOverride None
> </Directory>
> <Directory /home/sites/mmrn/serve/>
> Options Indexes FollowSymLinks MultiViews
> AllowOverride None
> Order allow,deny
> allow from all
> </Directory>
>
> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
> <Directory "/usr/lib/cgi-bin">
> AllowOverride None
> Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
> Order allow,deny
> Allow from all
> </Directory>
>
> ErrorLog /var/log/apache2/error.log
>
> # Possible values include: debug, info, notice, warn, error, crit,
> # alert, emerg.
> LogLevel warn
>
> CustomLog /var/log/apache2/access.log combined
>
> Alias /doc/ "/usr/share/doc/"
> <Directory "/usr/share/doc/">
> Options Indexes MultiViews FollowSymLinks
> AllowOverride None
> Order deny,allow
> Deny from all
> Allow from 127.0.0.0/255.0.0.0 ::1/128
> </Directory>
>
> Alias /static "/home/sites/mmrn/serve"
> <Location "/static">
> SetHandler None
> </Location>
> <Location "/source">
> SetHandler None
> </Location>
>
> WSGIDaemonProcess mmrn processes=4 threads=15 display-name=%{GROUP}
> WSGIProcessGroup mmrn
>
> WSGIScriptAlias / /home/sites/mmrn_wsgi.py
> </VirtualHost>'
>
This is just tricky in yaml. What you need is an explicit indentation
indicator, and a little cleanup.
Do it something like this:
options:
apache2_project_vhost:
default: |2
<VirtualHost foo>
bar
baz
</VirtualHost>
This will parse everything that is indented 2 more spaces than 'default:'
as the string, with newlines included, and with the spaces beyond that
yaml padding stripped out. So the above will produce this:
Python 2.7.3 (default, Apr 20 2012, 22:39:59)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import yaml
>>> x = yaml.safe_load("""options:
... apache2_project_vhost:
... default: |2
... <VirtualHost foo>
... bar
... baz
... </VirtualHost>
... """)
>>> x
{'options': {'apache2_project_vhost': {'default': '<VirtualHost foo>\n bar\n baz\n</VirtualHost>\n'}}}
>>> print x['options']['apache2_project_vhost']['default']
<VirtualHost foo>
bar
baz
</VirtualHost>
>>>
config-get should then print out the literal representation of that
when you run 'config-get apache2_project_vhost'. I would specifically
specify --format smart, since there's a possibility that the default
will change to 'json' in the next charm format, which will print it out
as a double quoted json string rather than the literal representation
with the newlines.
More information about the Juju
mailing list