clean up and make the queue states work

This commit is contained in:
Daniel Wallace 2014-09-21 17:41:59 -05:00
parent d156b46dc4
commit 8551118ab1
3 changed files with 38 additions and 51 deletions

View File

@ -10,48 +10,12 @@ module instead.
'''
# pylint: disable=E0102
# The import section is mostly libcloud boilerplate
# Import python libs
import os
import logging
import socket
import pprint
# Import generic libcloud functions
from salt.cloud.libcloudfuncs import * # pylint: disable=W0614,W0401
import salt.utils.openstack.pyrax as suop
import salt.utils.cloud
# Import salt libs
import salt.utils
import salt.client
# Import salt.cloud libs
import salt.utils.cloud
import salt.config as config
from salt.utils import namespaced_function
from salt.exceptions import (
SaltCloudConfigError,
SaltCloudNotFound,
SaltCloudSystemExit,
SaltCloudExecutionFailure,
SaltCloudExecutionTimeout
)
# Get logging started
log = logging.getLogger(__name__)
# namespace libcloudfuncs
get_salt_interface = namespaced_function(get_salt_interface, globals())
# Some of the libcloud functions need to be in the same namespace as the
# functions defined in the module, so we create new function objects inside
# this module namespace
script = namespaced_function(script, globals())
reboot = namespaced_function(reboot, globals())
# Import pyrax libraries
import salt.utils.openstack.pyrax as suop
# Only load in this module is the OPENSTACK configurations are in place
def __virtual__():
@ -87,21 +51,28 @@ def get_conn(conn_type):
return conn(**kwargs)
def queues_exists(call, kwargs):
conn = get_conn('RackspaceQueues')
return conn.exists(kwargs['name'])
def queues_show(call, kwargs):
conn = get_conn('RackspaceQueues')
return salt.utils.cloud.simple_types_filter(conn.show(kwargs['name']).__dict__)
def queues_create(call, kwargs):
conn = get_conn('RackspaceQueues')
if conn.create(kwargs['name']):
return conn.exists(kwargs['name']).__dict__
return salt.utils.cloud.simple_types_filter(conn.show(kwargs['name']).__dict__)
else:
return {}
def queues_delete(call, kwargs):
conn = get_conn('RackspaceQueues')
ret = conn.exists(kwargs['name']).__dict__
if conn.delete(kwargs['name']):
return {}
else:
return ret
return salt.utils.cloud.simple_types_filter(conn.show(kwargs['name'].__dict__))

View File

@ -73,7 +73,7 @@ def present(name, provider):
'''
ret = {'name': name, 'result': True, 'comment': '', 'changes': {}}
is_present = __salt__['cloud.action']('queues_exists', provider, name=name)
is_present = __salt__['cloud.action']('queues_exists', provider=provider, name=name)[provider].values()[0]
if not is_present:
if __opts__['test']:
@ -81,10 +81,11 @@ def present(name, provider):
ret['comment'] = msg
ret['result'] = None
return ret
created = __salt__['cloud.action']('queues_create', provider, name)
created = __salt__['cloud.action']('queues_create', provider=provider, name=name)
if created:
queue = __salt__['cloud.action']('queues_show', provider=provider, name=name)
ret['changes']['old'] = {}
ret['changes']['new'] = {'queue': created}
ret['changes']['new'] = {'queue': queue}
else:
ret['result'] = False
ret['comment'] = 'Failed to create {0} Rackspace queue.'.format(name)
@ -107,7 +108,7 @@ def absent(name, provider):
'''
ret = {'name': name, 'result': True, 'comment': '', 'changes': {}}
is_present = __salt__['cloud.action']('queues_exists', provider, name=name)
is_present = __salt__['cloud.action']('queues_exists', provider=provider, name=name)[provider].values()[0]
if is_present:
if __opts__['test']:
@ -115,14 +116,15 @@ def absent(name, provider):
name)
ret['result'] = None
return ret
deleted = __salt__['cloud.action']('queues_delete', provider, name)
queue = __salt__['cloud.action']('queues_show', provider=provider, name=name)
deleted = __salt__['cloud.action']('queues_delete', provider=provider, name=name)
if deleted:
ret['changes']['old'] = is_present
ret['changes']['old'] = queue
ret['changes']['new'] = {}
else:
ret['result'] = False
ret['comment'] = 'Failed to delete {0} Rackspace queue.'.format(name)
else:
ret['comment'] = '{0} does not exist in {1}.'.format(name, region)
ret['comment'] = '{0} does not exist.'.format(name)
return ret

View File

@ -43,9 +43,10 @@ class RackspaceQueues(object):
'''
try:
q = self.exists(qname)
log.debug('LOGGING: %s' % q)
if not q:
return False
q.delete()
self.show(qname).delete()
except pyrax.exceptions as err_msg:
log.error('RackSpace API got some problems during deletion: %s' % err_msg)
@ -57,6 +58,19 @@ class RackspaceQueues(object):
'''
Check to see if a Queue exists.
'''
try:
# First if not exists() -> exit
if self.conn.queue_exists(qname):
return True
return False
except pyrax.exceptions as err_msg:
log.error('RackSpace API got some problems during existing queue check: %s' % err_msg)
return False
def show(self, qname):
'''
Show information about Queue
'''
try:
# First if not exists() -> exit
if not self.conn.queue_exists(qname):
@ -64,7 +78,7 @@ class RackspaceQueues(object):
# If exist, search the queue to return the Queue Object
for queue in self.conn.list():
if queue.name == qname:
return queue.__dict__
return queue
except pyrax.exceptions as err_msg:
log.error('RackSpace API got some problems during existing queue check: %s' % err_msg)
return {}