Skip to content

Commit

Permalink
set node online/offline
Browse files Browse the repository at this point in the history
  • Loading branch information
lruslan committed Jan 18, 2013
1 parent 8be11f3 commit cc5c421
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions jenkinsapi/node.py
Original file line number Diff line number Diff line change
@@ -1,5 1,6 @@
from jenkinsapi.jenkinsbase import JenkinsBase
import logging
import urllib

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -33,11 34,49 @@ def get_node_data(self):
return self._data

def is_online(self):
self.poll()
return not self._data['offline']

def is_temporarily_offline(self):
self.poll()
return self._data['temporarilyOffline']

def is_jnlpagent(self):
return self._data['jnlpAgent']

def is_idle(self):
return self._data['idle']


def set_online(self):
self.poll()
if self._data['offline'] and not self._data['temporarilyOffline']:
raise AssertionError("Node is offline and not marked as temporarilyOffline"
", check client connection: "
"offline = %s , temporarilyOffline = %s" %
(self._data['offline'], self._data['temporarilyOffline']))
elif self._data['offline'] and self._data['temporarilyOffline']:
self.toggle_temporarily_offline()
self.poll()
if self._data['offline']:
raise AssertionError("The node state is still offline, check client connection:"
" offline = %s , temporarilyOffline = %s" %
(self._data['offline'], self._data['temporarilyOffline']))

def set_offline(self, message="requested from jenkinsapi"):
self.poll()
if not self._data['offline']:
self.toggle_temporarily_offline(message)
self.poll()
if not self._data['offline']:
raise AssertionError("The node state is still online:"
"offline = %s , temporarilyOffline = %s" %
(self._data['offline'], self._data['temporarilyOffline']))

def toggle_temporarily_offline(self, message="requested from jenkinsapi"):
initial_state = self.is_temporarily_offline()
url = self.baseurl "/toggleOffline?offlineMessage=" urllib.quote(message)
html_result = self.hit_url(url)
log.debug(html_result)
if initial_state == self.is_temporarily_offline():
raise AssertionError("The node state has not changed: temporarilyOffline = %s" % state)

0 comments on commit cc5c421

Please sign in to comment.