如何使用Softlayer API来授权iscsi存储

时间:2016-02-11 10:30:13

标签: python ibm-cloud-infrastructure network-storage

我尝试使用此命令

授权新系统上的softlayer耐久性存储
curl -v -i -X POST -d '{"parameters": [{"id": [IP ADDRESS ID]}]}' -u "[USERNAME]:[APIKEY]" https://api.softlayer.com/rest/v3/SoftLayer_Network_Storage/[STORAGE ID]/allowAccessFromIpAddress.jso

我按照链接中的说明操作,但它不起作用。 https://sldn.softlayer.com/it/blog/sjanowiak/how-use-softlayer-api-authorize-guest-vms-iscsi-storage

控制台返回此错误。 (显然我在参数中加入了正确的值)

{"error":"SoftLayer_Network_Storage::allowAccesstFromVirtualGuestList is not implemented.","code":"SoftLayer_Exception_NotImplemented"}

如何使用SoftLayer API授权VM使用iSCSI存储? 是否有python服务SoftLayer.ISCSIManager(client)的功能?

此致

1 个答案:

答案 0 :(得分:0)

以下是一些可能对您有所帮助的建议:

  • “网络存储”和VSI / Bar金属/子网必须位于同一位置/数据中心。

这些请求可以帮助我们获取可用于特定“网络存储”的项目,我们可以在门户中看到:

要获取具有关联IP地址的有效可用子网,请执行:

https://[username]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Network_Storage/[storage_id]/ getAllowableSubnets?objectMask=mask[id,networkIdentifier,cidr,subnetType,ipAddresses[id,ipAddress]]
Method: GET

要获得有效的虚拟访客,请执行:

https://[username]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Network_Storage_Iscsi/[storage_id]/ getAllowableVirtualGuests?objectMask=mask[id,fullyQualifiedDomainName] Method: GET

可用的金属条:

https://[username]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Network_Storage/[storage_id]/getAllowableHardware
Method: GET

<强>参考文献:

  

http://sldn.softlayer.com/reference/services/SoftLayer_Network_Storage_Iscsi/getAllowableVirtualGuests   http://sldn.softlayer.com/reference/services/SoftLayer_Network_Storage_Iscsi/getAllowableSubnets   http://sldn.softlayer.com/reference/services/SoftLayer_Network_Storage_Iscsi/getAllowableHardware

似乎不是使用ISCSI Manager授权网络存储的功能。但下面是一些使用python客户端的例子。

Python示例:

使用: SoftLayer_Network_Storage :: allowAccessFromIpAddress

# So we can talk to the SoftLayer API:
import SoftLayer

# For nice debug output:
from pprint import pprint as pp

# Your SoftLayer API username and key.
API_USERNAME = 'set me'
API_KEY = 'set me'
# Set the server id that you wish to allow.
ipAddressId = 20636706
iscsiId = 8393467

# Set up your API client
client = SoftLayer.Client(
    username=API_USERNAME,
    api_key=API_KEY
)

try:
    # The expected result after executing the script is: true
    # To get valid Ip address, execute:
    # https://[username]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Network_Storage/[Storage_id]/getAllowableSubnets?objectMask=mask[id,networkIdentifier,cidr,subnetType,ipAddresses[id,ipAddress]]
    result = client['SoftLayer_Network_Storage'].allowAccessFromIpAddress({"id":ipAddressId},id=iscsiId)
    pp(result)
except SoftLayer.SoftLayerAPIError as e:
        pp('Unable to allow the access to ISCSI faultCode=%s, faultString=%s'
            % (e.faultCode, e.faultString))

使用: SoftLayer_Network_Storage :: allowAccessFromVirtualGuest

# So we can talk to the SoftLayer API:
import SoftLayer

# For nice debug output:
from pprint import pprint as pp

# Your SoftLayer API username and key.
API_USERNAME = 'set me'
API_KEY = 'set me'
# Set the server id that you wish to allow.
vsiId = 14388437
iscsiId = 8393467

# Set up your API client
client = SoftLayer.Client(
    username=API_USERNAME,
    api_key=API_KEY
)

try:
    # The expected result after executing the script is: true
    # To get valid Virtual Guest ids, execute:
    # https://[username]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Network_Storage/[storage_id]/getAllowableVirtualGuests?objectMask=mask[id,fullyQualifiedDomainName]
    result = client['SoftLayer_Network_Storage'].allowAccessFromVirtualGuest({"id":vsiId},id=iscsiId)
    pp(result)
except SoftLayer.SoftLayerAPIError as e:
        pp('Unable to allow the access to ISCSI faultCode=%s, faultString=%s'
            % (e.faultCode, e.faultString))

使用: SoftLayer_Virtual_Guest :: allowAccessToNetworkStorage

# So we can talk to the SoftLayer API:
import SoftLayer

# For nice debug output:
from pprint import pprint as pp

# Your SoftLayer API username and key.
API_USERNAME = 'set me'
API_KEY = 'set me'
# Set the server id that you wish to allow.
serverId = 14388435
iscsiId = 8393467

# Set up your API client
client = SoftLayer.Client(
    username=API_USERNAME,
    api_key=API_KEY
)

try:
    # The expected result after executing the script is: true
    result = client['SoftLayer_Virtual_Guest'].allowAccessToNetworkStorage({"id":iscsiId},id=serverId)
    pp(result)
except SoftLayer.SoftLayerAPIError as e:
        pp('Unable to allow the access to ISCSI faultCode=%s, faultString=%s'
            % (e.faultCode, e.faultString))

<强>参考文献:

  

http://sldn.softlayer.com/reference/services/SoftLayer_Network_Storage/allowAccessFromVirtualGuest   http://sldn.softlayer.com/reference/services/SoftLayer_Network_Storage/allowAccessFromHardware   http://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest/allowAccessToNetworkStorage

     

https://github.com/softlayer/softlayer-python

     

https://sldn.softlayer.com/article/python

     

https://softlayer.github.io/python/

修改

我能够使用“耐力复制品”重现同样的问题。 这是一个授权虚拟Guest的python示例:

# So we can talk to the SoftLayer API:
import SoftLayer

# For nice debug output:
from pprint import pprint as pp

# Your SoftLayer API username and key.
API_USERNAME = 'set me'
API_KEY = 'set me'
# Set the server id that you wish to allow.
vsiId = 15571333
storageId = 6550721
objectType = "SoftLayer_Virtual_Guest"

# Set up your API client
client = SoftLayer.Client(
    username=API_USERNAME,
    api_key=API_KEY
)

try:
    # To get valid Virtual Guest ids, execute:
    # https://[username]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Network_Storage/[storage_id]/getAllowableVirtualGuests?objectMask=mask[id,fullyQualifiedDomainName]
    result = client['SoftLayer_Network_Storage'].allowAccessFromHostList([{"id":vsiId,"objectType": objectType}],id=storageId)
    pp(result)
except SoftLayer.SoftLayerAPIError as e:
        pp('Unable to allow the access to network Storage faultCode=%s, faultString=%s'
            % (e.faultCode, e.faultString))

如果您要授权“虚拟访客”,“IpAddress”或“硬件”,“ objectType ”的有效值为:
分别为“SoftLayer_Virtual_Guest”,“SoftLayer_Network_Subnet_IpAddress”,“SoftLayer_Hardware”

参考:

  

http://sldn.softlayer.com/reference/services/SoftLayer_Network_Storage/allowAccessFromHostList

问候。