Class ServerServiceImpl
- java.lang.Object
-
- org.openstack4j.openstack.internal.BaseOpenStackService
-
- org.openstack4j.openstack.compute.internal.BaseComputeServices
-
- org.openstack4j.openstack.compute.internal.ServerServiceImpl
-
- All Implemented Interfaces:
ServerService
public class ServerServiceImpl extends BaseComputeServices implements ServerService
Server Operation API implementation- Author:
- Jeremy Unruh
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.openstack4j.openstack.internal.BaseOpenStackService
BaseOpenStackService.Invocation<R>
-
-
Constructor Summary
Constructors Constructor Description ServerServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ActionResponseaction(String serverId, Action action)Executes the specified Action such as RESUME, PAUSE, START, STOP ...ActionResponseaddSecurityGroup(String serverId, String secGroupName)Associates the specified Server Group by name to the Server by it's identifierVolumeAttachmentattachVolume(String serverId, String volumeId, String device)attach the volume to the given serverActionResponsebackupServer(String serverId, BackupOptions options){#invokeAction(String, String)Serverboot(ServerCreate server)Create (boot) a new ServerServerbootAndWaitActive(ServerCreate server, int maxWaitTime)Create (boot) a new ServerActionResponsechangeAdminPassword(String serverId, String adminPassword)Changes the admin/root password on the serverActionResponseconfirmResize(String serverId)Confirm that the resize worked, thus removing the original serverStringcreateSnapshot(String serverId, String snapshotName)Creates the snapshot for a ServerStringcreateSnapshot(String serverId, String snapshotName, Map<String,String> metadata)Creates the snapshot from a serverActionResponsedelete(String serverId)Delete (i.e shut down and delete the image) of the serverActionResponsedeleteMetadataItem(String serverId, String key)Removes the specified metadata item via the specifiedkeyandserverIdActionResponsedetachVolume(String serverId, String attachmentId)detach the volume to the given serverMap<String,? extends Number>diagnostics(String serverId)Gets usage information about the server.ServerPasswordevacuate(String serverId, EvacuateOptions options)Evacuates a server identified withserverIdfrom a failed host to a new hostServerget(String serverId)Get the specified server by IDStringgetConsoleOutput(String serverId, int numLines)Will attempt to tail and return the lastnumLinesfrom the given servers console.Map<String,String>getMetadata(String serverId)Returns the metadata for the specified serverServerPasswordgetPassword(String serverId)Returns the encrypted password for the specified server which can be decrypted with the private keyVNCConsolegetVNCConsole(String serverId, VNCConsole.Type type)Obtains the VNC Console connection information for the given server and VNC Console TypeInstanceActionsServiceinstanceActions()The instance actions service extension (os-instance-actions)InterfaceServiceinterfaces()The interface attachment service extension (os-interface)List<? extends Server>list()List all servers (detailed) that the current tenant has access toList<? extends Server>list(boolean detail)List all servers (detailed / brief) that the current tenant has access toList<? extends Server>list(Map<String,String> filteringParams)Returns list of servers filtered by parameters.List<? extends Server>listAll(boolean detail)List all servers for all tenants (detailed / brief)ActionResponseliveMigrate(String serverId, LiveMigrateOptions options)Live-migrates a server identified withserverIdto a new host without rebootingActionResponsemigrateServer(String serverId)Only user with admin role can do this.ActionResponsereboot(String serverId, RebootType type)Reboot a server by SOFT (software-level) or HARD (hardware power cycle)ActionResponserebuild(String serverId, RebuildOptions options)Rebuilds the specified serverActionResponseremoveSecurityGroup(String serverId, String secGroupName)Removes the specified Server Group by name from the Server by it's identifierActionResponseresetState(String serverId, Server.Status state)Resets the state of a server to a specifiedstateActionResponseresize(String serverId, String flavorId)Resize a server's resources.ActionResponserevertResize(String serverId)Revert a previous resize, switching back to the old serverServerCreateBuilderserverBuilder()Serverupdate(String serverId, ServerUpdateOptions options)Updates an existing Server instanceMap<String,String>updateMetadata(String serverId, Map<String,String> metadata)Creates or replaces metadata items for the specified serverServerwaitForServerStatus(String serverId, Server.Status status, int maxWait, TimeUnit maxWaitUnit)Will poll the Server waiting for theStatusto match or an Error state occurs for themaxWait-
Methods inherited from class org.openstack4j.openstack.compute.internal.BaseComputeServices
invokeAction, invokeActionWithResponse
-
Methods inherited from class org.openstack4j.openstack.internal.BaseOpenStackService
delete, deleteWithResponse, get, getProvider, getServiceVersion, getWithResponse, getXOpenstackRequestId, head, patch, patchWithResponse, post, postWithResponse, put, putWithResponse, request, toList, uri
-
-
-
-
Method Detail
-
list
public List<? extends Server> list()
List all servers (detailed) that the current tenant has access to- Specified by:
listin interfaceServerService- Returns:
- list of all servers
-
list
public List<? extends Server> list(boolean detail)
List all servers (detailed / brief) that the current tenant has access to- Specified by:
listin interfaceServerService- Parameters:
detail- if true all attributes will be populated, false (brief) will be ID, Name and Links- Returns:
- list of all servers
-
listAll
public List<? extends Server> listAll(boolean detail)
List all servers for all tenants (detailed / brief)- Specified by:
listAllin interfaceServerService- Parameters:
detail- if true all attributes will be populated, false (brief) will be ID, Name and Links- Returns:
- list of all servers
-
list
public List<? extends Server> list(Map<String,String> filteringParams)
Returns list of servers filtered by parameters.- Specified by:
listin interfaceServerService- Parameters:
filteringParams- map (name, value) of filtering parameters
-
get
public Server get(String serverId)
Get the specified server by ID- Specified by:
getin interfaceServerService- Parameters:
serverId- the server id- Returns:
- the server or null if not found
-
boot
public Server boot(ServerCreate server)
Create (boot) a new Server- Specified by:
bootin interfaceServerService- Parameters:
server- the server to boot- Returns:
- the newly created server
-
bootAndWaitActive
public Server bootAndWaitActive(ServerCreate server, int maxWaitTime)
Create (boot) a new Server- Specified by:
bootAndWaitActivein interfaceServerService- Parameters:
server- the server to bootmaxWaitTime- the max time to wait in milliseconds for the server to become ACTIVE- Returns:
- the newly created server
-
delete
public ActionResponse delete(String serverId)
Delete (i.e shut down and delete the image) of the server- Specified by:
deletein interfaceServerService- Parameters:
serverId- the server identifier- Returns:
- the action response
-
action
public ActionResponse action(String serverId, Action action)
Executes the specified Action such as RESUME, PAUSE, START, STOP ... see (@linkActionfor all possible actions- Specified by:
actionin interfaceServerService- Parameters:
serverId- the server identifier to execute the action againstaction- the action the specified action- Returns:
- the action response
-
createSnapshot
public String createSnapshot(String serverId, String snapshotName)
Creates the snapshot for a Server- Specified by:
createSnapshotin interfaceServerService- Parameters:
serverId- the server idsnapshotName- the snapshot name- Returns:
- the newly created snapshot UUID
-
createSnapshot
public String createSnapshot(String serverId, String snapshotName, Map<String,String> metadata)
Creates the snapshot from a server- Specified by:
createSnapshotin interfaceServerService- Parameters:
serverId- the UUID of the serversnapshotName- the display name of the snapshotmetadata- the key/value properties for the snapshot- Returns:
- the UUID for the resulting image snapshot
-
reboot
public ActionResponse reboot(String serverId, RebootType type)
Reboot a server by SOFT (software-level) or HARD (hardware power cycle)- Specified by:
rebootin interfaceServerService- Parameters:
serverId- the server idtype- the type of reboot- Returns:
- the action response
-
rebuild
public ActionResponse rebuild(String serverId, RebuildOptions options)
Rebuilds the specified server- Specified by:
rebuildin interfaceServerService- Parameters:
serverId- the server idoptions- additional options used during the rebuild. (OPTIONAL, can be null)- Returns:
- the action response
-
resize
public ActionResponse resize(String serverId, String flavorId)
Resize a server's resources. Until a resize event is confirmedServerService.confirmResize(String), the old server will be kept around and you'll be able to roll back to the old flavor quick withServerService.revertResize(String). All resizes will be automatically confirmed after 24 hours.- Specified by:
resizein interfaceServerService- Parameters:
serverId- the server identifierflavorId- the new flavor id to resize to- Returns:
- the action response
-
addSecurityGroup
public ActionResponse addSecurityGroup(String serverId, String secGroupName)
Associates the specified Server Group by name to the Server by it's identifier- Specified by:
addSecurityGroupin interfaceServerService- Parameters:
serverId- the server identifiersecGroupName- the security group name- Returns:
- the action response
-
removeSecurityGroup
public ActionResponse removeSecurityGroup(String serverId, String secGroupName)
Removes the specified Server Group by name from the Server by it's identifier- Specified by:
removeSecurityGroupin interfaceServerService- Parameters:
serverId- the server identifiersecGroupName- the security group name- Returns:
- the action response
-
confirmResize
public ActionResponse confirmResize(String serverId)
Confirm that the resize worked, thus removing the original server- Specified by:
confirmResizein interfaceServerService- Parameters:
serverId- the server identifier- Returns:
- the action response
-
revertResize
public ActionResponse revertResize(String serverId)
Revert a previous resize, switching back to the old server- Specified by:
revertResizein interfaceServerService- Parameters:
serverId- the server identifier- Returns:
- the action response
-
getConsoleOutput
public String getConsoleOutput(String serverId, int numLines)
Will attempt to tail and return the lastnumLinesfrom the given servers console.- Specified by:
getConsoleOutputin interfaceServerService- Parameters:
serverId- the server identifiernumLines- the number of console lines to return. If lower or equal than zero, the whole console content will be returned.- Returns:
- console output as string or null
-
getVNCConsole
public VNCConsole getVNCConsole(String serverId, VNCConsole.Type type)
Obtains the VNC Console connection information for the given server and VNC Console Type- Specified by:
getVNCConsolein interfaceServerService- Parameters:
serverId- the server identifiertype- the VNC Console type- Returns:
- VNCConsole or null if not applicable
-
diagnostics
public Map<String,? extends Number> diagnostics(String serverId)
Gets usage information about the server. Usage includes CPU, Memory, IO. Information is dependent on the hypervisor used by the OpenStack installation and whether that hypervisor supports diagnostics- Specified by:
diagnosticsin interfaceServerService- Parameters:
serverId- the server id- Returns:
- Map of collected usage statistics organized by key and value
-
serverBuilder
public ServerCreateBuilder serverBuilder()
- Specified by:
serverBuilderin interfaceServerService- Returns:
- a builder to create a ServerCreate
-
attachVolume
public VolumeAttachment attachVolume(String serverId, String volumeId, String device)
attach the volume to the given server- Specified by:
attachVolumein interfaceServerService- Parameters:
serverId- the server identifiervolumeId- the volume identifierdevice- the device to attach the volume to, ex /dev/vda- Returns:
- volumeAttachment or null if not applicable
-
detachVolume
public ActionResponse detachVolume(String serverId, String attachmentId)
detach the volume to the given server- Specified by:
detachVolumein interfaceServerService- Parameters:
serverId- the server identifierattachmentId- the attachment identifier- Returns:
- the action response
-
migrateServer
public ActionResponse migrateServer(String serverId)
Only user with admin role can do this. Migrate a server. The new host will be selected by the scheduler. Until a resize event is confirmedServerService.confirmResize(String), the old server will be kept around and you'll be able to roll back to the old host quick withServerService.revertResize(String). All resizes will be automatically confirmed after 24 hours.- Specified by:
migrateServerin interfaceServerService- Parameters:
serverId- the server identifier- Returns:
- the action response
-
liveMigrate
public ActionResponse liveMigrate(String serverId, LiveMigrateOptions options)
Live-migrates a server identified withserverIdto a new host without rebooting- Specified by:
liveMigratein interfaceServerService- Parameters:
serverId- the server identifieroptions- live migration options- Returns:
- ActionResponse
-
resetState
public ActionResponse resetState(String serverId, Server.Status state)
Resets the state of a server to a specifiedstate- Specified by:
resetStatein interfaceServerService- Parameters:
serverId- the server identifierstate- the new server state- Returns:
- ActionResponse
-
backupServer
public ActionResponse backupServer(String serverId, BackupOptions options)
{#invokeAction(String, String)- Specified by:
backupServerin interfaceServerService- Parameters:
serverId- the server identifieroptions- the backup options- Returns:
- ActionResponse
-
changeAdminPassword
public ActionResponse changeAdminPassword(String serverId, String adminPassword)
Changes the admin/root password on the server- Specified by:
changeAdminPasswordin interfaceServerService- Parameters:
serverId- the server identifieradminPassword- the new password- Returns:
- ActionResponse
-
waitForServerStatus
public Server waitForServerStatus(String serverId, Server.Status status, int maxWait, TimeUnit maxWaitUnit)
Will poll the Server waiting for theStatusto match or an Error state occurs for themaxWait- Specified by:
waitForServerStatusin interfaceServerService- Parameters:
serverId- the server identifierstatus- the status to wait formaxWait- the max wait timemaxWaitUnit- the unit the max wait time was specified in- Returns:
- the last Server polled or null. User should re-check status in case max wait was hit and the status was still not in the desired state.
-
getMetadata
public Map<String,String> getMetadata(String serverId)
Returns the metadata for the specified server- Specified by:
getMetadatain interfaceServerService- Parameters:
serverId- the server identifier- Returns:
- Map of metadata of key and value
-
updateMetadata
public Map<String,String> updateMetadata(String serverId, Map<String,String> metadata)
Creates or replaces metadata items for the specified server- Specified by:
updateMetadatain interfaceServerService- Parameters:
serverId- the server identifiermetadata- the metadata to create or update- Returns:
- Map of metadata as the current state on the server
-
deleteMetadataItem
public ActionResponse deleteMetadataItem(String serverId, String key)
Removes the specified metadata item via the specifiedkeyandserverId- Specified by:
deleteMetadataItemin interfaceServerService- Parameters:
serverId- the server identifierkey- the metadata key to remove- Returns:
- the action response
-
update
public Server update(String serverId, ServerUpdateOptions options)
Description copied from interface:ServerServiceUpdates an existing Server instance- Specified by:
updatein interfaceServerService- Parameters:
serverId- the server identifieroptions- the options used to update- Returns:
- the updated server
-
interfaces
public InterfaceService interfaces()
Description copied from interface:ServerServiceThe interface attachment service extension (os-interface)- Specified by:
interfacesin interfaceServerService- Returns:
- the interface service
-
instanceActions
public InstanceActionsService instanceActions()
Description copied from interface:ServerServiceThe instance actions service extension (os-instance-actions)- Specified by:
instanceActionsin interfaceServerService- Returns:
- the instance actions service
-
getPassword
public ServerPassword getPassword(String serverId)
Returns the encrypted password for the specified server which can be decrypted with the private key- Specified by:
getPasswordin interfaceServerService- Parameters:
serverId- the server identifier- Returns:
- the encrypted server password
-
evacuate
public ServerPassword evacuate(String serverId, EvacuateOptions options)
Evacuates a server identified withserverIdfrom a failed host to a new host- Specified by:
evacuatein interfaceServerService- Parameters:
serverId- the server identifieroptions- evaucate options- Returns:
- an administrative password to access the evacuated or rebuilt instance.
-
-