在 SL 中重命名实例 API
Rename Instance API in SL
我正在寻找 Softlayer APIs 来重命名创建的 VM 和 BareMetal 实例。
使用 Softlayer java-client-lib,APIs 应该从我们正在开发的云门户页面调用。
如果您提供有关此 API.
的任何示例或 API 指南,将会很有帮助
谢谢
迈克
这些示例可能对您有所帮助:
Java 示例:
编辑虚拟访客
package virtualGuest;
import com.softlayer.api.ApiClient;
import com.softlayer.api.RestApiClient;
import com.softlayer.api.service.virtual.Guest;
import com.softlayer.api.service.virtual.Guest.Service;
public class editInstance {
public static void main(String[] args) {
// TODO Auto-generated method stub
String username = "set me";
String apikey = "set me";
ApiClient client = new RestApiClient().withCredentials(username, apikey);
Long vsiId = new Long(11498369);
String newHostName = "vsi-test-JavaEdited";
String myNote = "Editing from Java";
Guest templateObject = new Guest();
templateObject.setHostname(newHostName);
templateObject.setNotes(myNote);
Service vsiService = Guest.service(client, vsiId);
try
{
Boolean result = false;
result = vsiService.editObject(templateObject);
System.out.println("The Virtual Instance Server was edited sucessfullly: " + result);
} catch (Exception e) {
System.out.println(e);
}
}
}
Python 示例:
编辑虚拟访客:
"""
Edit details of a Virtual Guest.
It edits a computing instance's properties
Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest/editObject
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Virtual_Guest
License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
import SoftLayer
# For nice debug output:
from pprint import pprint as pp
# Your SoftLayer API username and key.
API_USERNAME = 'set me'
# Generate one at https://control.softlayer.com/account/users
API_KEY = 'set me'
serverId = 7437756
# Create an object template with data that you wish to edit.
# For example: I want to edit the "hostname" and "notes".
objectTemplate = {
'hostname': 'myhostnameEdited',
'notes': 'edited from api'
}
client = SoftLayer.Client(
username=API_USERNAME,
api_key=API_KEY
)
try:
# Edits an existing virtual Guest server
# The expected result after executing the script is: true
result = client['Virtual_Guest'].editObject(objectTemplate, id=serverId)
pp(result)
except SoftLayer.SoftLayerAPIError as e:
pp('Unable to edit the virtual guest details faultCode=%s, faultString=%s'
% (e.faultCode, e.faultString))
编辑 Bar Metal 服务器:
"""
Edit a bare metal server's basic information
Change the notes property for a single bare metal server record to the sentence "This
is my fastest server!" using the editObject() method in the
SoftLayer_Hardware_Server API service. See below for more details.
Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Hardware_Server/editObject
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'
# The name of the server we wish to edit.
serverName = 'set me'
"""
Define the new local properties to set.
A SoftLayer_Hardware_Server record has a few local properties that you can
change via the API. Every service's editObject() method takes a single
parameter, a skeleton object that only defines the properties we wish to
change. While we're only editing a server's notes in this example you can
also use editObject() to edit the server's host name and domain record.
"""
editTemplate = {
'notes': 'This is my fastest server!'
}
# The id of the bare metal you wish to edit
hardwareId = ''
# Declare a new API service object
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
"""
Call the getHardware() method from the SoftLayer_Account API service to get
a list of hardware on your account, including id numbers.
"""
try:
hardwareList = client['SoftLayer_Account'].getHardware()
except SoftLayer.SoftLayerAPIError as e:
"""
If there was an error returned from the SoftLayer API then bomb out with the
error message.
"""
print("Unable to retrieve bare metal list. "
% (e.faultCode, e.faultString))
# Looking for the server name to get its id
for hardware in hardwareList:
if hardware['hostname'] == serverName:
hardwareId = hardware['id']
# If the server name was not found we throw an error message.
if hardwareId == '':
raise Exception("Unable to find the server with the name " + serverName)
try:
# Edit our server record.
result = client['SoftLayer_Hardware_Server'].editObject(editTemplate, id=hardwareId)
print ('Bare Metal Server edited')
except SoftLayer.SoftLayerAPIError as e:
print("Unable to edit the bare metal server. "
% (e.faultCode, e.faultString))
参考文献:
http://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest/editObject
http://sldn.softlayer.com/reference/services/SoftLayer_Hardware_Server/editObject
你只需要使用编辑方法
http://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest/editObject
http://sldn.softlayer.com/reference/services/SoftLayer_Hardware_Server/editObject
这里是一个为 VSI 更改它的示例
package api.examples;
import java.util.ArrayList;
import java.util.List;
import com.softlayer.api.ApiClient;
import com.softlayer.api.RestApiClient;
import com.softlayer.api.service.virtual.Guest;
public class ChangeHostnameVSI {
public static void main(String[] args) {
String user = "set me";
String apikey = "set me";
// The id of the VSI where you want to change the properties
Long virtualGuestId = new Long(10476867);
// Declare the API client.
ApiClient client = new RestApiClient().withCredentials(user, apikey);
Guest.Service virtualGuestService = Guest.service(client,
virtualGuestId);
try {
Guest guest = new Guest();
// Changing the properties
guest.setHostname("mynewhostname");
guest.setDomain("exampledomain.com");
virtualGuestService.editObject(guest);
System.out.println("The guest was edited. ");
} catch (Exception e) {
System.out
.println("Unable to edit the data. " + e.getMessage());
}
}
}
我正在寻找 Softlayer APIs 来重命名创建的 VM 和 BareMetal 实例。
使用 Softlayer java-client-lib,APIs 应该从我们正在开发的云门户页面调用。
如果您提供有关此 API.
谢谢 迈克
这些示例可能对您有所帮助:
Java 示例:
编辑虚拟访客
package virtualGuest;
import com.softlayer.api.ApiClient;
import com.softlayer.api.RestApiClient;
import com.softlayer.api.service.virtual.Guest;
import com.softlayer.api.service.virtual.Guest.Service;
public class editInstance {
public static void main(String[] args) {
// TODO Auto-generated method stub
String username = "set me";
String apikey = "set me";
ApiClient client = new RestApiClient().withCredentials(username, apikey);
Long vsiId = new Long(11498369);
String newHostName = "vsi-test-JavaEdited";
String myNote = "Editing from Java";
Guest templateObject = new Guest();
templateObject.setHostname(newHostName);
templateObject.setNotes(myNote);
Service vsiService = Guest.service(client, vsiId);
try
{
Boolean result = false;
result = vsiService.editObject(templateObject);
System.out.println("The Virtual Instance Server was edited sucessfullly: " + result);
} catch (Exception e) {
System.out.println(e);
}
}
}
Python 示例:
编辑虚拟访客:
"""
Edit details of a Virtual Guest.
It edits a computing instance's properties
Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest/editObject
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Virtual_Guest
License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
import SoftLayer
# For nice debug output:
from pprint import pprint as pp
# Your SoftLayer API username and key.
API_USERNAME = 'set me'
# Generate one at https://control.softlayer.com/account/users
API_KEY = 'set me'
serverId = 7437756
# Create an object template with data that you wish to edit.
# For example: I want to edit the "hostname" and "notes".
objectTemplate = {
'hostname': 'myhostnameEdited',
'notes': 'edited from api'
}
client = SoftLayer.Client(
username=API_USERNAME,
api_key=API_KEY
)
try:
# Edits an existing virtual Guest server
# The expected result after executing the script is: true
result = client['Virtual_Guest'].editObject(objectTemplate, id=serverId)
pp(result)
except SoftLayer.SoftLayerAPIError as e:
pp('Unable to edit the virtual guest details faultCode=%s, faultString=%s'
% (e.faultCode, e.faultString))
编辑 Bar Metal 服务器:
"""
Edit a bare metal server's basic information
Change the notes property for a single bare metal server record to the sentence "This
is my fastest server!" using the editObject() method in the
SoftLayer_Hardware_Server API service. See below for more details.
Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Hardware_Server/editObject
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'
# The name of the server we wish to edit.
serverName = 'set me'
"""
Define the new local properties to set.
A SoftLayer_Hardware_Server record has a few local properties that you can
change via the API. Every service's editObject() method takes a single
parameter, a skeleton object that only defines the properties we wish to
change. While we're only editing a server's notes in this example you can
also use editObject() to edit the server's host name and domain record.
"""
editTemplate = {
'notes': 'This is my fastest server!'
}
# The id of the bare metal you wish to edit
hardwareId = ''
# Declare a new API service object
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
"""
Call the getHardware() method from the SoftLayer_Account API service to get
a list of hardware on your account, including id numbers.
"""
try:
hardwareList = client['SoftLayer_Account'].getHardware()
except SoftLayer.SoftLayerAPIError as e:
"""
If there was an error returned from the SoftLayer API then bomb out with the
error message.
"""
print("Unable to retrieve bare metal list. "
% (e.faultCode, e.faultString))
# Looking for the server name to get its id
for hardware in hardwareList:
if hardware['hostname'] == serverName:
hardwareId = hardware['id']
# If the server name was not found we throw an error message.
if hardwareId == '':
raise Exception("Unable to find the server with the name " + serverName)
try:
# Edit our server record.
result = client['SoftLayer_Hardware_Server'].editObject(editTemplate, id=hardwareId)
print ('Bare Metal Server edited')
except SoftLayer.SoftLayerAPIError as e:
print("Unable to edit the bare metal server. "
% (e.faultCode, e.faultString))
参考文献:
http://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest/editObject http://sldn.softlayer.com/reference/services/SoftLayer_Hardware_Server/editObject
你只需要使用编辑方法
http://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest/editObject http://sldn.softlayer.com/reference/services/SoftLayer_Hardware_Server/editObject
这里是一个为 VSI 更改它的示例
package api.examples;
import java.util.ArrayList;
import java.util.List;
import com.softlayer.api.ApiClient;
import com.softlayer.api.RestApiClient;
import com.softlayer.api.service.virtual.Guest;
public class ChangeHostnameVSI {
public static void main(String[] args) {
String user = "set me";
String apikey = "set me";
// The id of the VSI where you want to change the properties
Long virtualGuestId = new Long(10476867);
// Declare the API client.
ApiClient client = new RestApiClient().withCredentials(user, apikey);
Guest.Service virtualGuestService = Guest.service(client,
virtualGuestId);
try {
Guest guest = new Guest();
// Changing the properties
guest.setHostname("mynewhostname");
guest.setDomain("exampledomain.com");
virtualGuestService.editObject(guest);
System.out.println("The guest was edited. ");
} catch (Exception e) {
System.out
.println("Unable to edit the data. " + e.getMessage());
}
}
}