Exemplo n.º 1
0
    def create(cls, context, tenant_id, instance_id, group_id, instance_type):
        try:
            is_found = False
            db_info = DBInstanceGroupItem.find_all(group_id=group_id, deleted=False)
            for inst in db_info:
                if inst.type in (DBInstanceType.MASTER, DBInstanceType.SINGLE) and instance_type in (
                    DBInstanceType.MASTER,
                    DBInstanceType.SINGLE,
                ):
                    raise MultiMasterInGroup(**locals())

            try:
                cls.get_by_instance_id(context, instance_id)
            except exception.NotFound:
                is_found = True

            if is_found:
                db_info = DBInstanceGroupItem.create(
                    tenant_id=tenant_id, instance_id=instance_id, group_id=group_id, type=instance_type, deleted=False
                )
            else:
                raise InstanceIdRepeat(**locals())
        except exception.InvalidModelError as ex:
            LOG.exception("Unable to create InstanceGroup record:")
            raise CreateGroupItemFail(**locals())
        return db_info
Exemplo n.º 2
0
 def get_by_gid_type(cls, context, group_id, type, deleted=False):
     if type in [DBInstanceType.MASTER, DBInstanceType.SINGLE, DBInstanceType.STANDBY]:
         db_info = DBInstanceGroupItem.find_by(context=context, group_id=group_id, deleted=deleted, type=type)
         return db_info
     elif type in [DBInstanceType.READ_REPLI, DBInstanceType.PENDING]:
         db_info = DBInstanceGroupItem.find_all(group_id=group_id, deleted=deleted, type=type)
         ret_list = []
         for _item in db_info:
             ret_list.append(_item)
         return ret_list
     else:
         raise TypeError()
Exemplo n.º 3
0
 def list_by_group_id(context, group_id):
     LOG.debug("list_by_group_id group_id '%s'" % group_id)
     groups = DBInstanceGroupItem.find_all(tenant_id=context.tenant, group_id=group_id, deleted=False)
     if not any(groups):
         raise exception.ModelNotFoundError("group Not Found, group_id: %s " % group_id)
     groups = filter(lambda g: g.type in [DBInstanceType.MASTER, DBInstanceType.READ_REPLI, DBInstanceType.SINGLE],
                     groups)
     members = []
     for g in groups:
         try:
             member = DBInstanceVip.find_by(context, instance_id=g.instance_id, deleted=False)
             if member and member.vip_id:
                 members.append(member)
         except Exception as ex:
             LOG.error(ex)
     vip_ids = set(map(lambda m: m.vip_id, members))
     vips = []
     for _id in vip_ids:
         try:
             vip = DBVips.find_by(context, id=_id, deleted=False)
             if vip:
                 vips.append(vip)
         except Exception as ex:
             LOG.error(ex)
     return vips
Exemplo n.º 4
0
 def update_type(cls, context, item_id, type, deleted=False):
     if type not in [
         DBInstanceType.MASTER,
         DBInstanceType.READ_REPLI,
         DBInstanceType.SINGLE,
         DBInstanceType.STANDBY,
         DBInstanceType.PENDING,
     ]:
         raise TypeError()
     try:
         item = DBInstanceGroupItem.find_by(context, id=item_id, deleted=deleted)
         item.type = type
         item.save()
     except exception.NotFound:
         raise exception.NotFound(uuid=item_id)
     return item
Exemplo n.º 5
0
 def list_by_gid(cls, context, group_id, deleted=False):
     db_info = DBInstanceGroupItem.find_all(group_id=group_id, deleted=deleted)
     ret = []
     for _item in db_info:
         ret.append(_item)
     return ret
Exemplo n.º 6
0
 def list(cls, context, deleted=False):
     db_info = DBInstanceGroupItem.find_all(deleted=False)
     ret = []
     for _item in db_info:
         ret.append(_item)
     return ret
Exemplo n.º 7
0
 def list_by_tenant_id(cls, context, deleted=False):
     db_info = DBInstanceGroupItem.find_all(tenant_id=context.tenant, deleted=deleted)
     ret = []
     for _item in db_info:
         ret.append(_item)
     return ret
Exemplo n.º 8
0
 def get_by_instance_id(cls, context, instance_id, deleted=False):
     try:
         db_info = DBInstanceGroupItem.find_by(instance_id=instance_id, deleted=deleted)
         return db_info
     except exception.NotFound:
         raise exception.NotFound(uuid=instance_id)