%PDF- %PDF-
Direktori : /usr/lib/python2.7/site-packages/salt/runners/ |
Current File : //usr/lib/python2.7/site-packages/salt/runners/queue.pyc |
� ���^c @@ s� d Z d d l m Z m Z m Z d d l Z d d l m Z d d l m Z m Z d d l m Z d d � Z d d � Z d d � Z d d � Z d d � Z d d e d � Z d d e d � Z d d d � Z d d d d d � Z d d d d � Z d S( u� General management and processing of queues. ============================================ This runner facilitates interacting with various queue backends such as the included sqlite3 queue or the planned AWS SQS and Redis queues The queue functions such as `insert`, `delete`, and `pop` can be used for typical management of the queue. The `process_queue` function pops the requested number of items from the queue and creates a Salt Event that can then be processed by a Reactor. The `process_queue` function can be called manually, or can be configured to run on a schedule with the Salt Scheduler or regular system cron. It is also possible to use the peer system to allow a minion to call the runner. This runner, as well as the Queues system, is not api stable at this time. There are many things that could potentially be done with queues within Salt. For the time being the focus will be on queueing infrastructure actions on specific minions. The queues generally will be populated with minion IDs. When the `process_queue` runner function is called events are created on the Salt Event bus that indicate the queue and a list of one or more minion IDs. The reactor is set up to match on event tags for a specific queue and then take infrastructure actions on those minion IDs. These actions might be to delete the minion's key from the master, use salt-cloud to destroy the vm, or some other custom action. Queued runners ============== Using the Salt Queues, references to the commandline arguments of other runners can be saved to be processed later. The queue runners require a queue backend that can store json data (default: :mod:`pgjsonb <salt.queues.pgjsonb_queue>`). Once the queue is setup, the `runner_queue` will need to be configured. .. code-block:: yaml runner_queue: queue: runners backend: pgjsonb .. note:: only the queue is required, this defaults to using pgjsonb Once this is set, then the following can be added to the scheduler on the master and it will run the specified amount of commands per time period. .. code-block:: yaml schedule: runner queue: schedule: function: queue.process_runner minutes: 1 kwargs: quantity: 2 The above configuration will pop 2 runner jobs off the runner queue, and then run them. And it will do this every minute, unless there are any jobs that are still running from the last time the process_runner task was executed. i ( t absolute_importt print_functiont unicode_literalsN( t six( t get_eventt tagify( t SaltInvocationErroru sqlitec C@ sb t j j t � } d j | � } | | k rE t d j | � � � n | | d | d | � } | S( uV Add an item or items to a queue CLI Example: .. code-block:: bash salt-run queue.insert myqueue myitem salt-run queue.insert myqueue "['item1', 'item2', 'item3']" salt-run queue.insert myqueue myitem backend=sqlite salt-run queue.insert myqueue "['item1', 'item2', 'item3']" backend=sqlite u {0}.insertu Function "{0}" is not availablet itemst queue( t saltt loadert queuest __opts__t formatR ( R R t backendt queue_funcst cmdt ret( ( s6 /usr/lib/python2.7/site-packages/salt/runners/queue.pyt insertK s c C@ sb t j j t � } d j | � } | | k rE t d j | � � � n | | d | d | � } | S( u Delete an item or items from a queue CLI Example: .. code-block:: bash salt-run queue.delete myqueue myitem salt-run queue.delete myqueue myitem backend=sqlite salt-run queue.delete myqueue "['item1', 'item2', 'item3']" u {0}.deleteu Function "{0}" is not availableR R ( R R R R R R ( R R R R R R ( ( s6 /usr/lib/python2.7/site-packages/salt/runners/queue.pyt delete` s c C@ sV t j j t � } d j | � } | | k rE t d j | � � � n | | � } | S( u� Return a list of Salt Queues on the backend CLI Example: .. code-block:: bash salt-run queue.list_queues salt-run queue.list_queues backend=sqlite u {0}.list_queuesu Function "{0}" is not available( R R R R R R ( R R R R ( ( s6 /usr/lib/python2.7/site-packages/salt/runners/queue.pyt list_queuest s c C@ s\ t j j t � } d j | � } | | k rE t d j | � � � n | | d | � } | S( u� Provide the number of items in a queue CLI Example: .. code-block:: bash salt-run queue.list_length myqueue salt-run queue.list_length myqueue backend=sqlite u {0}.list_lengthu Function "{0}" is not availableR ( R R R R R R ( R R R R R ( ( s6 /usr/lib/python2.7/site-packages/salt/runners/queue.pyt list_length� s c C@ s\ t j j t � } d j | � } | | k rE t d j | � � � n | | d | � } | S( u� List contents of a queue CLI Example: .. code-block:: bash salt-run queue.list_items myqueue salt-run queue.list_items myqueue backend=sqlite u {0}.list_itemsu Function "{0}" is not availableR ( R R R R R R ( R R R R R ( ( s6 /usr/lib/python2.7/site-packages/salt/runners/queue.pyt list_items� s i c C@ sh t j j t � } d j | � } | | k rE t d j | � � � n | | d | d | d | � } | S( u9 Pop one or more or all items from a queue CLI Example: .. code-block:: bash salt-run queue.pop myqueue salt-run queue.pop myqueue 6 salt-run queue.pop myqueue all salt-run queue.pop myqueue 6 backend=sqlite salt-run queue.pop myqueue all backend=sqlite u {0}.popu Function "{0}" is not availablet quantityR t is_runner( R R R R R R ( R R R R R R R ( ( s6 /usr/lib/python2.7/site-packages/salt/runners/queue.pyt pop� s c C@ s� t d t d t d d t d t �} y% t d | d | d | d | � } Wn: t k r� } d j | � } t j i | d 6d � t SXi | d 6| d 6| d 6} | j | t | d g d d �� | S( u4 Pop items off a queue and create an event on the Salt event bus to be processed by a Reactor. CLI Example: .. code-block:: bash salt-run queue.process_queue myqueue salt-run queue.process_queue myqueue 6 salt-run queue.process_queue myqueue all backend=sqlite u masteru sock_diru transportt optst listenR R R R u {0}u errorsu progressu itemsu backendu queueu processt prefix( R R t FalseR R R t __jid_event__t fire_eventR ( R R R R t eventR t exct error_txtt data( ( s6 /usr/lib/python2.7/site-packages/salt/runners/queue.pyt process_queue� s"