Encryption 如何在SoftLayer中使用API获取iSCSI sotrage的加密状态(是/否)
def get_iscsi(自身,卷id,**kwargs) 我已使用此方法获取特定存储组件的详细信息,但无法借助API服务获取加密状态Encryption 如何在SoftLayer中使用API获取iSCSI sotrage的加密状态(是/否),encryption,ibm-cloud-infrastructure,Encryption,Ibm Cloud Infrastructure,def get_iscsi(自身,卷id,**kwargs) 我已使用此方法获取特定存储组件的详细信息,但无法借助API服务获取加密状态 哪个API可用于提取iSCSI存储的加密状态?hasEncryptionAtRest属性将提供此信息,您可以尝试以下rest请求: https://$user:$apiKey@api.softlayer.com/rest/v3/SoftLayer_Network_Storage/$storageId/getObject?objectMask=mask[hasE
哪个API可用于提取iSCSI存储的加密状态?hasEncryptionAtRest属性将提供此信息,您可以尝试以下rest请求:
https://$user:$apiKey@api.softlayer.com/rest/v3/SoftLayer_Network_Storage/$storageId/getObject?objectMask=mask[hasEncryptionAtRest]
Method: Get
用您自己的值替换:$user、$apiKey和$storageId
参考资料:
已更新 这里有一个Python脚本,它使用get\u iscsi方法
"""
This script retrieves storage with hasEncryptionAtRest
Important manual pages:
https://github.com/softlayer/softlayer-python/blob/master/SoftLayer/managers/iscsi.py
License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
import SoftLayer
import pprint
# Your SoftLayer API username and key.
USERNAME = 'set me'
API_KEY = 'set me'
# Define iscsi's identifier
volumeId = 16933699
# Declaring the API client
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
iscsiManager = SoftLayer.ISCSIManager(client)
try:
result = iscsiManager.get_iscsi(volumeId, mask='hasEncryptionAtRest')
pprint.pprint(result)
except SoftLayer.SoftLayerAPIError as e:
print(('Error faultCode=%s, faultString=%s'
% (e.faultCode, e.faultString)))
“”“
此脚本使用hasEncryptionAtRest检索存储
重要手册页:
https://github.com/softlayer/softlayer-python/blob/master/SoftLayer/managers/iscsi.py
许可证:http://sldn.softlayer.com/article/License
作者:SoftLayer Technologies,Inc。
"""
导入软层
导入pprint
#您的SoftLayer API用户名和密钥。
用户名='设置我'
API_KEY='设置我'
#定义iscsi的标识符
卷ID=16933699
#声明API客户端
client=SoftLayer.client(用户名=用户名,api\U密钥=api\U密钥)
iscsiManager=SoftLayer.iscsiManager(客户端)
尝试:
结果=iscsiManager.get_iscsi(volumeId,mask='hasnyptionatrest')
pprint.pprint(结果)
除SoftLayer.SoftLayer外,错误为e:
打印(('Error faultCode=%s,faultString=%s'
%(e.faultCode,e.faultString)))
更新2
获取帐户的公共ip地址 此脚本将有助于从您的帐户的公共ip地址检索信息 """ 此脚本检索帐户的公共ip地址
Important links:
http://sldn.softlayer.com/reference/services/SoftLayer_Account/getIpAddresses
License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
import SoftLayer
import pprint
# Your SoftLayer API username and key.
USERNAME = 'set me'
API_KEY = 'set me'
# Define an objectFilter to get public ips
objectFilter = {"ipAddresses": {"subnet": {"addressSpace": {"operation": "PUBLIC"}}}}
# Define an object mask to get id and ipaddress from ips
objectMask = 'id,ipAddress'
# Declaring the API client
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
try:
result = client['SoftLayer_Account'].getIpAddresses(mask=objectMask, filter=objectFilter)
pprint.pprint(result)
except SoftLayer.SoftLayerAPIError as e:
print(('Error faultCode=%s, faultString=%s'
% (e.faultCode, e.faultString)))
重要链接:
http://sldn.softlayer.com/reference/services/SoftLayer_Account/getIpAddresses
许可证:http://sldn.softlayer.com/article/License
作者:SoftLayer Technologies,Inc。
"""
导入软层
导入pprint
#您的SoftLayer API用户名和密钥。
用户名='设置我'
API_KEY='设置我'
#定义objectFilter以获取公共IP
objectFilter={“ipAddresses”:{“subnet”:{“addressSpace”:{“operation”:“PUBLIC”}}
#定义对象掩码以从IP获取id和IP地址
objectMask='id,ipAddress'
#声明API客户端
client=SoftLayer.client(用户名=用户名,api\U密钥=api\U密钥)
尝试:
结果=客户端['SoftLayer\u Account']。GetIPAddresss(掩码=对象掩码,筛选器=对象筛选器)
pprint.pprint(结果)
除SoftLayer.SoftLayer外,错误为e:
打印(('Error faultCode=%s,faultString=%s'
%(e.faultCode,e.faultString)))
更新3
获取帐户的公共ip地址并将其签入黑名单主机 不幸的是,没有任何SL API服务可以提供帮助,但请查看以下链接
"""
This script retrieves account's public ip addresses
Important links:
http://sldn.softlayer.com/reference/services/SoftLayer_Account/getIpAddresses
License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
import SoftLayer
import dns.resolver
bls = ["zen.spamhaus.org", "spam.abuse.ch", "cbl.abuseat.org", "virbl.dnsbl.bit.nl", "dnsbl.inps.de",
"ix.dnsbl.manitu.net", "dnsbl.sorbs.net", "bl.spamcannibal.org", "bl.spamcop.net",
"xbl.spamhaus.org", "pbl.spamhaus.org", "dnsbl-1.uceprotect.net", "dnsbl-2.uceprotect.net",
"dnsbl-3.uceprotect.net", "db.wpbl.info", "dyn.nszones.com", "bl.nszones.com"]
# Your SoftLayer API username and key.
USERNAME = 'set me'
API_KEY = 'set me'
# Define an objectFilter to get public ips
objectFilter = {"ipAddresses": {"subnet": {"addressSpace": {"operation": "PUBLIC"}}}}
# Define an object mask to get id and ipaddress from ips
objectMask = 'id,ipAddress'
# Declaring the API client
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
try:
ips = client['SoftLayer_Account'].getIpAddresses(mask=objectMask, filter=objectFilter)
for ip in ips:
print(ip['ipAddress'])
for bl in bls:
try:
my_resolver = dns.resolver.Resolver()
query = '.'.join(reversed(ip['ipAddress'].split("."))) + "." + bl
answers = my_resolver.query(query, "A")
answer_txt = my_resolver.query(query, "TXT")
print ' IP: %s IS listed in %s (%s: %s)' % (ip['ipAddress'], bl, answers[0], answer_txt[0])
except dns.resolver.NXDOMAIN:
print ' IP: %s is NOT listed in %s' % (ip['ipAddress'], bl)
except SoftLayer.SoftLayerAPIError as e:
print(('Error faultCode=%s, faultString=%s'
% (e.faultCode, e.faultString)))
“”“
此脚本检索帐户的公共ip地址
重要环节:
http://sldn.softlayer.com/reference/services/SoftLayer_Account/getIpAddresses
许可证:http://sldn.softlayer.com/article/License
作者:SoftLayer Technologies,Inc。
"""
导入软层
导入dns.resolver
bls=[“zen.spamhaus.org”、“spam.crack.ch”、“cbl.abuseat.org”、“virbl.dnsbl.bit.nl”、“dnsbl.inps.de”,
“ix.dnsbl.manitu.net”、“dnsbl.sorbs.net”、“bl.spamcannibal.org”、“bl.spamcop.net”,
“xbl.spamhaus.org”、“pbl.spamhaus.org”、“dnsbl-1.uceprotect.net”、“dnsbl-2.uceprotect.net”,
“dnsbl-3.net”、“db.wpbl.info”、“dyn.nszones.com”、“bl.nszones.com”]
#您的SoftLayer API用户名和密钥。
用户名='设置我'
API_KEY='设置我'
#定义objectFilter以获取公共IP
objectFilter={“ipAddresses”:{“subnet”:{“addressSpace”:{“operation”:“PUBLIC”}}
#定义对象掩码以从IP获取id和IP地址
objectMask='id,ipAddress'
#声明API客户端
client=SoftLayer.client(用户名=用户名,api\U密钥=api\U密钥)
尝试:
ips=client['SoftLayer\u Account'].GetIPAddresss(mask=objectMask,filter=objectFilter)
对于ip中的ip:
打印(ip['ipAddress'])
对于bls中的bl:
尝试:
my_resolver=dns.resolver.resolver()
查询='.'.join(反向(ip['ipAddress'].split(“.”))+“+bl
answers=my_resolver.query(查询,“A”)
answer_txt=my_resolver.query(查询,“txt”)
打印“IP:%s”列在%s(%s:%s)”中(IP['ipAddress'],bl,answers[0],answer\u txt[0])
除dns.resolver.NXDOMAIN外:
打印“IP:%s未列在%s%”(IP['ipAddress'],bl)中
除SoftLayer.SoftLayer外,错误为e:
打印(('Error faultCode=%s,faultString=%s'
%(e.faultCode,e.faultString)))
如您所见,IP将在“bls”主机中进行检查,您可以添加更多要检查的主机,在这里,您可以从一个在线网站检索要检查的黑名单主机:
检索标签
“”“
此脚本检索帐户的标记
重要环节:
http://sldn.softlayer.com/reference/services/SoftLayer_Account/getTags
许可证:http://sldn.softlayer.com/article/License
作者:SoftLayer Technologies,Inc。
"""
导入软层
导入pprint
#您的SoftLayer API用户名和密钥。
用户名='设置我'
API_KEY='设置我'
#声明API客户端
client=SoftLayer.client(用户名=用户名,api\U密钥=api\U密钥)
尝试:
结果=客户端['SoftLayer\u帐户'].getTags()
pprint.pprint(结果)
除SoftLayer.SoftLayer外,错误为e:
打印(('Error faultCode=%s,faultString=%s'
%(e.faultCode,e.faultString)))
通过标签获取设备
“”“
按标签搜索设备
重要手册页:
http://sldn.softlayer.com/reference/services/SoftLayer_Search/advancedSearch
许可证:http://sldn.softlayer.com/article/License
作者:SoftLayer Technologies,Inc。
"""
#搜索t的示例
"""
This script retrieves account's tags
Important links:
http://sldn.softlayer.com/reference/services/SoftLayer_Account/getTags
License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
import SoftLayer
import pprint
# Your SoftLayer API username and key.
USERNAME = 'set me'
API_KEY = 'set me'
# Declaring the API client
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
try:
result = client['SoftLayer_Account'].getTags()
pprint.pprint(result)
except SoftLayer.SoftLayerAPIError as e:
print(('Error faultCode=%s, faultString=%s'
% (e.faultCode, e.faultString)))
"""
Search devices by tag
Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Search/advancedSearch
License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
# Example to search tags for a VSI
import SoftLayer
import pprint
# Your SoftLayer API username.
USERNAME = 'set me'
API_KEY = 'set me'
# Tag to search
tag ="singapore1"
# Declare the API client
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY, endpoint_url='https://api.softlayer.com/xmlrpc/v3.1/')
searchService = client['SoftLayer_Search']
# Building the search string
searchString = "tagReferences.tag.name:%s _objectType:SoftLayer_Hardware,SoftLayer_Virtual_Guest,SoftLayer_Network_Vlan_Firewall,SoftLayer_Network_Application_Delivery_Controller _sort:[fullyQualifiedDomainName:asc]" % tag
try:
result = searchService.advancedSearch(searchString)
pprint.pprint(result)
except SoftLayer.SoftLayerAPIError as e:
print("Error faultCode=%s, faultString=%s" % (e.faultCode, e.faultString))
exit(1)
"""
This script retrieve devices which belongs from a list ip addresses.
Each device display information about its tags
Important links:
http://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest/findByIpAddress
http://sldn.softlayer.com/reference/services/SoftLayer_Hardware/findByIpAddress
License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
import SoftLayer
# Your SoftLayer API username and key.
USERNAME = 'set me'
API_KEY = 'set me'
# Define ip addresses to search in devices (HW/VSI)
ips = ['159.8.30.72', '159.122.15.65', '127.0.0.1']
# Object mask to get tag information
objectMask = 'mask[tagReferences[id,tag[id,name]]]'
# Declaring the API client
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
try:
for ip in ips:
print("Ip Address: %s" % ip)
result = client['SoftLayer_Virtual_Guest'].findByIpAddress(ip, mask=objectMask)
if not result:
result = client['SoftLayer_Hardware'].findByIpAddress(ip, mask=objectMask)
if not result:
print(" There not exists a server with this ip address")
else:
print(" Device Ip: %s, Hostname: %s Domain: %s" % (result['id'], result['hostname'], result['domain']))
for tag in result['tagReferences']:
if tag:
print(" TagReferencesId: %s TagId: %s TagName: %s" % (tag['id'], tag['tag']['id'], tag['tag']['name']))
except SoftLayer.SoftLayerAPIError as e:
print(('Error faultCode=%s, faultString=%s'
% (e.faultCode, e.faultString)))
"""
This script retrieve devices HW and VSI
Important links:
http://sldn.softlayer.com/reference/services/SoftLayer_Account/getVirtualGuests
http://sldn.softlayer.com/reference/services/SoftLayer_Account/getHardware
License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
import SoftLayer
from prettytable import PrettyTable
# Your SoftLayer API username and key.
USERNAME = 'set me'
API_KEY = 'set me'
# Declaring the API client
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
#Define an object mask to get public and private ip
mask = 'mask[primaryIpAddress, primaryBackendIpAddress]'
#table = BeautifulTable()
table = PrettyTable(["Id", "Hostname", "Domain", "Public IP", "Private IP", "Type"])
try:
vsis = client['SoftLayer_Account'].getVirtualGuests(mask=mask)
for vsi in vsis:
if 'primaryIpAddress' not in vsi:
vsi['primaryIpAddress'] = 'None'
table.add_row([vsi['id'], vsi['hostname'], vsi['domain'], vsi['primaryIpAddress'] , vsi['primaryBackendIpAddress'], "Virtual Guest"])
hws = client['SoftLayer_Account'].getHardware(mask=mask)
for hw in hws:
if 'primaryIpAddress' not in hw:
hw['primaryIpAddress'] = 'None'
table.add_row([hw['id'], hw['hostname'], hw['domain'], hw['primaryIpAddress'], hw['primaryBackendIpAddress'], "Hardware"])
print(table)
except SoftLayer.SoftLayerAPIError as e:
print(('Error faultCode=%s, faultString=%s'
% (e.faultCode, e.faultString)))
"""
This script retrieves account's brand and owned accounts (child accounts)
Important links:
http://sldn.softlayer.com/reference/services/SoftLayer_Account/getBrand
http://sldn.softlayer.com/reference/services/SoftLayer_Brand/getOwnedAccounts
License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
import SoftLayer
import pprint
# Your SoftLayer API username and key.
USERNAME = 'set me'
API_KEY = 'set me'
# Declaring the API client
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
try:
brand = client['SoftLayer_Account'].getBrand()
print("Brand Id: %s" % brand['id'])
childAccounts = client['SoftLayer_Brand'].getOwnedAccounts(id=brand['id'])
pprint.pprint(childAccounts)
except SoftLayer.SoftLayerAPIError as e:
print(('Error faultCode=%s, faultString=%s'
% (e.faultCode, e.faultString)))
"""
Retrieve all available permissions
Important links:
http://sldn.softlayer.com/reference/services/SoftLayer_User_Customer_CustomerPermission_Permission/getAllObjects
License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
import SoftLayer
import pprint
# Your SoftLayer API username and key.
USERNAME = 'set me'
API_KEY = 'set me'
# Declaring the API client
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
try:
permissions = client['SoftLayer_User_Customer_CustomerPermission_Permission'].getAllObjects()
pprint.pprint(permissions)
except SoftLayer.SoftLayerAPIError as e:
print(('Error faultCode=%s, faultString=%s'
% (e.faultCode, e.faultString)))