def register(cls, context, hostname, drivers, conductor_group, update_existing=False): """Register an active conductor with the cluster. :param cls: the :class:`Conductor` :param context: Security context :param hostname: the hostname on which the conductor will run :param drivers: the list of drivers enabled in the conductor :param conductor_group: conductor group to join, used for node:conductor affinity. :param update_existing: When false, registration will raise an exception when a conflicting online record is found. When true, will overwrite the existing record. Default: False. :raises: ConductorAlreadyRegistered :returns: a :class:`Conductor` object. """ utils.validate_conductor_group(conductor_group) db_cond = cls.dbapi.register_conductor( { 'hostname': hostname, 'drivers': drivers, 'conductor_group': conductor_group.lower(), 'version': cls.get_target_version() }, update_existing=update_existing) return cls._from_db_object(context, cls(), db_cond)
def _validate_and_format_conductor_group(self, fields): """Validate conductor_group and format it for our use. Currently formatting is just lowercasing it. :param fields: a dict of Node fields for create or update. :raises: InvalidConductorGroup if validation fails. """ if 'conductor_group' in fields: utils.validate_conductor_group(fields['conductor_group']) fields['conductor_group'] = fields['conductor_group'].lower()
def _validate_and_format_conductor_group(self, fields): """Validate conductor_group and format it for our use. Currently formatting is just lowercasing it. :param fields: a dict of Node fields for create or update. :raises: InvalidConductorGroup if validation fails. """ if 'conductor_group' in fields: utils.validate_conductor_group(fields['conductor_group']) fields['conductor_group'] = fields['conductor_group'].lower()
def test_validate_conductor_group_success(self): self.assertIsNone(utils.validate_conductor_group('foo')) self.assertIsNone(utils.validate_conductor_group('group1')) self.assertIsNone(utils.validate_conductor_group('group1.with.dot')) self.assertIsNone(utils.validate_conductor_group('group1_with_under')) self.assertIsNone(utils.validate_conductor_group('group1-with-dash'))
def test_validate_conductor_group_success(self): self.assertIsNone(utils.validate_conductor_group('foo')) self.assertIsNone(utils.validate_conductor_group('group1')) self.assertIsNone(utils.validate_conductor_group('group1.with.dot')) self.assertIsNone(utils.validate_conductor_group('group1_with_under')) self.assertIsNone(utils.validate_conductor_group('group1-with-dash'))