def save(self, update_fields=None, force_update=False, *args, **kwargs): """ This method implements three purposes. 1. Implements the functionality originally done by django (e.g. setting id on self) 2. Modify the Ceph state-machine in a sane way. 3. Providing a RESTful API. """ insert = self._state.adding # there seems to be no id field. if insert and not force_update: raise ValidationError('Cannot create Ceph cluster.') diff, original = self.get_modified_fields(update_fields=update_fields) for key, value in diff.items(): if key == 'keyring_file_path': ClusterConf(self.config_file_path).keyring_file_path = value elif key == 'keyring_user': ClusterConf(self.config_file_path).keyring.set_user_name( self.fsid, value) elif key == 'osd_flags': api = self.mon_api(self.fsid) for flag in set(original.osd_flags) - set(value): api.osd_unset(flag) for flag in set(value) - set(original.osd_flags): api.osd_set(flag) else: logger.warning( 'Tried to set "{}" to "{}" on rbd "{}", which is not ' 'supported'.format(key, value, self.config_file_path)) super(CephCluster, self).save(*args, **kwargs)
def check_ceph_api(fsid): try: cluster = ClusterConf.from_fsid(fsid) except LookupError: raise UnavailableModule(Reason.OPENATTIC_CEPH_NO_CLUSTER_FOUND, {'fsid': fsid}) def test_connection(client): if not client.connected(): raise UnavailableModule(Reason.OPENATTIC_CEPH_NO_CONNECTION, { 'fsid': fsid, 'cluster_name': cluster.name }) try: call_librados(fsid, test_connection, 'cluster connection test') except ExternalCommandError as e: raise UnavailableModule(Reason.OPENATTIC_CEPH_NO_CLUSTER_FOUND, { 'fsid': fsid, 'message': str(e), 'cluster_name': cluster.name, })
def status(params): configs = ClusterConf.all_configs() for conf in configs: check_keyring_permission(conf.keyring) check_ceph_api(conf.fsid)
def keyring_candidates(self): return [{ "file-path": keyring.file_name, "user-names": keyring.available_user_names } for keyring in ClusterConf(self.config_file_path).keyring_candidates]
def get_all_objects(context, query): return map(CephCluster.from_cluster_conf, ClusterConf.all_configs())