【问题标题】:Softlayer API getAccountBackupHistory with Python giving SoftLayer_Exception_Public使用 Python 提供 SoftLayer_Exception_Public 的 Softlayer API getAccountBackupHistory
【发布时间】:2016-01-19 22:19:53
【问题描述】:


首先,我想提一下我对云计算和 Python 非常陌生。 希望你们比softlayer服务台更有帮助。

目前我很难理解 Python API。 我有几台服务器正在运行,每台服务器都在运行 evault 代理。代理会定期创建我的服务器的备份。电子仓库代理现在已经运行了几个月,所以我有一些历史数据。

我想要的是创建一个 Python 脚本来(每天)检查备份是否成功。但不幸的是,我无法从“Account”服务访问“getAccountBackupHistory”方法。

“getAccountBackupHistory”需要 3 个参数,但我不知道在哪里添加这些。

我也搜索了那里的论坛,希望找到类似的东西,但我没有找到任何有用的东西。

  • Softlayer 论坛通用
  • Softlayer 论坛实现

到目前为止,这是我的脚本:

import SoftLayer
import datetime,time
from SoftLayer import utils
import pprint

usr_name="my_username"
api="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

client = SoftLayer.create_client_from_env(username=usr_name, api_key=api)

dt_now=datetime.datetime.now()
dt_end=str(dt_now.strftime('%Y-%m-%d'))
dt_start=str((dt_now-datetime.timedelta(days=2)).strftime('%Y-%m-%d'))

#First attempt
obj=client.call("Account","getAccountBackupHistory",dt_start,dt_end,"success")


#Second attempt
obj=client["Account"]
webcc=obj.getAccountBackupHistory(dt_start,dt_end,"success")

这给了我以下例外:

SoftLayer.exceptions.SoftLayerAPIError: SoftLayerAPIError(SoftLayer_Exception_Public): Error Occured. Unable to get account backup history.

P.S:我使用的帐户具有管理员权限
欢迎任何建议
干杯,
艾瑞加

【问题讨论】:

    标签: python api ibm-cloud-infrastructure


    【解决方案1】:

    显然,SoftLayer_Account::getAccountBackupHistory 存在问题。

    但是,如果您想检查备份是否从其代理成功创建,您可以尝试以下 Python 脚本:

    """
    This script retrieves an account's associated EVault storage volumes.
    Also it retrieves the "agentStatuses" and "backupJobDetails" information from them.
    
    Important manual pages:
    http://sldn.softlayer.com/reference/services/SoftLayer_Account/getEvaultNetworkStorage
    http://sldn.softlayer.com/article/object-masks
    
    License: http://sldn.softlayer.com/article/License
    Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
    """
    import SoftLayer
    import pprint
    
    # Your SoftLayer username and apiKey
    usr_name = "set me"
    api = "set me"
    
    # Declare the API client.
    client = SoftLayer.create_client_from_env(username=usr_name, api_key=api)
    
    # Declare an object mask, to get agentStatuses and backupJobDetails information
    object_mask = "mask(SoftLayer_Network_Storage_Backup_Evault_Version6)[agentStatuses, backupJobDetails]"
    
    try:
        obj = client["SoftLayer_Account"].getEvaultNetworkStorage(mask=object_mask)
        pprint.pprint(obj)
    except SoftLayer.SoftLayerAPIError as e:
        print("Error: faultCode=%s, faultString=%s" % (e.faultCode, e.faultString))
    

    【讨论】:

    • 感谢您的解决方法,但您是如何知道使用“SoftLayer_Network_Storage_Backup_Evault_Version6”的?因为当我查看“SoftLayer_Account”时,我在数据类型(关系或本地属性)下看不到这个
    • 如您所见,SoftLayer_Account::getEvaultNetworkStorage 方法检索 SoftLayer_Network_Storage 对象,这是“网络存储对象”的通用容器。因此,我们需要在对象掩码中指定我们希望检索的对象的类型,以便清楚地了解它,请查看Object Mask“类型”部分。另外,我们可以查看有关 Evaul 的文档:SoftLayer_Network_Storage_Backup_Evault_Version6
    • 我认为这可能会让人感到困惑,但我可以建议查看SLDN documentation。您还可以看到 SoftLayer API 正在处理的对象SLDN datatypes
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-31
    • 1970-01-01
    相关资源
    最近更新 更多