2017-09-25 46 views
0

我們使用SoftLayer API來設置和拆除開發虛擬機,並且這些虛擬機的ping監控器的自動設置會向我們發送不需要的消息以顯示其狀態。有沒有辦法通過SoftLayer API,特別是通過python刪除給定虛擬機的監視器?我瀏覽過文檔,但沒有看到添加/刪除顯示器的方法。Softlayer API - 刪除顯示器

回答

0

看到這個代碼

""" 
Delete network monitoring 

The script makes a single call to SoftLayer_Network_Monitor_Version1_Query_Host::deleteObject 
method to delete the network monitoring for more information see below 

Important manual pages: 
http://sldn.softlayer.com/reference/services/SoftLayer_Network_Monitor_Version1_Query_Host 
http://sldn.softlayer.com/reference/services/SoftLayer_Network_Monitor_Version1_Query_Host/deleteObject 

License: http://sldn.softlayer.com/article/License 
Author: SoftLayer Technologies, Inc. <[email protected]> 
""" 
import SoftLayer.API 
from pprint import pprint as pp 

# Your SoftLayer API username and key. 
USERNAME = 'set me' 
API_KEY = 'set me' 

""" 
The id of the network monitor you wish to delete 
to get the network monitorings on your machine use this code: 
virtualGuestService = client['SoftLayer_Virtual_Guest'] 
virtualGuestId = 7698842 
networkMonitors = virtualGuestService.getNetworkMonitors(id = virtualGuestId) 
print (networkMonitors) 
""" 
idNetworkMonitoringToDelete = 1738019 

# Declare the API client 
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY) 
networkMonitorVersionService = client['SoftLayer_Network_Monitor_Version1_Query_Host'] 

# Send the request to delete the object 
try: 
    result = networkMonitorVersionService.deleteObject(id=idNetworkMonitoringToDelete) 
    pp(result) 
except SoftLayer.SoftLayerAPIError as e: 
    print("Unable to delete the network monitoring " 
      % (e.faultCode, e.faultString)) 
    exit(1) 
+0

完美。謝謝! –