Coder Social home page Coder Social logo

rundeckrun's Introduction

RundeckRun

READ FIRST
If you're new to RundeckRun and are interacting with newer versions of Rundeck (>=2.1.3), you should consider using the command line tools included with Rundeck (since at least Rundeck version 2.0.4). RundeckRun should work well for the Rundeck API up to version 11 (Rundeck <=2.1.3). It currently does not support Rundeck API versions greater than 11 for no other reason the project maintainer not having enough time to put into making the necessary changes. Pull requests welcome!

A client library written in Python to interact with the Rundeck API. It uses the awesome requests library.

Documentation is hosted on Read the Docs

DISCLAIMER: Test suite is not comprehensive, but most features have been tested and should work. Should work on at least Python 2.7 and Python 3.3.

Installation

Requires

$ pip install rundeckrun

Use

>>> from rundeck.client import Rundeck
>>> rd = Rundeck('rundeck.server.com', api_token='SECRET_API_TOKEN')
>>> rd.list_projects()
[{
    'description': None,
    'name': 'TestProject',
    'resources': {'providerURL': 'http://localhost:8000/resources.xml'},
}]
>>> rd.list_jobs('TestProject')
[{'description': 'Hello World!',
  'group': None,
  'id': 'a6e1e0f7-ad32-4b93-ba2c-9387be06a146',
  'name': 'HelloWorld',
  'project': 'TestProject'}]
>>> rd.run_job('a6e1e0f7-ad32-4b93-ba2c-9387be06a146', argString={'from':'RundeckRun'})
{'argstring': '-from RundeckRun',
 'date-started': datetime.datetime(2013, 7, 11, 18, 4, 24),
 'description': 'Plugin[localexec, nodeStep: true]',
 'href': 'http://rundeck.server.com/execution/follow/123',
 'id': '123',
 'job': None,
 'status': 'running',
 'user': 'rundeckrun'}

Running Tests

Note

You'll probably want to create a virtualenv for this.

Running the tests requires a running Rundeck server (the Rundeck standalone jar works well) and an API token for said Rundeck server.

You'll have to at least set the API token environment variable of RUNDECK_API_TOKEN but there are other environment variables to be aware of. The list is below and can be found at the head of the tests/__init__.py file. They should be fairly self-explanatory (OK, RUNDECK_PROTOCOL might not be self-explanatory... use either 'http' or 'https' there).

RUNDECK_API_TOKEN
RUNDECK_SERVER
RUNDECK_PORT
RUNDECK_PROTOCOL

Next clone the repo.

git clone https://github.com/marklap/rundeckrun

Note

activate your virtualenv

Then install the requirements and dev requirements.

pip install -r requirements.txt
pip install -r requirements_dev.txt

Lastly, execute nose tests.

nosetests

rundeckrun's People

Contributors

aodag avatar marklap avatar pgtest2 avatar zyv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rundeckrun's Issues

Bug in test/__init__.py

line 4: import rundeck.client import Rundeck

Should be:
from rundeck.client import Rundeck

This causes setup to fail

Exception in update_project_resources method

Hi, faced with the following problem when tried to update resources:

...
new_node = {"name": "some_node", "hostname": "some_node.some_domain", "username": "some_user"}
rd.update_project_resources(project, nodes=[new_node])

Traceback (most recent call last):
  File "rundeck_test.py", line 20, in <module>
    rd.update_project_resources(project, nodes=[new_node])
  File "/usr/local/lib/python2.7/dist-packages/rundeckrun-0.1.12-py2.7.egg/rundeck/transforms.py", line 258, in wrapper
    results = func(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/rundeckrun-0.1.12-py2.7.egg/rundeck/client.py", line 964, in update_project_resources
    if isinstance(node, dict) and set(d.keys()).issuperset(required_keys):
NameError: global name 'd' is not defined

Seems that 'node' variable should be used instead of 'd'. Can you please check and fix it? Thank you in advance!

Create Project

Is there any possibiltiy to create project using rundeckrun?

jobs failing on ec2 nodes

I'm using rundeckrun to execute various jobs on physical servers with no problem. However when I try to execute the same jobs on an ec2 node suing the rundeck ec2 plugin it's failing .

If I execute the jobs from the Rundeck UI there are no issues, the problem is only when I execute the jobs on ec2 nodes from rundeckrun.

The rundeckrun output from my script is always the same when failing or not :

/usr/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py:768: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html
  InsecureRequestWarning)

This is what I see from the UI Log output :

