Class Openstack
java.lang.Object
jenkins.plugins.openstack.compute.internal.Openstack
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class)
@ThreadSafe
public class Openstack
extends Object
Encapsulate
OSClient
.
It is needed to make sure the client is truly immutable and provide easy-to-mock abstraction for unit testing.
For server manipulation, this implementation provides metadata fingerprinting
to identify machines started via this plugin from given instance so it will not
manipulate servers it does not "own". In other words, pretends that there are no
other machines running in connected tenant except for those started using this class.- Author:
- ogondza
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
static final class
static class
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionorg.openstack4j.model.compute.Server
_bootAndWaitActive
(org.openstack4j.model.compute.builder.ServerCreateBuilder request, int timeout) List<? extends org.openstack4j.model.network.Network>
org.openstack4j.model.compute.Server
assignFloatingIp
(org.openstack4j.model.compute.Server server, String poolName) Assign floating ip address to the server.void
attachFingerprint
(org.openstack4j.model.compute.builder.ServerCreateBuilder request) org.openstack4j.model.compute.Server
bootAndWaitActive
(org.openstack4j.model.compute.builder.ServerCreateBuilder request, int timeout) Provision machine and wait until ready.void
destroyFip
(String fip) void
destroyServer
(org.openstack4j.model.compute.Server server) Delete server eagerly.static String
getAccessIpAddress
(org.openstack4j.model.compute.Server server) Extract public address from server.static org.openstack4j.model.compute.Address
getAccessIpAddressObject
(org.openstack4j.model.compute.Server server) List<? extends org.openstack4j.model.compute.ext.AvailabilityZone>
static String
getFlavorInfo
(org.openstack4j.model.compute.Flavor f) Get list of Floating IPs created for this Jenkins instance that are not connected to any server.getImageIdsFor
(String nameOrId) Finds the Id(s) of all activeImage
s with the given name or ID.Finds allImage
s.getInfo()
Get information about OpenStack deployment.List<? extends org.openstack4j.model.network.ext.NetworkIPAvailability>
getNetworks
(List<String> nameOrIds) List all requested network details.getNetworksCapacity
(Map<String, org.openstack4j.model.network.Network> declaredNetworks) For every network requested, return mapping of network and number of available fixed addresses.List<org.openstack4j.model.compute.Server>
org.openstack4j.model.compute.Server
getServerById
(String id) List<org.openstack4j.model.compute.Server>
getServersByName
(String name) Collection<? extends org.openstack4j.model.compute.Flavor>
getVolumeSnapshotDescription
(String volumeSnapshotId) Gets the description of aVolumeSnapshot
.getVolumeSnapshotIdsFor
(String nameOrId) Finds the Id(s) of all availableVolumeSnapshot
s with the given name or ID.Finds allVolumeSnapshot
s that areVolume.Status.AVAILABLE
.Binary fingerprint to be unique worldwide.Identification for instances launched by this instance via this plugin.static boolean
isOccupied
(org.openstack4j.model.compute.Server server) Determine whether the server is considered occupied by openstack plugin.Perform some tests before calling the connection successfully established.void
setVolumeNameAndDescription
(String volumeId, String newVolumeName, String newVolumeDescription) Sets the name and description of aVolume
.org.openstack4j.model.compute.Server
updateInfo
(org.openstack4j.model.compute.Server server) Fetch updated info about the server.
-
Field Details
-
FINGERPRINT_KEY_URL
- See Also:
-
FINGERPRINT_KEY_FINGERPRINT
- See Also:
-
-
Constructor Details
-
Openstack
public Openstack(@Nonnull org.openstack4j.api.OSClient<?> client)
-
-
Method Details
-
getFlavorInfo
-
getInfo
Get information about OpenStack deployment. -
_listNetworks
-
getNetworks
@Nonnull public Map<String,org.openstack4j.model.network.Network> getNetworks(@Nonnull List<String> nameOrIds) List all requested network details.- Parameters:
nameOrIds
- List of network names/IDs.- Returns:
- Map of ID and network.
-
getNetworksCapacity
@Nonnull public Map<org.openstack4j.model.network.Network,Integer> getNetworksCapacity(@Nonnull Map<String, org.openstack4j.model.network.Network> declaredNetworks) For every network requested, return mapping of network and number of available fixed addresses. Note the network-ip-availability is usually available for admins only so the method may returnnull
in that case.- Returns:
- Map of requested networks and their free capacity. Might be empty.
-
getNetworkIPAvailability
public List<? extends org.openstack4j.model.network.ext.NetworkIPAvailability> getNetworkIPAvailability() -
getImages
Finds allImage
s.- Returns:
- A Map of collections of images, indexed by name (or id if the image has no name) in ascending order and, in the event of name-collisions, the images for a given name are sorted by creation date.
-
getVolumeSnapshots
@Nonnull public Map<String,List<org.openstack4j.model.storage.block.VolumeSnapshot>> getVolumeSnapshots()Finds allVolumeSnapshot
s that areVolume.Status.AVAILABLE
.- Returns:
- A Map of collections of
VolumeSnapshot
s, indexed by name (or id if the volume snapshot has no name) in ascending order and, in the event of name-collisions, the volume snapshots for a given name are sorted by creation date.
-
getSortedFlavors
-
getSortedIpPools
-
getAvailabilityZones
@Nonnull public List<? extends org.openstack4j.model.compute.ext.AvailabilityZone> getAvailabilityZones() -
getRunningNodes
-
getFreeFipIds
Get list of Floating IPs created for this Jenkins instance that are not connected to any server. -
getSortedKeyPairNames
-
getImageIdsFor
Finds the Id(s) of all activeImage
s with the given name or ID. If we have found multipleImage
s then they will be listed in ascending date order (oldest first).- Parameters:
nameOrId
- TheImage
name or ID.- Returns:
- Zero, one or multiple IDs.
-
getVolumeSnapshotIdsFor
Finds the Id(s) of all availableVolumeSnapshot
s with the given name or ID. If we have found multipleVolumeSnapshot
s then they will be listed in ascending date order (oldest first).- Parameters:
nameOrId
- TheVolumeSnapshot
name or ID.- Returns:
- Zero, one or multiple IDs.
-
getVolumeSnapshotDescription
Gets the description of aVolumeSnapshot
. This will be visible if a user looks at volume snapshots using the OpenStack command-line or WebUI and may well contain useful information.- Parameters:
volumeSnapshotId
- The ID of the volume snapshot whose description is to be retrieved.- Returns:
- The description string, or null if there isn't one.
-
setVolumeNameAndDescription
public void setVolumeNameAndDescription(String volumeId, String newVolumeName, String newVolumeDescription) Sets the name and description of aVolume
. These will be visible if a user looks at volumes using the OpenStack command-line or WebUI.- Parameters:
volumeId
- The ID of the volume whose name and description are to be set.newVolumeName
- The new name for the volume.newVolumeDescription
- The new description for the volume.
-
isOccupied
public static boolean isOccupied(@Nonnull org.openstack4j.model.compute.Server server) Determine whether the server is considered occupied by openstack plugin. -
instanceUrl
Identification for instances launched by this instance via this plugin.- Returns:
- Identifier to filter instances we control.
-
instanceFingerprint
Binary fingerprint to be unique worldwide. -
getServerById
@Nonnull public org.openstack4j.model.compute.Server getServerById(@Nonnull String id) throws NoSuchElementException - Throws:
NoSuchElementException
-
getServersByName
-
bootAndWaitActive
@Nonnull public org.openstack4j.model.compute.Server bootAndWaitActive(@Nonnull org.openstack4j.model.compute.builder.ServerCreateBuilder request, @Nonnegative int timeout) throws Openstack.ActionFailed Provision machine and wait until ready.- Throws:
Openstack.ActionFailed
- Openstack failed to provision the slave or it was in erroneous state (server will be deleted in such case).
-
attachFingerprint
public void attachFingerprint(@Nonnull org.openstack4j.model.compute.builder.ServerCreateBuilder request) -
_bootAndWaitActive
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public org.openstack4j.model.compute.Server _bootAndWaitActive(@Nonnull org.openstack4j.model.compute.builder.ServerCreateBuilder request, @Nonnegative int timeout) -
updateInfo
@Nonnull public org.openstack4j.model.compute.Server updateInfo(@Nonnull org.openstack4j.model.compute.Server server) Fetch updated info about the server. -
destroyServer
public void destroyServer(@Nonnull org.openstack4j.model.compute.Server server) throws Openstack.ActionFailed Delete server eagerly. The deletion tends to fail a couple of time before it succeeds. This method throws on any such failure. UseDestroyMachine
to destroy the server reliably.- Throws:
Openstack.ActionFailed
-
assignFloatingIp
@Nonnull public org.openstack4j.model.compute.Server assignFloatingIp(@Nonnull org.openstack4j.model.compute.Server server, @Nonnull String poolName) throws Openstack.ActionFailed Assign floating ip address to the server. Note that after the successful assignment, the old Server instance becomes outdated as it does not contain the IP details. The IP description will contain fingerprint linking it back to server it was created for. It is guaranteed it will be created after the server so any IP found without its server running is a leaked one.- Parameters:
server
- Server to assign FIPpoolName
- Name of the FIP pool to use.- Returns:
- Updated server.
- Throws:
Openstack.ActionFailed
-
destroyFip
-
getAccessIpAddress
@CheckForNull public static String getAccessIpAddress(@Nonnull org.openstack4j.model.compute.Server server) throws IllegalArgumentException, NoSuchElementException Extract public address from server.- Returns:
- Preferring IPv4 over IPv6 and floating address over fixed.
- Throws:
IllegalArgumentException
- When address can not be understood.NoSuchElementException
- When no suitable address is found.
-
getAccessIpAddressObject
public static org.openstack4j.model.compute.Address getAccessIpAddressObject(@Nonnull org.openstack4j.model.compute.Server server) -
sanityCheck
Perform some tests before calling the connection successfully established.
-