Exemplo n.º 1
0
 def create(self, context, deployable_id, cpid_id):
     """Create a driver-side AttachHandle object, call AttachHandle
     Object to store in DB."""
     attach_handle_obj = AttachHandle(context=context,
                                      deployable_id=deployable_id,
                                      cpid_id=cpid_id,
                                      attach_type=self.attach_type,
                                      attach_info=self.attach_info,
                                      in_use=self.in_use)
     attach_handle_obj.create(context)
Exemplo n.º 2
0
 def drv_ah_make_diff(cls, context, dep_id, cpid_id, old_driver_ah_list,
                      new_driver_ah_list):
     """Diff new dirver-side AttachHandle Object lists with the old one."""
     LOG.info("Start differing attach_handles.")
     new_info_list = [driver_ah_obj.attach_info for driver_ah_obj in
                      new_driver_ah_list]
     old_info_list = [driver_ah_obj.attach_info for driver_ah_obj in
                      old_driver_ah_list]
     same = set(new_info_list) & set(old_info_list)
     LOG.info('new info list %s', new_info_list)
     LOG.info('old info list %s', old_info_list)
     # attach-info is same
     for s in same:
         # get attach_handle obj
         new_driver_ah_obj = new_driver_ah_list[new_info_list.index(s)]
         old_driver_ah_obj = old_driver_ah_list[old_info_list.index(s)]
         changed_key = ['attach_type']
         ah_obj = AttachHandle.get_ah_by_depid_attachinfo(context,
                                                          dep_id, s)
         for c_k in changed_key:
             if getattr(new_driver_ah_obj, c_k) != getattr(
                     old_driver_ah_obj, c_k):
                 setattr(ah_obj, c_k, getattr(new_driver_ah_obj, c_k))
         ah_obj.save(context)
     # attach_info is deleted.
     deleted = set(old_info_list) - same
     for d in deleted:
         old_driver_ah_obj = old_driver_ah_list[old_info_list.index(d)]
         old_driver_ah_obj.destroy(context, dep_id)
     # attach_info is added.
     added = set(new_info_list) - same
     for a in added:
         new_driver_ah_obj = new_driver_ah_list[new_info_list.index(a)]
         new_driver_ah_obj.create(context, dep_id, cpid_id)
Exemplo n.º 3
0
 def list(cls, context, deployable_id):
     """Form a driver-side attach_handle list for one deployable."""
     ah_obj_list = AttachHandle.get_ah_list_by_deployable_id(
         context, deployable_id)
     driver_ah_obj_list = []
     for ah_obj in ah_obj_list:
         driver_ah_obj = cls(context=context,
                             attach_type=ah_obj.attach_type,
                             attach_info=ah_obj.attach_info,
                             in_use=ah_obj.in_use)
         driver_ah_obj_list.append(driver_ah_obj)
     return driver_ah_obj_list
Exemplo n.º 4
0
    def unbind(self, context):
        arq = self.arq
        arq.hostname = None
        arq.device_rp_uuid = None
        arq.instance_uuid = None
        arq.state = constants.ARQ_UNBOUND

        # Unbind: mark attach handles as freed
        ah_id = self.attach_handle_id
        if ah_id:
            attach_handle = AttachHandle.get_by_id(context, ah_id)
            attach_handle.deallocate(context)
        self.attach_handle_id = None
        self.save(context)
Exemplo n.º 5
0
 def _allocate_attach_handle(self, context, deployable):
     try:
         ah = AttachHandle.allocate(context, deployable.id)
         self.attach_handle_id = ah.id
     except Exception as e:
         LOG.error(
             "Failed to allocate attach handle for ARQ %s"
             "from deployable %s. Reason: %s", self.arq.uuid,
             deployable.uuid, str(e))
         # TODO(Shaohe) Rollback? We have _update_placement,
         # should cancel it.
         self.update_check_state(context, constants.ARQ_BIND_FAILED)
         raise
     LOG.info('Attach handle(%s) for ARQ(%s) successfully.', ah.uuid,
              self.arq.uuid)
Exemplo n.º 6
0
 def destroy(self, context, deployable_id):
     ah_obj = AttachHandle.get_ah_by_depid_attachinfo(
         context, deployable_id, self.attach_info)
     if ah_obj is not None:
         ah_obj.destroy(context)