def get_iscsi(self,volume_id,** kwargs)
我已使用此方法获取特定存储组件的详细信息,但我无法借助API服务提取加密状态。
哪些API可用于提取iSCSI存储的加密状态?
答案 0 :(得分:0)
hasEncryptionAtRest 属性将提供此信息,您可以尝试以下休息请求:
https://$user:$apiKey@api.softlayer.com/rest/v3/SoftLayer_Network_Storage/$storageId/getObject?objectMask=mask[hasEncryptionAtRest]
Method: Get
使用您自己的值替换 $ user , $ apiKey 和 $ storageId
<强>参考强>:
<强>更新强>
这是一个使用 get_iscsi 方法
的Python脚本"""
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)))
更新2
此脚本将帮助您从帐户的公共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)))
更新3
不幸的是,没有任何SL API服务可以提供帮助,但请查看以下链接,
您可以尝试使用它来检查IP地址,因此脚本:
"""
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)))
如您所见,将在“bls”主机中检查ips,您可以添加更多主机进行检查,这里有一个在线网站,您可以检索黑名单主机进行检查:
"""
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)))
答案 1 :(得分:0)
"""
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)))