Example #1
0
    def _action_ha_to_sg(self, instance, body):
        LOG.debug("_action_ha_to_sg start instance: %s", instance.id)
        ha_to_sg_body = body.get('ha_to_sg', None)
        if ha_to_sg_body is None:
            msg = (_("request body not contains 'ha_to_sg' attribute. '%s'" % body))
            LOG.error(msg)
            raise exception.BadRequest(msg)

        master_id = instance.id
        fake_delete_standby = ha_to_sg_body.get('fake_delete_standby')
        if fake_delete_standby is not None:
            fake_delete_standby = str(fake_delete_standby).lower().strip()
            if fake_delete_standby == 'false':
                fake_delete_standby = False
            else:
                fake_delete_standby = True
        else:
            fake_delete_standby = True

        LOG.debug("_action_ha_to_sg fake_delete_standby: %s", fake_delete_standby)

        master = FreshInstance.load(instance.context, master_id)
        seccess, msg = KSC_FreshInstanceTasks_Ext.check_ha_to_sg(instance.context, master)
        if not seccess:
            LOG.error(msg)
            raise exception.BadRequest(msg)

        instance.ha_to_sg(instance.context, master_id, fake_delete_standby=fake_delete_standby)
        LOG.debug("_action_ha_to_sg finished instance: %s", instance.id)
        return wsgi.Result(None, 202)
Example #2
0
 def type_in_members(self, members, instance_type):
     if instance_type is None:
         return True
     for m in members:
         try:
             instance = FreshInstance.load(self.context, id=m.instance_id)
         except Exception as ex:
             LOG.error(ex)
         if instance:
             if instance_type == instance.type:
                 return True
     return False
Example #3
0
 def data(self):
     """
     :return:
     {
         "vip": {
             "id": "xxx",
             "vip": "10.147.0.150",
             "vport": "3306",
             "members": [{
                 "id": "xxx",
                 "rip": "10.142.1.129",
                 "rport": "3306",
                 "mid": "xxx",
                 "instance_id": "xxx",
                 "type": "MASTER"
             }]
         }
     }
     """
     view_members = []
     for m in self.members:
         try:
             instance = FreshInstance.load(self.context, id=m.instance_id)
         except Exception as ex:
             LOG.error(ex)
         if instance:
             if self.instance_type is None or self.instance_type == instance.type:
                 view_members.append({"id": m.id,
                                      "rip": m.rip,
                                      "rport": m.rport,
                                      "mid": m.mid,
                                      "instance_id": m.virtual_instance_id,
                                      "type": instance.type})
     return {"vip": {
         "id": self.vip.id,
         "vip": self.vip.vip,
         "vport": self.vip.vport,
         "members": view_members
     }
     }