Showing posts with label juju. Show all posts
Showing posts with label juju. Show all posts

Monday, May 19, 2014

Use JuJu "run" to discover charm relationships

Juju run is cool because it lets you execute stuff inside an anonymous hook context. So if you were say prompted with the following topology.
services:
  mediawiki:
    charm: cs:precise/mediawiki-16
    exposed: true
    relations:
      db:
      - mysql
      website:
      - siege
    units:
      mediawiki/0:
        agent-state: started
        agent-version: 1.18.3
        machine: "5"
        open-ports:
        - 80/tcp
        public-address: XXX
  mysql:
    charm: cs:precise/mysql-44
    exposed: false
    relations:
      cluster:
      - mysql
      db:
      - mediawiki
    units:
      mysql/0:
        agent-state: started
        agent-version: 1.18.3
        machine: "3"
        public-address: XXX
  siege:
    charm: cs:~dannf/precise/siege-4
    exposed: false
    relations:
      website:
      - mediawiki
    units:
      siege/0:
        agent-state: started
        agent-version: 1.18.3
        machine: "4"
        public-address: XXX
Which is just mediawiki powered by mysql with siege attached to mediawiki. Say you want to know more details mysql's relationships.
# bash shell
unit='mysql/0'
relations=$(juju run --unit ${unit} 'ls ./hooks/ | grep relation | cut -d '-' -f1 | uniq')

for rel in $relations
do
  echo "testing for relationships in $rel"
  juju run --unit ${unit} "relation-ids   ${rel} --format=json"
done

...

testing for relationships in ceph
[]
testing for relationships in cluster
["cluster:2"]
testing for relationships in db
["db:4"]
testing for relationships in ha
[]
testing for relationships in ha_relations.py
[]
testing for relationships in local
[]
testing for relationships in master
[]
testing for relationships in monitors
[]
testing for relationships in munin
[]
testing for relationships in shared
[]
testing for relationships in shared_db_relations.py
[]
testing for relationships in slave
[]
Cool, there's the DB relationship, now you can probe it.
ppetraki@:cabs-sandbox$ juju run --unit ${unit} "relation-get database ${unit} -r db:4 --format=json"
"mediawiki"

ppetraki@:cabs-sandbox$ juju run --unit ${unit} "relation-get password ${unit} -r db:4 --format=json"
"alaeyomooxaesee"

Thursday, June 13, 2013

Determine machine size in juju programitcally

I wouldn't call this easy, but it works, and it keeps me out of python.
# on hpcloud

$juju status apache2 2>/dev/null | grep instance-id |
  awk '{split($0,array,":")} END{print array[2]}' | tr -d ' ' |
  xargs nova show | grep flavor |
  awk '{split($0,array,"|")} END{print array[3]}' | tr -d ' '

standard.xsmall

Monday, November 26, 2012

OpenGrok is now in the Ubuntu Charm Store!

http://jujucharms.com/charms/precise/opengrok
  • Now supports multiple projects using a simple JSON format
  • Supports both git and bzr
$ juju bootstrap
$ juju deploy opengrok
$ juju expose opengrok

Thursday, November 1, 2012

My first juju charm: OpenGrok

From the project page:

" OpenGrok is a fast and usable source code search and cross reference engine. It helps you search, cross-reference and navigate your source tree. It can understand various program file formats and version control histories like Mercurial, Git, SCCS, RCS, CVS, Subversion, Teamware, ClearCase, Perforce, Monotone and Bazaar. In other words it lets you grok (profoundly understand) source code and is developed in the open, hence the name OpenGrok. It is written in Java."

To get started:
$ juju deploy cs:~peter-petrakis/precise/opengrok
$ juju expose opengrok
and the icing, you can add and index new projects by simply:
juju set opengrok og-content=lp:juju
Currently it only will do this with lp urls but later I intend to expand to general bzr urls and of course git. Automatic source code updating and indexing is also in the works. It's currently in the charm store submission stage but is ready for trial use. Remember, you can use LXC containers with juju so it's trivial to deploy complex services locally without a cloud.

Tuesday, October 16, 2012

sshuttle and juju for seamless private network bridging

Suppose you're getting started with juju, but you wish to try this on a VM or separate server dedicated to the task, further suppose you wish to use LXC for development purposes. Once everything is said and done you'll have a working juju service with an ip address you can't reach.
ppetraki@mark21:~/Sandbox/juju-local$ juju status
machines:
  0:
    agent-state: running
    dns-name: localhost
    instance-id: local
    instance-state: running
services:
  mysql:
    charm: cs:precise/mysql-8
    relations:
      db:
      - wordpress
    units:
      mysql/0:
        agent-state: started
        machine: 0
        public-address: 192.168.122.119
  wordpress:
    charm: cs:precise/wordpress-9
    exposed: true
    relations:
      db:
      - mysql
      loadbalancer:
      - wordpress
    units:
      wordpress/0:
        agent-state: started
        machine: 0
        open-ports:
        - 80/tcp
        public-address: 192.168.122.196
The solution? sshuttle.
$ sshuttle -r mark21 192.168.122.0/24
Will use iptables to create a NAT which tunnels over ssh to bridge this network. Now you can visit 192.168.122.196 in your web browser and have full TCP access to that network, all without using openvpn.