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 parcel by name 
 27    @param resource_root: The root Resource object. 
 28    @param product: Parcel product name 
 29    @param version: Parcel version 
 30    @param cluster_name: Cluster name 
 31    @return: An ApiService object 
 32    """ 
 33    return _get_parcel(resource_root, PARCEL_PATH % (cluster_name, product, version)) 
  34   
 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    @since: API v3 
 45    """ 
 46    return call(resource_root.get, PARCELS_PATH % (cluster_name,), 
 47        ApiParcel, True, params=view and dict(view=view) or None, api_version=3) 
  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    @since: API v3 
 74    """ 
 75    _ATTRIBUTES = { 
 76      'product'     : ROAttr(), 
 77      'version'     : ROAttr(), 
 78      'stage'       : ROAttr(), 
 79      'state'       : ROAttr(ApiParcelState), 
 80      'clusterRef'  : ROAttr(ApiClusterRef), 
 81    } 
 82   
 85   
 87      return "<ApiParcel>: %s-%s (stage: %s) (state: %s) (cluster: %s)" % ( 
 88          self.product, self.version, self.stage, self.state, self._get_cluster_name()) 
  89   
 92   
 98   
100      if self.clusterRef: 
101        return self.clusterRef.clusterName 
102      return None 
 103   
105      """ 
106      Start the download of the parcel 
107   
108      @return: Reference to the completed command. 
109      """ 
110      return self._cmd('startDownload') 
 111   
113      """ 
114      Cancels the parcel download. If the parcel is not 
115      currently downloading an exception is raised. 
116   
117      @return: Reference to the completed command. 
118      """ 
119      return self._cmd('cancelDownload') 
 120   
122      """ 
123      Removes the downloaded parcel 
124   
125      @return: Reference to the completed command. 
126      """ 
127      return self._cmd('removeDownload') 
 128   
130      """ 
131      Start the distribution of the parcel to all hosts 
132      in the cluster. 
133   
134      @return: Reference to the completed command. 
135      """ 
136      return self._cmd('startDistribution') 
 137   
139      """ 
140      Cancels the parcel distrubution. If the parcel is not 
141      currently distributing an exception is raised. 
142   
143      @return: Reference to the completed command 
144      """ 
145      return self._cmd('cancelDistribution') 
 146   
148      """ 
149      Start the removal of the distribution of the parcel 
150      from all the hosts in the cluster. 
151   
152      @return: Reference to the completed command. 
153      """ 
154      return self._cmd('startRemovalOfDistribution') 
 155   
157      """ 
158      Activate the parcel on all the hosts in the cluster. 
159   
160      @return: Reference to the completed command. 
161      """ 
162      return self._cmd('activate') 
 163   
165      """ 
166      Deactivates the parcel on all the hosts in the cluster. 
167   
168      @return: Reference to the completed command. 
169      """ 
170      return self._cmd('deactivate') 
  171