21:23:52    rundeck.example.com     com.dtolabs.rundeck.core.NodesetEmptyException: No matched nodes: NodeSet{includes={hostname=server1.example.com, dominant=true, }}
21:23:52                at com.dtolabs.rundeck.core.execution.workflow.NodeFirstWorkflowStrategy.validateNodeSet(NodeFirstWorkflowStrategy.java:333)
21:23:52                at com.dtolabs.rundeck.core.execution.workflow.NodeFirstWorkflowStrategy.executeWorkflowImpl(NodeFirstWorkflowStrategy.java:85)
21:23:52                at com.dtolabs.rundeck.core.execution.workflow.BaseWorkflowStrategy.executeWorkflow(BaseWorkflowStrategy.java:124)
21:23:52                at com.dtolabs.rundeck.core.execution.WorkflowExecutionServiceThread.run(WorkflowExecutionServiceThread.java:55)
21:23:53            Exception: class com.dtolabs.rundeck.core.NodesetEmptyException: No matched nodes: NodeSet{includes={hostname=server1.example.com, dominant=true, }}
21:23:53            No matched nodes: NodeSet{includes={hostname=server1.example.com, dominant=true, }}

The above error is the same for any kind of job I run on any ec2 node.

Rundeckrun = 0.1.15
requests = 2.7.0
Rundeck server = 2.4.0-1

rundeckrun is not working with SSL/HTTPS

Hi,

I'm able to run jobs on Rundeck when the server is listening on the standard port 4440 on HTTP for security reasons I had to change the port to 4443 with HTTPS and my python program is not working anymore..

#!/usr/bin/python3

import sys
from rundeck.client import Rundeck

RUNDECK_SERVER='rundeck.mydomain.com'
RUNDECK_PORT=4443
PROTOCOL='https'
API_TOKEN="dfljLIUREJKDlkirleliufkJIFRE42"
JOB_ID="34334d4j9dj29-1989-40f7-8aa6-2b9a10399a2b"

rd = Rundeck(RUNDECK_SERVER, protocol=PROTOCOL, port=RUNDECK_PORT,api_token=API_TOKEN)

rd.run_job(JOB_ID, argString={'from':'Rundeckrun'})

Output :

Traceback (most recent call last):
  File "/usr/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py", line 518, in urlopen
    body=body, headers=headers)
  File "/usr/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py", line 322, in _make_request
    self._validate_conn(conn)
  File "/usr/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py", line 727, in _validate_conn
    conn.connect()
  File "/usr/lib/python3.4/site-packages/requests/packages/urllib3/connection.py", line 238, in connect
    ssl_version=resolved_ssl_version)
  File "/usr/lib/python3.4/site-packages/requests/packages/urllib3/util/ssl_.py", line 253, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "/usr/lib64/python3.4/ssl.py", line 364, in wrap_socket
    _context=self)
  File "/usr/lib64/python3.4/ssl.py", line 578, in __init__
    self.do_handshake()
  File "/usr/lib64/python3.4/ssl.py", line 805, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.4/site-packages/requests/adapters.py", line 370, in send
    timeout=timeout
  File "/usr/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py", line 548, in urlopen
    raise SSLError(e)
requests.packages.urllib3.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./zabbix_rundeck.py", line 50, in <module>
    rd.run_job(JOB_ID, argString={'Zabbix':'Auto-Healing'}, hostname=TARGET)
  File "/usr/lib/python3.4/site-packages/rundeck/client.py", line 247, in run_job
    execution = self._run_job(job_id, **kwargs)
  File "/usr/lib/python3.4/site-packages/rundeck/transforms.py", line 258, in wrapper
    results = func(self, *args, **kwargs)
  File "/usr/lib/python3.4/site-packages/rundeck/client.py", line 324, in _run_job
    return self.api.job_run(job_id, **kwargs)
  File "/usr/lib/python3.4/site-packages/rundeck/api.py", line 357, in job_run
    return self._exec(GET, 'job/{0}/run'.format(job_id), params=params, **kwargs)
  File "/usr/lib/python3.4/site-packages/rundeck/api.py", line 1053, in _exec
    method, url, params=params, data=data, parse_response=parse_response, **kwargs)
  File "/usr/lib/python3.4/site-packages/rundeck/api.py", line 224, in _exec
    method, url, params=params, data=data, parse_response=parse_response, **kwargs)
  File "/usr/lib/python3.4/site-packages/rundeck/connection.py", line 232, in call
    method, url, params=params, data=data, headers=headers, files=files, **kwargs)
  File "/usr/lib/python3.4/site-packages/rundeck/connection.py", line 284, in request
    method, url, params=params, data=data, headers=headers, files=files)
  File "/usr/lib/python3.4/site-packages/rundeck/connection.py", line 257, in request
    method, url, params=params, data=data, headers=headers, files=files)
  File "/usr/lib/python3.4/site-packages/requests/sessions.py", line 461, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3.4/site-packages/requests/sessions.py", line 573, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3.4/site-packages/requests/adapters.py", line 431, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600)

