Remove duplicate python-jenkins code from nodepool
This is a redo of change I3852106ae6 which was reverted in I53f1f86d3c6. The reason why it didn't work previously was because a bug to the create_node method was introduced in python-jenkins while the nodepool change was sitting around waiting to be approved. That bug has now been fixed in change I85fa43bc0b and a new release has been created with the fix so this change should work now. Change-Id: If54eaa9b4b9a0abd732f2cd22ac6b7ededc64855
This commit is contained in:
parent
c44c72a360
commit
8bd03e3acd
|
@ -19,7 +19,7 @@
|
|||
import logging
|
||||
import re
|
||||
|
||||
import myjenkins
|
||||
import jenkins
|
||||
import fakeprovider
|
||||
from task_manager import Task, TaskManager
|
||||
|
||||
|
@ -47,7 +47,7 @@ class CreateNodeTask(Task):
|
|||
args['labels'] = self.args['labels']
|
||||
try:
|
||||
jenkins.create_node(**args)
|
||||
except myjenkins.JenkinsException as e:
|
||||
except jenkins.JenkinsException as e:
|
||||
if 'already exists' in str(e):
|
||||
pass
|
||||
else:
|
||||
|
@ -96,9 +96,9 @@ class JenkinsManager(TaskManager):
|
|||
def _getClient(self):
|
||||
if self.target.jenkins_apikey == 'fake':
|
||||
return fakeprovider.FakeJenkins(self.target.jenkins_user)
|
||||
return myjenkins.Jenkins(self.target.jenkins_url,
|
||||
self.target.jenkins_user,
|
||||
self.target.jenkins_apikey)
|
||||
return jenkins.Jenkins(self.target.jenkins_url,
|
||||
self.target.jenkins_user,
|
||||
self.target.jenkins_apikey)
|
||||
|
||||
def createNode(self, name, host, description, executors, root, labels=[],
|
||||
credentials_id=None, username=None, private_key=None):
|
||||
|
|
|
@ -1,136 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# Copyright 2011-2013 OpenStack Foundation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import jenkins
|
||||
import json
|
||||
|
||||
import six.moves.urllib.parse as urlparse
|
||||
import six.moves.urllib.request as urlrequest
|
||||
|
||||
from jenkins import JenkinsException, NODE_TYPE, CREATE_NODE
|
||||
|
||||
TOGGLE_OFFLINE = '/computer/%(name)s/toggleOffline?offlineMessage=%(msg)s'
|
||||
CONFIG_NODE = '/computer/%(name)s/config.xml'
|
||||
|
||||
|
||||
class Jenkins(jenkins.Jenkins):
|
||||
def disable_node(self, name, msg=''):
|
||||
'''
|
||||
Disable a node
|
||||
|
||||
@param name: Jenkins node name
|
||||
@type name: str
|
||||
@param msg: Offline message
|
||||
@type msg: str
|
||||
'''
|
||||
info = self.get_node_info(name)
|
||||
if info['offline']:
|
||||
return
|
||||
self.jenkins_open(
|
||||
urlrequest.Request(self.server + TOGGLE_OFFLINE % locals()))
|
||||
|
||||
def enable_node(self, name):
|
||||
'''
|
||||
Enable a node
|
||||
|
||||
@param name: Jenkins node name
|
||||
@type name: str
|
||||
'''
|
||||
info = self.get_node_info(name)
|
||||
if not info['offline']:
|
||||
return
|
||||
msg = ''
|
||||
self.jenkins_open(
|
||||
urlrequest.Request(self.server + TOGGLE_OFFLINE % locals()))
|
||||
|
||||
def get_node_config(self, name):
|
||||
'''
|
||||
Get the configuration for a node.
|
||||
|
||||
:param name: Jenkins node name, ``str``
|
||||
'''
|
||||
get_config_url = self.server + CONFIG_NODE % locals()
|
||||
return self.jenkins_open(urlrequest.Request(get_config_url))
|
||||
|
||||
def reconfig_node(self, name, config_xml):
|
||||
'''
|
||||
Change the configuration for an existing node.
|
||||
|
||||
:param name: Jenkins node name, ``str``
|
||||
:param config_xml: New XML configuration, ``str``
|
||||
'''
|
||||
headers = {'Content-Type': 'text/xml'}
|
||||
reconfig_url = self.server + CONFIG_NODE % locals()
|
||||
self.jenkins_open(
|
||||
urlrequest.Request(reconfig_url, config_xml, headers))
|
||||
|
||||
def create_node(self, name, numExecutors=2, nodeDescription=None,
|
||||
remoteFS='/var/lib/jenkins', labels=None, exclusive=False,
|
||||
launcher='hudson.slaves.JNLPLauncher', launcher_params={}):
|
||||
'''
|
||||
@param name: name of node to create
|
||||
@type name: str
|
||||
@param numExecutors: number of executors for node
|
||||
@type numExecutors: int
|
||||
@param nodeDescription: Description of node
|
||||
@type nodeDescription: str
|
||||
@param remoteFS: Remote filesystem location to use
|
||||
@type remoteFS: str
|
||||
@param labels: Labels to associate with node
|
||||
@type labels: str
|
||||
@param exclusive: Use this node for tied jobs only
|
||||
@type exclusive: boolean
|
||||
@param launcher: The launch method for the slave
|
||||
@type launcher: str
|
||||
@param launcher_params: Additional parameters for the launcher
|
||||
@type launcher_params: dict
|
||||
'''
|
||||
if self.node_exists(name):
|
||||
raise JenkinsException('node[%s] already exists' % (name))
|
||||
|
||||
mode = 'NORMAL'
|
||||
if exclusive:
|
||||
mode = 'EXCLUSIVE'
|
||||
|
||||
#hudson.plugins.sshslaves.SSHLauncher
|
||||
#hudson.slaves.CommandLauncher
|
||||
#hudson.os.windows.ManagedWindowsServiceLauncher
|
||||
launcher_params['stapler-class'] = launcher
|
||||
|
||||
inner_params = {
|
||||
'name': name,
|
||||
'nodeDescription': nodeDescription,
|
||||
'numExecutors': numExecutors,
|
||||
'remoteFS': remoteFS,
|
||||
'labelString': labels,
|
||||
'mode': mode,
|
||||
'type': NODE_TYPE,
|
||||
'retentionStrategy': {
|
||||
'stapler-class': 'hudson.slaves.RetentionStrategy$Always'},
|
||||
'nodeProperties': {'stapler-class-bag': 'true'},
|
||||
'launcher': launcher_params
|
||||
}
|
||||
|
||||
params = {
|
||||
'name': name,
|
||||
'type': NODE_TYPE,
|
||||
'json': json.dumps(inner_params)
|
||||
}
|
||||
|
||||
self.jenkins_open(urlrequest.Request(
|
||||
self.server + CREATE_NODE % urlparse.urlencode(params)))
|
||||
|
||||
if not self.node_exists(name):
|
||||
raise JenkinsException('create[%s] failed' % (name))
|
|
@ -2,7 +2,7 @@ pbr>=1.3
|
|||
|
||||
gear
|
||||
PyYAML
|
||||
python-jenkins
|
||||
python-jenkins>=0.4.12
|
||||
paramiko>1.11.6,<2.0.0
|
||||
python-daemon>=2.0.4,<2.1.0
|
||||
extras
|
||||
|
|
Loading…
Reference in New Issue