Skip to content

Commit d633ac2

Browse files
authored
Add files via upload
1 parent fe22e6e commit d633ac2

27 files changed

+4195
-0
lines changed

Deadline/Data/deadlineData.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<data>
2+
<settings>
3+
<dept></dept>
4+
<grp>cml_blade</grp>
5+
<pool>show_cml</pool>
6+
<s_pool>show_cml</s_pool>
7+
<prio>58</prio>
8+
<fpt>2</fpt>
9+
<threads>24</threads>
10+
<initialStatus>Suspended</initialStatus>
11+
<frame>FF</frame>
12+
</settings>
13+
</data>

Deadline/Deadline_API/Balancer.py

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
from ConnectionProperty import ConnectionProperty
2+
import json
3+
4+
class Balancer:
5+
"""
6+
Class used by DeadlineCon to send Balancer requests.
7+
Stores the address of the web service for use in sending requests.
8+
"""
9+
def __init__(self, connectionProperties):
10+
self.connectionProperties = connectionProperties
11+
12+
def GetBalancerNames(self):
13+
""" Gets all the balancer names.
14+
Returns: The list of balancer names
15+
"""
16+
return self.connectionProperties.__get__("/api/balancer?NamesOnly=true")
17+
18+
def GetBalancerInfo(self, name):
19+
""" Gets a balancer info.
20+
Input: name: The balancer name
21+
Returns: The balancer info.
22+
"""
23+
return self.connectionProperties.__get__("/api/balancer?Name="+name.replace(' ','+')+"&Info=true")
24+
25+
def GetBalancerInfos(self, names = None):
26+
""" Gets a list of balancer infos.
27+
Input: name: The balancer names to be retrieved. If None then gets all balancer infos
28+
Returns: The balancer infos.
29+
"""
30+
script = "/api/balancer?Info=true"
31+
if names != None:
32+
script = script+"&Names="+ArrayToCommaSeperatedString(names).replace(' ','+')
33+
return self.connectionProperties.__get__(script)
34+
35+
def SaveBalancerInfo(self, info):
36+
""" Saves a balancer info to the database.
37+
Input: info: JSon object of the Balancer info
38+
Returns: Success message
39+
"""
40+
41+
info = json.dumps(info)
42+
43+
body = '{"Command":"saveinfo", "BalancerInfo":'+info+'}'
44+
45+
return self.connectionProperties.__put__("/api/balancer", body)
46+
47+
def GetBalancerSettings(self, name):
48+
""" Gets a balancer settings.
49+
Input: name: The balancer name
50+
Returns: The balancer settings.
51+
"""
52+
return self.connectionProperties.__get__("/api/balancer?Name="+name.replace(' ','+')+"&Settings=true")
53+
54+
def GetBalancerSettingsList(self, names = None):
55+
""" Gets a list of balancer settings.
56+
Input: name: The balancer names to be retrieved. If None then gets all balancer settings
57+
Returns: The balancer settings.
58+
"""
59+
script = "/api/balancer?Settings=true"
60+
if names != None:
61+
script = script+"&Names="+ArrayToCommaSeperatedString(names).replace(' ','+')
62+
63+
return self.connectionProperties.__get__(script)
64+
65+
def SaveBalancerSettings(self, settings):
66+
""" Saves a balancer settings to the database.
67+
Input: settings: JSon object of the Balancer settings
68+
Returns: Success message
69+
"""
70+
71+
settings = json.dumps(settings)
72+
73+
body = '{"Command":"savesettings", "BalancerSettings":'+settings+'}'
74+
75+
return self.connectionProperties.__put__("/api/balancer", body)
76+
77+
def GetBalancerInfoSettings(self, name):
78+
""" Gets a balancer info settings.
79+
Input: name: The balancer name
80+
Returns: The balancer info settings.
81+
"""
82+
return self.connectionProperties.__get__("/api/balancer?Name="+name.replace(' ','+')+"&Settings=true&Info=true")
83+
84+
def GetBalancerInfoSettingsList(self, names = None):
85+
""" Gets a list of balancer info settings.
86+
Input: name: The balancer names to be retrieved. If None then gets all balancer info settings
87+
Returns: The balancer info settings.
88+
"""
89+
script = "/api/balancer"
90+
if names != None:
91+
script = script+"?Names="+ArrayToCommaSeperatedString(names).replace(' ','+')
92+
93+
return self.connectionProperties.__get__(script)
94+
95+
def DeleteBalancer(self, name):
96+
""" Deletes the Balancer instance associated with the name provided.
97+
Input: name: The balancer name to delete.
98+
Returns: Success message
99+
"""
100+
return self.connectionProperties.__delete__("/api/balancer?Name="+name)
101+
102+
#Helper function to seperate arrays into strings
103+
def ArrayToCommaSeperatedString(array):
104+
if isinstance(array, basestring):
105+
return array
106+
else:
107+
i=0
108+
script=""
109+
for i in range(0,len(array)):
110+
if(i!=0):
111+
script+=","
112+
script += str(array[i]);
113+
return script
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import sys, subprocess, os
2+
import json
3+
import traceback
4+
import DeadlineSend
5+
6+
class ConnectionProperty:
7+
8+
def __init__(self, address, useAuth=False):
9+
self.address = address
10+
self.useAuth = useAuth
11+
self.user = ""
12+
self.password = ""
13+
14+
def GetAddress(self):
15+
return self.address
16+
17+
def SetAddress(self, address):
18+
self.address = address
19+
20+
def GetAuthentication(self):
21+
return self.user, self.password
22+
23+
def SetAuthentication(self, user, password):
24+
self.user = user
25+
self.password = password
26+
27+
def AuthenticationEnabled(self):
28+
return self.useAuth
29+
30+
def EnableAuthentication(self, enable):
31+
self.useAuth = enable
32+
33+
def __get__(self, commandString):
34+
35+
return DeadlineSend.send(self.address,commandString, "GET", self.useAuth, self.user, self.password)
36+
37+
def __put__(self, commandString, body):
38+
39+
return DeadlineSend.pSend(self.address, commandString, "PUT", body, self.useAuth, self.user, self.password)
40+
41+
def __delete__(self, commandString):
42+
43+
return DeadlineSend.send(self.address,commandString, "DELETE", self.useAuth, self.user, self.password)
44+
45+
def __post__(self, commandString, body):
46+
47+
return DeadlineSend.pSend(self.address, commandString, "POST", body, self.useAuth, self.user, self.password)
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import sys, subprocess, os
2+
import json
3+
import traceback
4+
import Jobs
5+
import SlavesRenderingJob
6+
import JobReports
7+
import TaskReports
8+
import Limits
9+
import Tasks
10+
import Pulse
11+
import Repository
12+
import MappedPaths
13+
import MaximumPriority
14+
import Pools
15+
import Groups
16+
import Plugins
17+
import Slaves
18+
import Users
19+
import Balancer
20+
from ConnectionProperty import ConnectionProperty
21+
22+
#http://docs.python.org/2/library/httplib.html
23+
24+
class DeadlineCon:
25+
"""
26+
Object used by user to communicate with the web service.
27+
Host name of the web service, as well as the port number the
28+
web service is listening on are required for construction.
29+
Call other API functions through this object.
30+
"""
31+
def __init__(self, host, port):
32+
""" Constructs an instance of DeadlineCon.
33+
Params: host name of the web service (string)
34+
port number the web service is listening on (integer)
35+
"""
36+
37+
#Builds the ConnectionProperty object used for sending requests
38+
address = host+":"+str(port)
39+
self.connectionProperties = ConnectionProperty(address)
40+
41+
#The different request groups use the ConnectionProperty object to send their requests
42+
self.Jobs = Jobs.Jobs(self.connectionProperties)
43+
self.SlavesRenderingJob = SlavesRenderingJob.SlavesRenderingJob(self.connectionProperties)
44+
self.Tasks = Tasks.Tasks(self.connectionProperties)
45+
self.TaskReports = TaskReports.TaskReports(self.connectionProperties)
46+
self.JobReports = JobReports.JobReports(self.connectionProperties)
47+
self.LimitGroups = Limits.LimitGroups(self.connectionProperties)
48+
self.Pulse = Pulse.Pulse(self.connectionProperties)
49+
self.Repository = Repository.Repository(self.connectionProperties)
50+
self.MappedPaths = MappedPaths.MappedPaths(self.connectionProperties)
51+
self.MaximumPriority = MaximumPriority.MaximumPriority(self.connectionProperties)
52+
self.Pools = Pools.Pools(self.connectionProperties)
53+
self.Groups = Groups.Groups(self.connectionProperties)
54+
self.Plugins = Plugins.Plugins(self.connectionProperties)
55+
self.Slaves = Slaves.Slaves(self.connectionProperties)
56+
self.Users = Users.Users(self.connectionProperties)
57+
self.Balancer = Balancer.Balancer(self.connectionProperties)
58+
59+
def EnableAuthentication(self, enable=True):
60+
"""
61+
Toggles authentication mode. If enabled, requests sent through this DeadlineCon object will attempt authentication with the current user name and password credentials.
62+
If the authentication credentials have not been set, authentication will fail. Required to be enabled if the Web Service requires authentication.
63+
Params: whether to disable or enable authentication mode (enabled by default, bool)
64+
"""
65+
self.connectionProperties.EnableAuthentication(enable)
66+
67+
def SetAuthenticationCredentials(self, username, password, enable=True):
68+
"""
69+
Sets the authentication credentials to be used when attempting authentication.
70+
Params: the username credential (string)
71+
the password credential (string)
72+
whether to enable authentication mode or not (enabled by default, bool)
73+
"""
74+
self.connectionProperties.SetAuthentication(username, password)
75+
self.connectionProperties.EnableAuthentication(enable)
76+
77+
def AuthenticationModeEnabled(self):
78+
"""
79+
Returns whether authentication mode is enabled for this DeadlineCon or not. If not, then authentication will fail if the Web Service requires authentication."
80+
"""
81+
return self.connectionProperties.AuthenticationEnabled()