Versions installed

python3.4
pip3.4
rundeckrun=0.1.11
bottle=0.11.6
nose=1.3.0
requests=2.5.1

Unclean server url handling issue

When trying to access the Rundeck API via a URl such as http://rundeckserver:4440/rundeck/api/etc... the requests module throws a HTTPError exception. In our environment the rundeck server resides behind such a URL.

Creating the Rundeck object works fine, but when trying to access Rundeck the Exception rises. Looking into the Rundeck object gives the following:

rd = Rundeck(server='rundeckserver/rundeck', api_token='secret', verify_cert=False)
rd.api.connection.base_api_url
'http://rundeck01.mgmt.dvag.net/rundeck:4440/api'

Guess the following should clear the issue at this line: https://github.com/marklap/rundeckrun/blob/master/rundeck/connection.py#L138

        if (protocol == 'http' and port != 80) or (protocol == 'https' and port != 443):
            parted_server = server.partition('/')
            if parted_server[2]:
                self.server = '{0}:{1}/{2}'.format(parted_server[0], port, parted_server[2])
            else:
                self.server = '{0}:{1}'.format(server, port)

Tests are installed in top-level site-packages directory

Hi Mark,

Unfortunately, when rundeckrun is installed, tests are installed as well as a top-level tests package in site-packages. It's better to not to take such a generic package name in order to avoid conflicts.

I can see two different solutions to this:

  1. one possibility is to move tests inside rundeckrun namespace
  2. another possibility is leave tests the way they are, and simply not install them

I could try to come up with a pull request if you want, but then I'd need to know which solution you would prefer...

Many thanks!

Your license is funny

Hi there,

CC-BY-SA is heavily disreputed for using with software projects. It's fine for text, books, and documentation, but using it with code just generates headaches.

Could you please change it to some permissive license, like BSD, MIT, ISC, or a weak copyleft license like the Apache License 2.0 ?

Create job

How to create job in Rundeck using rundeckrun?

run_job method, Not passing proper argument values, if argument has space in string

Hi Guys,

When we use run_job method, argument as spaces in string means, not properly passing to the main job.

for example In our case '2.dv_lead_id': ' FC BD sub J ZH0010 P1' argument has space, When we try to execute the job, It passes only FC only.

[INFO] ==> let's start rundeck job id=186c8375-574f-4a83-9773-3f6430cd9efc, args={'3.prev_campaign_id': 'FCBDsubQZH0010P3', '4.provider_lead_id': '7c4648becf', '2.dv_lead_id': ' FC BD sub J ZH0010 P1', '1.action': 'talos_automation'}
let's print job_id=http://172.16.60.21:4440/execution/follow/94936, job_status=failed

print "[INFO] ==> let's start rundeck job id=%s, args=%s" % (RUNDECK_JOB_UUID, jobArgs)
execution = rd.run_job(RUNDECK_JOB_UUID, argString=jobArgs)

NOTE:
It's working fine, if arguments has no space between characters.

Please let me know, if any you any questions.

Kind regards,
-Dhanasekaran

rd.get_execution_output returns Attribute error

After executing a job and running rd.get_execution_output(job_id) command, I get python Attribute error as shown below:

rd.get_execution_output('30')
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.7/dist-packages/rundeck/client.py", line 656, in get_execution_output
return results._as_dict_method(results)
AttributeError: 'dict' object has no attribute '_as_dict_method'

Running the same job without trying to serialize output to json (e.g. having "raw" option enabled) works fine (output attached)

rundeck_output.txt

Support for multi-value params when running a job

In Rundeck, you can add parameters which take multiple parameters (see screenshot).
I'd like to mimic this in RundeckRun. I can't seem to send multiple values to a job.
Similarily, I haven't found any documentation about the Rundeck API that says this is (or is not) possible.
screen shot 2014-11-06 at 11 55 21 am

Feature request : Need one call to delete older job execution

Currently we can list older job executions but no call to delete them.. Yeah, we can pass the execution IDs to http API urls and can invoke with curl but would have been nicer if we have rundeckrun call to remove old executions with execution id as arg.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.