1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 import copy
18 from cm_api.endpoints.types import *
19
20 __docformat__ = "epytext"
21
22 HOST_TEMPLATES_PATH = "/clusters/%s/hostTemplates"
23 HOST_TEMPLATE_PATH = "/clusters/%s/hostTemplates/%s"
24 APPLY_HOST_TEMPLATE_PATH = HOST_TEMPLATE_PATH + "/commands/applyHostTemplate"
25
27 """
28 Create a host template.
29 @param resource_root: The root Resource object.
30 @param name: Host template name
31 @param cluster_name: Cluster name
32 @return: An ApiHostTemplate object for the created host template.
33 @since: API v3
34 """
35 apitemplate = ApiHostTemplate(resource_root, name, [])
36 return call(resource_root.post,
37 HOST_TEMPLATES_PATH % (cluster_name,),
38 ApiHostTemplate, True, data=[apitemplate], api_version=3)[0]
39
41 """
42 Lookup a host template by name in the specified cluster.
43 @param resource_root: The root Resource object.
44 @param name: Host template name.
45 @param cluster_name: Cluster name.
46 @return: An ApiHostTemplate object.
47 @since: API v3
48 """
49 return call(resource_root.get,
50 HOST_TEMPLATE_PATH % (cluster_name, name),
51 ApiHostTemplate, api_version=3)
52
54 """
55 Get all host templates in a cluster.
56 @param cluster_name: Cluster name.
57 @return: ApiList of ApiHostTemplate objects for all host templates in a cluster.
58 @since: API v3
59 """
60 return call(resource_root.get,
61 HOST_TEMPLATES_PATH % (cluster_name,),
62 ApiHostTemplate, True, api_version=3)
63
65 """
66 Delete a host template identified by name in the specified cluster.
67 @param resource_root: The root Resource object.
68 @param name: Host template name.
69 @param cluster_name: Cluster name.
70 @return: The deleted ApiHostTemplate object.
71 @since: API v3
72 """
73 return call(resource_root.delete,
74 HOST_TEMPLATE_PATH % (cluster_name, name),
75 ApiHostTemplate, api_version=3)
76
78 """
79 Update a host template identified by name in the specified cluster.
80 @param resource_root: The root Resource object.
81 @param name: Host template name.
82 @param cluster_name: Cluster name.
83 @param api_host_template: The updated host template.
84 @return: The updated ApiHostTemplate.
85 @since: API v3
86 """
87 return call(resource_root.put,
88 HOST_TEMPLATE_PATH % (cluster_name, name),
89 ApiHostTemplate, data=api_host_template, api_version=3)
90
92 """
93 Apply a host template identified by name on the specified hosts and
94 optionally start them.
95 @param resource_root: The root Resource object.
96 @param name: Host template name.
97 @param cluster_name: Cluster name.
98 @param host_ids: List of host ids.
99 @param start_roles: Whether to start the created roles or not.
100 @return: An ApiCommand object.
101 @since: API v3
102 """
103 host_refs = []
104 for host_id in host_ids:
105 host_refs.append(ApiHostRef(resource_root, host_id))
106
107 params = {"startRoles" : start_roles}
108 return call(resource_root.post,
109 APPLY_HOST_TEMPLATE_PATH % (cluster_name, name),
110 ApiCommand, data=host_refs, params=params, api_version=3)
111
112
114 _ATTRIBUTES = {
115 'name' : None,
116 'roleConfigGroupRefs' : Attr(ApiRoleConfigGroupRef),
117 'clusterRef' : ROAttr(ApiClusterRef),
118 }
119
120 - def __init__(self, resource_root, name=None, roleConfigGroupRefs=None):
122
124 return "<ApiHostTemplate>: %s (cluster %s)" % (self.name, self.clusterRef.clusterName)
125
128
131
135
137 """
138 Rename a host template.
139 @param new_name: New host template name.
140 @return: An ApiHostTemplate object.
141 """
142 update = copy.copy(self)
143 update.name = new_name
144 return self._do_update(update)
145
147 """
148 Updates the role config groups in a host template.
149 @param role_config_group_refs: List of role config group refs.
150 @return: An ApiHostTemplate object.
151 """
152 update = copy.copy(self)
153 update.roleConfigGroupRefs = role_config_group_refs
154 return self._do_update(update)
155
157 """
158 Apply a host template identified by name on the specified hosts and
159 optionally start them.
160 @param host_ids: List of host ids.
161 @param start_roles: Whether to start the created roles or not.
162 @return: An ApiCommand object.
163 """
164 return apply_host_template(self._get_resource_root(), self.name, self.clusterRef.clusterName, host_ids, start_roles)
165