Add support for Jenkins OpenStack Cloud Plugin
This commit adds support for [Openstack Cloud Plugin] (https://wiki.jenkins-ci.org/display/JENKINS/Openstack+Cloud+Plugin). Change-Id: Ic3cf46908113cdb1c0bc50005d470a7da8a86f60 Signed-off-by: Ryo Tagami <rtagami@airstrip.jp>
This commit is contained in:
parent
e8424c9c64
commit
6ce5c6a31a
@ -1108,6 +1108,67 @@ def jclouds(parser, xml_parent, data):
|
||||
'JCloudsOneOffSlave')
|
||||
|
||||
|
||||
def openstack(parser, xml_parent, data):
|
||||
"""yaml: openstack
|
||||
Provision slaves from OpenStack on demand. Requires the Jenkins
|
||||
:jenkins-wiki:`Openstack Cloud Plugin <Openstack+Cloud+Plugin>`.
|
||||
|
||||
:arg list instances: List of instances to be launched at the beginning of
|
||||
the build.
|
||||
|
||||
:instances:
|
||||
* **cloud-name** (`str`) -- The name of the cloud profile which
|
||||
contains the specified cloud instance template (required).
|
||||
* **template-name** (`str`) -- The name of the cloud instance
|
||||
template to create an instance from(required).
|
||||
* **manual-template** (`bool`) -- If True, instance template name
|
||||
will be put in 'Specify Template Name as String' option. Not
|
||||
specifying or specifying False, instance template name will be
|
||||
put in 'Select Template from List' option. To use parameter
|
||||
replacement, set this to True. (default: False)
|
||||
* **count** (`int`) -- How many instances to create (default: 1).
|
||||
|
||||
:arg bool single-use: Whether or not to terminate the slave after use
|
||||
(default: False).
|
||||
|
||||
Example:
|
||||
|
||||
.. literalinclude:: /../../tests/wrappers/fixtures/openstack001.yaml
|
||||
"""
|
||||
tag_prefix = 'jenkins.plugins.openstack.compute.'
|
||||
|
||||
if 'instances' in data:
|
||||
clouds_build_wrapper = XML.SubElement(
|
||||
xml_parent, tag_prefix + 'JCloudsBuildWrapper')
|
||||
instances_wrapper = XML.SubElement(
|
||||
clouds_build_wrapper, 'instancesToRun')
|
||||
|
||||
for instance in data['instances']:
|
||||
instances_to_run = XML.SubElement(
|
||||
instances_wrapper, tag_prefix + 'InstancesToRun')
|
||||
|
||||
try:
|
||||
cloud_name = instance['cloud-name']
|
||||
template_name = instance['template-name']
|
||||
except KeyError as exception:
|
||||
raise MissingAttributeError(exception.args[0])
|
||||
|
||||
XML.SubElement(instances_to_run, 'cloudName').text = cloud_name
|
||||
|
||||
if instance.get('manual-template', False):
|
||||
XML.SubElement(instances_to_run,
|
||||
'manualTemplateName').text = template_name
|
||||
else:
|
||||
XML.SubElement(instances_to_run,
|
||||
'templateName').text = template_name
|
||||
|
||||
XML.SubElement(instances_to_run, 'count').text = str(
|
||||
instance.get('count', 1))
|
||||
|
||||
if data.get('single-use', False):
|
||||
XML.SubElement(xml_parent, tag_prefix + 'JCloudsOneOffSlave')
|
||||
|
||||
|
||||
def build_user_vars(parser, xml_parent, data):
|
||||
"""yaml: build-user-vars
|
||||
Set environment variables to the value of the user that started the build.
|
||||
|
20
tests/wrappers/fixtures/openstack001.xml
Normal file
20
tests/wrappers/fixtures/openstack001.xml
Normal file
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<buildWrappers>
|
||||
<jenkins.plugins.openstack.compute.JCloudsBuildWrapper>
|
||||
<instancesToRun>
|
||||
<jenkins.plugins.openstack.compute.InstancesToRun>
|
||||
<cloudName>mycloud1</cloudName>
|
||||
<templateName>jenkins-dev-slave</templateName>
|
||||
<count>1</count>
|
||||
</jenkins.plugins.openstack.compute.InstancesToRun>
|
||||
<jenkins.plugins.openstack.compute.InstancesToRun>
|
||||
<cloudName>mycloud2</cloudName>
|
||||
<manualTemplateName>jenkins-test-slave</manualTemplateName>
|
||||
<count>2</count>
|
||||
</jenkins.plugins.openstack.compute.InstancesToRun>
|
||||
</instancesToRun>
|
||||
</jenkins.plugins.openstack.compute.JCloudsBuildWrapper>
|
||||
<jenkins.plugins.openstack.compute.JCloudsOneOffSlave/>
|
||||
</buildWrappers>
|
||||
</project>
|
11
tests/wrappers/fixtures/openstack001.yaml
Normal file
11
tests/wrappers/fixtures/openstack001.yaml
Normal file
@ -0,0 +1,11 @@
|
||||
wrappers:
|
||||
- openstack:
|
||||
instances:
|
||||
- cloud-name: mycloud1
|
||||
template-name: jenkins-dev-slave
|
||||
count: 1
|
||||
- cloud-name: mycloud2
|
||||
template-name: jenkins-test-slave
|
||||
manual-template: True
|
||||
count: 2
|
||||
single-use: True
|
14
tests/wrappers/fixtures/openstack002.xml
Normal file
14
tests/wrappers/fixtures/openstack002.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<buildWrappers>
|
||||
<jenkins.plugins.openstack.compute.JCloudsBuildWrapper>
|
||||
<instancesToRun>
|
||||
<jenkins.plugins.openstack.compute.InstancesToRun>
|
||||
<cloudName>mycloud1</cloudName>
|
||||
<templateName>jenkins-dev-slave</templateName>
|
||||
<count>1</count>
|
||||
</jenkins.plugins.openstack.compute.InstancesToRun>
|
||||
</instancesToRun>
|
||||
</jenkins.plugins.openstack.compute.JCloudsBuildWrapper>
|
||||
</buildWrappers>
|
||||
</project>
|
6
tests/wrappers/fixtures/openstack002.yaml
Normal file
6
tests/wrappers/fixtures/openstack002.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
wrappers:
|
||||
- openstack:
|
||||
instances:
|
||||
- cloud-name: mycloud1
|
||||
template-name: jenkins-dev-slave
|
||||
count: 1
|
6
tests/wrappers/fixtures/openstack003.xml
Normal file
6
tests/wrappers/fixtures/openstack003.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<buildWrappers>
|
||||
<jenkins.plugins.openstack.compute.JCloudsOneOffSlave/>
|
||||
</buildWrappers>
|
||||
</project>
|
3
tests/wrappers/fixtures/openstack003.yaml
Normal file
3
tests/wrappers/fixtures/openstack003.yaml
Normal file
@ -0,0 +1,3 @@
|
||||
wrappers:
|
||||
- openstack:
|
||||
single-use: True
|
Loading…
Reference in New Issue
Block a user