1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 from cm_api.endpoints.types import *
18
19 __docformat__ = "epytext"
20
21 PARCELS_PATH = "/clusters/%s/parcels"
22 PARCEL_PATH = "/clusters/%s/parcels/products/%s/versions/%s"
23
24 -def get_parcel(resource_root, product, version, cluster_name="default"):
25 """
26 Lookup a service by name
27 @param resource_root: The root Resource object.
28 @param name: Service name
29 @param cluster_name: Cluster name
30 @return: An ApiService object
31 """
32 return _get_parcel(resource_root, PARCEL_PATH % (cluster_name, product, version))
33
37
39 """
40 Get all parcels
41 @param resource_root: The root Resource object.
42 @param cluster_name: Cluster name
43 @return: A list of ApiParcel objects.
44 """
45 dic = resource_root.get(PARCELS_PATH % (cluster_name,),
46 params=view and dict(view=view) or None)
47 return ApiList.from_json_dict(ApiParcel, dic, resource_root)
48
50 """
51 An object that represents the state of a parcel.
52 """
53 _ATTRIBUTES = {
54 'progress' : ROAttr(),
55 'totalProgress' : ROAttr(),
56 'count' : ROAttr(),
57 'totalCount' : ROAttr(),
58 'warnings' : ROAttr(),
59 'errors' : ROAttr(),
60 }
61
64
66 return "<ApiParcelState>: (progress: %s) (totalProgress: %s) (count: %s) (totalCount: %s)" % (
67 self.progress, self.totalProgress, self.count, self.totalCount)
68
70 """
71 An object that represents a parcel and allows administrative operations.
72 """
73 _ATTRIBUTES = {
74 'product' : ROAttr(),
75 'version' : ROAttr(),
76 'stage' : ROAttr(),
77 'state' : ROAttr(ApiParcelState),
78 'clusterRef' : ROAttr(ApiClusterRef),
79 }
80
83
85 return "<ApiParcel>: %s-%s (stage: %s) (state: %s) (cluster: %s)" % (
86 self.product, self.version, self.stage, self.state, self._get_cluster_name())
87
93
95 if self.clusterRef:
96 return self.clusterRef.clusterName
97 return None
98
99 - def _cmd(self, cmd, data=None, params=None):
106
108 """
109 Start the download of the parcel
110
111 @return: Reference to the completed command.
112 """
113 return self._cmd('startDownload')
114
116 """
117 Cancels the parcel download. If the parcel is not
118 currently downloading an exception is raised.
119
120 @return: Reference to the completed command.
121 """
122 return self._cmd('cancelDownload')
123
125 """
126 Removes the downloaded parcel
127
128 @return: Reference to the completed command.
129 """
130 return self._cmd('removeDownload')
131
133 """
134 Start the distribution of the parcel to all hosts
135 in the cluster.
136
137 @return: Reference to the completed command.
138 """
139 return self._cmd('startDistribution')
140
142 """
143 Cancels the parcel distrubution. If the parcel is not
144 currently distributing an exception is raised.
145
146 @return: Reference to the completed command
147 """
148 return self._cmd('cancelDistribution')
149
151 """
152 Start the removal of the distribution of the parcel
153 from all the hosts in the cluster.
154
155 @return: Reference to the completed command.
156 """
157 return self._cmd('startRemovalOfDistribution')
158
160 """
161 Activate the parcel on all the hosts in the cluster.
162
163 @return: Reference to the completed command.
164 """
165 return self._cmd('activate')
166
168 """
169 Deactivates the parcel on all the hosts in the cluster.
170
171 @return: Reference to the completed command.
172 """
173 return self._cmd('deactivate')
174