Permalink
Browse files

Rename cloud functions with underscores. Rework base wovencommand to …

…pick up cloud nodes
  • Loading branch information...
1 parent 08e70f4 commit e31f871817d70823b561bfed3c9f863eb2253d18 @bretth committed Jan 4, 2011
View
@@ -1,15 +1,47 @@
Management Commands
===================
-Commands that run on a host require a hoststring, role or have HOSTS or ROLEDEFS defined in your settings.
+Active Node Commands
+--------------------
-As per fabric a hoststring can be username@hostname, or use just the hostname or ip address. If no username is defined then woven will use the current user or settings.HOST_USER. You never need to set the port. It will always use port 10022 though another port can be defined using the HOST_SSH_PORT setting.
+Commands that run on an active node (activate, deploy, node, patch, setupnode, startsites) use the following precedence to determine which nodes to execute against:
+
+**Default Role Definitions**
+
+With ROLEDEFS setting defined for `default` and no command arguments, the command will execute against the host list defined by the `default` role.
+
+**Default Role Cloud Provider**
+
+With NODES setting defined with a `default` role configuration and no arguments the command will execute against the host list generated by that provider.
+
+**Default Host list**
+
+With HOSTS setting defined and no arguments the command will execute against all HOSTS.
+
+**Specified Role**
+
+If the command args match any ROLEDEFS roles, the command will execute against all the hosts defined by those roles.
+
+**Specified Role Cloud Provider**
+
+If the command args match any NODES role configuration the command will execute against all the hosts defined by those roles. A current limitation of this is that grouping of hosts into roles is dependent on provider support for some kind of tagging or grouping attribute that you can define for nodes that are the same and hosted in the same location.
+
+**Hoststring**
+
+With no settings defined you must use a valid fabric *hoststring* which can be be username@hostname, or just the hostname or ip address.
+
+Active Node Commands User and Port
+----------------------------------
+
+Once the hostlist is determined woven will use the current user if none is set in the host list. You can set the username for all hosts with the HOST_USER setting.
+
+You should never set the port. It will always use the HOST_SSH_PORT setting or 10022.
+
+Manage Node Commands
+------------------------
+
+Commands that manage nodes (createnode, destroynode, listnodes) execute using a provider if no NODES are defined, a `default` NODES provider configuration, or the specified NODES role provider configuration.
-A common and recommended deployment pattern is to separate out staging servers from production servers. To do this in woven you would define your hoststrings in the ROLEDEFS settings (like fabfile roledefs). For example to have one staging server and two production servers you could define::
-
- ROLEDEFS = {'staging':['user@192.168.188.10'], 'production':['user@host1.example.com', user@host2.example.com]}
-
-You would then use the role in place of the hoststring e.g. ``woven-admin.py deploy staging``
startproject
------------
View
@@ -4,7 +4,7 @@
"""
from fabric.state import env
-from woven.cloud import createnode, destroynode, listhosts, listnodes
+from woven.cloud import create_node, destroy_node, list_hosts, list_nodes
from woven.decorators import run_once_per_node, run_once_per_version
View
@@ -28,7 +28,7 @@ def connect(provider, secret_key, uid=''):
return cloud_conn
-def createnode(named_conf='default', **kwargs):
+def create_node(named_conf='default', **kwargs):
"""
Create a node at a provider
"""
@@ -95,16 +95,16 @@ def createnode(named_conf='default', **kwargs):
print " }"
print "}"
-def destroynode(provider, secret_key, uid, image_id):
+def destroy_node(provider, secret_key, uid, image_id):
"""
Destroy nodes
"""
if not image_id:
- nodes = listnodes(provider, secret_key, uid)
+ nodes = list_nodes(provider, secret_key, uid)
else:
with settings(verbosity=False):
- nodes = listnodes(provider, secret_key, uid)
+ nodes = list_nodes(provider, secret_key, uid)
resp = False
conn = connect(provider, secret_key, uid)
@@ -170,11 +170,12 @@ def get_node_obj(conn, attribute, id):
print o.id,'|', o.name
count += 1
-def listhosts(nodes_conf, role):
+def list_hosts(nodes_conf, role):
"""
- Get a list of host public ips or hostnames with the given role or default
+ Get a dict of host public ip node objects with the given role or default
from a provider defined by NODES settings
"""
+ node_objs = {}
if role:
conf = nodes_conf.get(role)
else:
@@ -198,14 +199,14 @@ def listhosts(nodes_conf, role):
sys.exit(1)
raise
# list of hosts that are running
- hosts = [n.public_ip[0] for n in nodes]
-else:
- hosts = []
+ for n in nodes:
+ if n.state == 0: #running
+ node_objs[n.public_ip[0]] = n
- return hosts
+ return nodes
-def listnodes(provider, secret_key, uid):
+def list_nodes(provider, secret_key, uid):
"""
List nodes on a provider
"""
View
@@ -438,6 +438,9 @@ def set_env(settings=None, setup_dir=''):
env.sites = {}
env.shell = '/bin/bash --noprofile -l -c'
#output.debug = True
+
+ #Node objs
+ env.node_objs = []
def get_packages():
"""
View
@@ -13,7 +13,7 @@
from fabric.context_managers import hide,show
from woven.environment import set_env
-from woven.cloud import listhosts
+from woven.cloud import list_hosts
class WovenCommand(BaseCommand):
option_list = BaseCommand.option_list + (
@@ -94,13 +94,23 @@ def handle(self, *args, **options):
elif hasattr(settings,'NODES') and settings.NODES:
for r in normalized_host_list:
- all_role_hosts += listhosts(settings.NODES, r)
+ h = list_hosts(settings.NODES, r)
+ if h:
+ all_role_hosts += h.keys()
+ state.env['roles'] = state.env['roles'] + [r]
+ state.env['node_objs'] = h
if all_role_hosts:
comma_hosts = ','.join(all_role_hosts)
if comma_hosts:
state.env.hosts = comma_hosts
+ elif hasattr(settings, 'ROLEDEFS') and settings.ROLEDEFS.get('default'):
+ state.env.hosts = ','.join(settings.ROLEDEFS.get('default',''))
+ state.env['roles'] = state.env['roles'] + ['default']
elif hasattr(settings, 'NODES') and settings.NODES.get('default'):
- state.env.hosts = ','.join(listhosts(settings.NODES,'default'))
+ h = list_hosts(settings.NODES,'default')
+ state.env.hosts = ','.join(h.keys())
+ state.env['roles'] = state.env['roles'] + ['default']
+ state.env['node_objs'] = h
if 'hosts' in state.env and isinstance(state.env['hosts'], str):
state.env['hosts'] = state.env['hosts'].split(',')
@@ -11,7 +11,7 @@
from libcloud.types import Provider
-from woven.api import createnode, post_exec_hook, set_env
+from woven.api import create_node, post_exec_hook, set_env
class Command(BaseCommand):
"""
@@ -71,5 +71,5 @@ def handle(self,*args, **options):
lower_kwargs[k.lower()] = kwargs[k]
lower_kwargs['provider'] = provider
- createnode(named_conf, **lower_kwargs)
+ create_node(named_conf, **lower_kwargs)
post_exec_hook('post_createnode')
@@ -8,7 +8,7 @@
from libcloud.types import Provider
-from woven.api import destroynode, set_env
+from woven.api import destroy_node, set_env
class Command(BaseCommand):
"""
@@ -71,4 +71,4 @@ def handle(self,*args, **options):
print "Error: you must enter a single valid provider or define NODES in your settings"
sys.exit(1)
- destroynode(provider, secret_key, uid, image_id)
+ destroy_node(provider, secret_key, uid, image_id)
@@ -10,7 +10,7 @@
from libcloud.types import Provider
-from woven.api import listnodes, set_env
+from woven.api import list_nodes, set_env
class Command(BaseCommand):
"""
@@ -68,4 +68,4 @@ def handle(self,*args, **options):
print "Error: you must enter a single valid provider or define NODES in your settings"
sys.exit(1)
- listnodes(provider, secret_key, uid)
+ list_nodes(provider, secret_key, uid)

0 comments on commit e31f871

Please sign in to comment.