コード例 #1
0
ファイル: impl_zookeeper.py プロジェクト: ziziwu/openstack
    def _update_atom_details(self, ad, txn, create_missing=False):
        # Determine whether the desired data exists or not.
        ad_path = paths.join(self.atom_path, ad.uuid)
        e_ad = None
        try:
            ad_data, _zstat = self._client.get(ad_path)
        except k_exc.NoNodeError:
            # Not-existent: create or raise exception.
            raise exc.NotFound("No atom details found with id: %s" % ad.uuid)
        else:
            # Existent: read it out.
            try:
                ad_data = misc.decode_json(ad_data)
                ad_cls = logbook.atom_detail_class(ad_data['type'])
                e_ad = ad_cls.from_dict(ad_data['atom'])
            except KeyError:
                pass

        # Update and write it back
        if e_ad:
            e_ad = e_ad.merge(ad)
        else:
            e_ad = ad
        ad_data = base._format_atom(e_ad)
        txn.set_data(ad_path,
                     misc.binary_encode(jsonutils.dumps(ad_data)))
        return e_ad
コード例 #2
0
 def _save_atom_details(self, atom_detail, ignore_missing):
     # See if we have an existing atom detail to merge with.
     e_ad = None
     try:
         e_ad = self._get_atom_details(atom_detail.uuid, lock=False)
     except EnvironmentError:
         if not ignore_missing:
             raise exc.NotFound("No atom details found with id: %s" % atom_detail.uuid)
     if e_ad is not None:
         atom_detail = e_ad.merge(atom_detail)
     ad_path = os.path.join(self._atom_path, atom_detail.uuid)
     ad_data = base._format_atom(atom_detail)
     self._write_to(ad_path, jsonutils.dumps(ad_data))
     return atom_detail
コード例 #3
0
ファイル: impl_dir.py プロジェクト: ygkim93/OpenStackInAction
 def _save_atom_details(self, atom_detail, ignore_missing):
     # See if we have an existing atom detail to merge with.
     e_ad = None
     try:
         e_ad = self._get_atom_details(atom_detail.uuid, lock=False)
     except EnvironmentError:
         if not ignore_missing:
             raise exc.NotFound("No atom details found with id: %s" %
                                atom_detail.uuid)
     if e_ad is not None:
         atom_detail = e_ad.merge(atom_detail)
     ad_path = os.path.join(self._atom_path, atom_detail.uuid)
     ad_data = base._format_atom(atom_detail)
     self._write_to(ad_path, jsonutils.dumps(ad_data))
     return atom_detail
コード例 #4
0
ファイル: impl_zookeeper.py プロジェクト: ziziwu/openstack
 def _create_logbook(lb_path, txn):
     lb_data = lb.to_dict(marshal_time=True)
     txn.create(lb_path, misc.binary_encode(jsonutils.dumps(lb_data)))
     for fd in lb:
         # NOTE(harlowja): create an entry in the logbook path
         # for the provided flow detail so that a reference exists
         # from the logbook to its flow details.
         txn.create(paths.join(lb_path, fd.uuid))
         fd_path = paths.join(self.flow_path, fd.uuid)
         fd_data = jsonutils.dumps(fd.to_dict())
         txn.create(fd_path, misc.binary_encode(fd_data))
         for ad in fd:
             # NOTE(harlowja): create an entry in the flow detail path
             # for the provided atom detail so that a reference exists
             # from the flow detail to its atom details.
             txn.create(paths.join(fd_path, ad.uuid))
             ad_path = paths.join(self.atom_path, ad.uuid)
             ad_data = base._format_atom(ad)
             txn.create(ad_path,
                        misc.binary_encode(jsonutils.dumps(ad_data)))
     return lb