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
  • Field Details

  • Constructor Details

    • Openstack

      public Openstack(@Nonnull org.openstack4j.api.OSClient<?> client)
  • Method Details

    • getFlavorInfo

      @Nonnull public static String getFlavorInfo(@Nonnull org.openstack4j.model.compute.Flavor f)
    • getInfo

      @Nonnull public String getInfo()
      Get information about OpenStack deployment.
    • _listNetworks

      @Nonnull public List<? extends org.openstack4j.model.network.Network> _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 return null 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

      @Nonnull public Map<String,List<org.openstack4j.model.image.v2.Image>> getImages()
      Finds all Images.
      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 all VolumeSnapshots that are Volume.Status.AVAILABLE.
      Returns:
      A Map of collections of VolumeSnapshots, 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

      @Nonnull public Collection<? extends org.openstack4j.model.compute.Flavor> getSortedFlavors()
    • getSortedIpPools

      @Nonnull public List<String> getSortedIpPools()
    • getAvailabilityZones

      @Nonnull public List<? extends org.openstack4j.model.compute.ext.AvailabilityZone> getAvailabilityZones()
    • getRunningNodes

      @Nonnull public List<org.openstack4j.model.compute.Server> getRunningNodes()
    • getFreeFipIds

      @Nonnull public List<String> getFreeFipIds()
      Get list of Floating IPs created for this Jenkins instance that are not connected to any server.
    • getSortedKeyPairNames

      @Nonnull public List<String> getSortedKeyPairNames()
    • getImageIdsFor

      @Nonnull public List<String> getImageIdsFor(String nameOrId)
      Finds the Id(s) of all active Images with the given name or ID. If we have found multiple Images then they will be listed in ascending date order (oldest first).
      Parameters:
      nameOrId - The Image name or ID.
      Returns:
      Zero, one or multiple IDs.
    • getVolumeSnapshotIdsFor

      @Nonnull public List<String> getVolumeSnapshotIdsFor(String nameOrId)
      Finds the Id(s) of all available VolumeSnapshots with the given name or ID. If we have found multiple VolumeSnapshots then they will be listed in ascending date order (oldest first).
      Parameters:
      nameOrId - The VolumeSnapshot name or ID.
      Returns:
      Zero, one or multiple IDs.
    • getVolumeSnapshotDescription

      @CheckForNull public String getVolumeSnapshotDescription(String volumeSnapshotId)
      Gets the description of a VolumeSnapshot. 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 a Volume. 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

      @Nonnull public String instanceUrl()
      Identification for instances launched by this instance via this plugin.
      Returns:
      Identifier to filter instances we control.
    • instanceFingerprint

      @Nonnull public String instanceFingerprint()
      Binary fingerprint to be unique worldwide.
    • getServerById

      @Nonnull public org.openstack4j.model.compute.Server getServerById(@Nonnull String id) throws NoSuchElementException
      Throws:
      NoSuchElementException
    • getServersByName

      @Nonnull public List<org.openstack4j.model.compute.Server> getServersByName(@Nonnull String name)
    • 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. Use DestroyMachine 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 FIP
      poolName - Name of the FIP pool to use.
      Returns:
      Updated server.
      Throws:
      Openstack.ActionFailed
    • destroyFip

      public void destroyFip(String fip)
    • 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

      @CheckForNull public Throwable sanityCheck()
      Perform some tests before calling the connection successfully established.