solar-resources/examples/compiled-resources/example-compiled-resources.py
Łukasz Oleś 25dc2685f5 Refactor VirtualResources
- rename VirtualResource to Composer
- rename event parameter depend_action to child_action
- rename values parameter to input

Closes-bug: #1526780

Change-Id: Ib974e14ff4bda44c2d7d991f62aa4a06dea160ea
2015-12-29 16:50:46 +01:00

92 lines
2.5 KiB
Python
Executable File

#!/usr/bin/env python
"""
To run this code, first compile the resources with
solar resource compile_all
NOTE: this script might be outdated, the idea is just to show how
compiled resources work.
"""
import click
import json
import requests
import sys
import time
from solar.core import actions
from solar.core.resource import composer as cr
from solar.core import resource
from solar.core import signals
from solar.dblayer.model import ModelMeta
from solar.core.resource_provider import GitProvider, RemoteZipProvider
import resources_compiled
@click.group()
def main():
pass
@click.command()
def deploy():
ModelMeta.remove_all()
signals.Connections.clear()
node1 = resources_compiled.RoNodeResource('node1', None, {})
node1.ip = '10.0.0.3'
node1.ssh_key = '/vagrant/.vagrant/machines/solar-dev1/virtualbox/private_key'
node1.ssh_user = 'vagrant'
rabbitmq_service1 = resources_compiled.RabbitmqServiceResource('rabbitmq_service1', None, {'management_port': 15672, 'port': 5672, 'container_name': 'rabbitmq_service1', 'image': 'rabbitmq:3-management'})
openstack_vhost = resource.create('openstack_vhost', 'resources/rabbitmq_vhost/', {'vhost_name': 'openstack'})[0]
openstack_rabbitmq_user = resource.create('openstack_rabbitmq_user', 'resources/rabbitmq_user/', {'user_name': 'openstack', 'password': 'openstack_password'})[0]
####
# connections
####
# rabbitmq
signals.connect(node1, rabbitmq_service1)
signals.connect(rabbitmq_service1, openstack_vhost)
signals.connect(rabbitmq_service1, openstack_rabbitmq_user)
signals.connect(openstack_vhost, openstack_rabbitmq_user, {'vhost_name': 'vhost_name'})
errors = cr.validate_resources()
if errors:
for r, error in errors:
print 'ERROR: %s: %s' % (r.name, error)
sys.exit(1)
# run
actions.resource_action(rabbitmq_service1, 'run')
actions.resource_action(openstack_vhost, 'run')
actions.resource_action(openstack_rabbitmq_user, 'run')
time.sleep(10)
@click.command()
def undeploy():
ModelMeta.remove_all()
resources = resource.load_all()
resources = {r.name: r for r in resources}
actions.resource_action(resources['openstack_rabbitmq_user'], 'remove')
actions.resource_action(resources['openstack_vhost'], 'remove')
actions.resource_action(resources['rabbitmq_service1'], 'remove')
ModelMeta.remove_all()
main.add_command(deploy)
main.add_command(undeploy)
if __name__ == '__main__':
main()