Deadline/Deadline_API/DeadlineSend.py

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import socket
2+
import httplib
3+
import json
4+
import urllib2
5+
import traceback
6+
7+
def send(address, message, requestType, useAuth=False, username="", password=""):
8+
"""
9+
Used for sending requests that do not require message body, like GET and DELETE.
10+
Params: address of the webservice (string)
11+
message to the webservice (string)
12+
request type for the message (string, GET or DELETE)
13+
"""
14+
try:
15+
if not address.startswith("http://"):
16+
address = "http://"+address
17+
url = address + message
18+
19+
if useAuth:
20+
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
21+
22+
password_mgr.add_password(None, url, username, password)
23+
24+
handler = urllib2.HTTPBasicAuthHandler(password_mgr)
25+
opener = urllib2.build_opener(handler)
26+
request = urllib2.Request(url)
27+
request.get_method = lambda: requestType
28+
29+
response = opener.open(request)
30+
else:
31+
opener = urllib2.build_opener(urllib2.HTTPHandler)
32+
request = urllib2.Request(url)
33+
request.get_method = lambda: requestType
34+
35+
response = opener.open(request)
36+
37+
data = response.read()
38+
39+
data = data.replace('\n',' ')
40+
41+
except urllib2.HTTPError, err:
42+
data = traceback.format_exc()
43+
if err.code == 401:
44+
data = "Error: HTTP Status Code 401. Authentication with the Web Service failed. Please ensure that the authentication credentials are set, are correct, and that authentication mode is enabled."
45+
else:
46+
data = err.read()
47+
try:
48+
data = json.loads(data)
49+
except:
50+
pass
51+
52+
return data
53+
54+
def pSend(address, message, requestType, body, useAuth=False, username="", password=""):
55+
"""
56+
Used for sending requests that require a message body, like PUT and POST.
57+
Params: address of the webservice (string)
58+
message to the webservice (string)
59+
request type for the message (string, PUT or POST)
60+
message body for the request (string, JSON object)
61+
"""
62+
response = ""
63+
try:
64+
if not address.startswith("http://"):
65+
address = "http://"+address
66+
url = address + message
67+
68+
if useAuth:
69+
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
70+
71+
password_mgr.add_password(None, url, username, password)
72+
73+
handler = urllib2.HTTPBasicAuthHandler(password_mgr)
74+
opener = urllib2.build_opener(handler)
75+
76+
request = urllib2.Request(url, data=body)
77+
request.get_method = lambda: requestType
78+
79+
response = opener.open(request)
80+
81+
else:
82+
opener = urllib2.build_opener(urllib2.HTTPHandler)
83+
request = urllib2.Request(url, data=body)
84+
request.get_method = lambda: requestType
85+
response = opener.open(request)
86+
87+
data = response.read()
88+
89+
except urllib2.HTTPError, err:
90+
data = traceback.format_exc()
91+
if err.code == 401:
92+
data = "Error: HTTP Status Code 401. Authentication with the Web Service failed. Please ensure that the authentication credentials are set, are correct, and that authentication mode is enabled."
93+
else:
94+
data = err.read()
95+
96+
97+
try:
98+
data = json.loads(data)
99+
except:
100+
pass
101+
102+
return data

0 commit comments

Comments
 (0)