Example #1
0
 def modifySecurityIps(self,DBInstanceId,SecurityIps,DBInstanceIPArrayName):
     '''Mysql数据库白名单修改'''
     request = ModifySecurityIpsRequest.ModifySecurityIpsRequest()
     request.set_DBInstanceId(DBInstanceId)
     request.set_SecurityIps(SecurityIps)
     request.set_DBInstanceIPArrayName(DBInstanceIPArrayName)
     return request
    def modifySecurityIpsRequest(self, DBInstanceId, SecurityIps,
                                 DBInstanceIPArrayName,
                                 DBInstanceIPArrayAttribute):
        """修改数据库实例白名单
        """
        request = ModifySecurityIpsRequest.ModifySecurityIpsRequest()
        request.set_DBInstanceId(DBInstanceId)
        request.set_SecurityIps(SecurityIps)
        request.set_DBInstanceIPArrayName(DBInstanceIPArrayName)
        request.set_DBInstanceIPArrayAttribute(DBInstanceIPArrayAttribute)
        request.set_WhitelistNetworkType('Classic')

        return request
 def modifySecurityIpsRequest(self,
                              DBInstanceId,
                              DBInstanceIPArrayName='ops',
                              SecurityIps=None,
                              ModifyMode='Append'):
     '''
     修改ip白名单
     '''
     request = ModifySecurityIpsRequest.ModifySecurityIpsRequest()
     request.set_DBInstanceId(DBInstanceId)
     request.set_DBInstanceIPArrayName(DBInstanceIPArrayName)
     request.set_SecurityIps(SecurityIps)
     request.set_ModifyMode(ModifyMode)
     request.set_accept_format('json')
     return request
 def modify_rds_whitelistip_info(
     self,
     ip,
     modify_mode,
     new_ip=None,
 ):
     """
     Modify WhitelistIP info into RDS Data Security. See also:
         https://www.alibabacloud.com/help/zh/doc-detail/26242.htm?spm=a2c63.p38356.879954.54.6eb34542JGBoSp
     :param ip: IP address to modify.
     :param new_ip: IP to add info.
     :param modify_mode: modify mode(valid values: Append, Delete, Cover).
     :return: Python built-in exit code.
     """
     assert modify_mode == "Append" or modify_mode == "Delete"
     client = self.get_cloud_client()
     for whitelistip_info in self.get_rds_whitelistip_info(ip):
         if modify_mode == "Append" and re.search(
                 self.get_ip_pattern(new_ip),
                 str(whitelistip_info["CheckInfo"])):
             print(self.get_ip_pattern(ip),
                   str(whitelistip_info["CheckInfo"]))
         del whitelistip_info["CheckInfo"]
         logger.warning(
             "modify_rds_whitelistip_info:\n\t{info}".format(info=str(
                 {
                     "db_instance_id": whitelistip_info["DBInstanceId"],
                     "ip_array_name":
                     whitelistip_info["DBInstanceIPArrayName"],
                     "modify_mode": modify_mode,
                     "modify_ip": ip,
                 })))
         request = ModifySecurityIpsRequest.ModifySecurityIpsRequest()
         request.set_accept_format('json')
         if modify_mode == "Append":
             request.set_SecurityIps(new_ip)
         else:
             request.set_SecurityIps(ip)
         request.set_ModifyMode(modify_mode)
         request.set_DBInstanceId(whitelistip_info["DBInstanceId"])
         request.set_DBInstanceIPArrayName(
             whitelistip_info["DBInstanceIPArrayName"])
         request.set_DBInstanceIPArrayAttribute(
             whitelistip_info["DBInstanceIPArrayAttribute"])
         request.set_SecurityIPType(whitelistip_info["SecurityIPType"])
         request.set_WhitelistNetworkType(
             whitelistip_info["WhitelistNetworkType"])
         client.do_action_with_exception(request)
Example #5
0
 def add_ip(self, name, ip, array='py_api'):
     """
     添加白名单
     :name: rds实例别名
     :param ip: 要添加的ip
     :param array: 分组
     :return:
     """
     request = ModifySecurityIpsRequest.ModifySecurityIpsRequest()
     db_list = self.get_db_instance(name)
     if not db_list:
         raise AttributeError('the db instance is not exist')
     print(db_list[0].id)
     request.set_DBInstanceId(db_list[0].id)
     request.set_DBInstanceIPArrayName(array)
     request.set_SecurityIps(ip)
     response = self.clt.do_action_with_exception(request)
     return response