forked from Katello/katello
/
template.py
103 lines (79 loc) · 3.23 KB
/
template.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# -*- coding: utf-8 -*-
#
# Copyright © 2011 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public License,
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
# along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
#
# Red Hat trademarks are not licensed under GPLv2. No permission is
# granted to use or replicate Red Hat trademarks that are incorporated
# in this software or its documentation.
from katello.client.api.base import KatelloAPI
class TemplateAPI(KatelloAPI):
def templates(self, envId):
path = "/api/environments/%s/templates/" % str(envId)
tpls = self.server.GET(path)[1]
return tpls
def template(self, tplId):
path = "/api/templates/%s" % str(tplId)
tpl = self.server.GET(path)[1]
return tpl
def template_by_name(self, envId, tplName):
path = "/api/environments/%s/templates/" % str(envId)
tpls = self.server.GET(path, {"name": tplName})[1]
if len(tpls) > 0:
#show provides more information than index
return self.template(tpls[0]["id"])
else:
return None
def import_tpl(self, envId, description, tplFile):
tplData = {
"template_file": tplFile,
"template": {
"description": description
},
"environment_id": envId
}
path = "/api/templates/import"
return self.server.POST(path, tplData, multipart=True)[1]
def create(self, envId, name, description, parentId):
tplData = {
"name": name,
"description": description
}
tplData = self.update_dict(tplData, "parent_id", parentId)
tplData = {
"template": tplData,
"environment_id": envId
}
path = "/api/templates/"
return self.server.POST(path, tplData)[1]
def update(self, tplId, newName, description, parentId):
tplData = {}
tplData = self.update_dict(tplData, "name", newName)
tplData = self.update_dict(tplData, "description", description)
tplData = self.update_dict(tplData, "parent_id", parentId)
tplData = {
"template": tplData
}
path = "/api/templates/%s" % str(tplId)
return self.server.PUT(path, tplData)[1]
def add_content(self, tplId, contentType, attrs):
path = "/api/templates/%s/%s/" % (str(tplId), contentType)
return self.server.POST(path, attrs)[1]
def remove_content(self, tplId, contentType, contentId):
path = "/api/templates/%s/%s/%s/" % (str(tplId), contentType, str(contentId))
return self.server.DELETE(path)[1]
def promote(self, template_id):
path = "/api/templates/%s/promote" % str(template_id)
return self.server.POST(path)[1]
def promotion_status(self, task_id):
path = "/api/tasks/%s" % str(task_id)
return self.server.GET(path)[1]
def delete(self, template_id):
path = "/api/templates/%s" % str(template_id)
return self.server.DELETE(path)[1]