@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.
  • 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> _listNetworks()
    • getNetworks

      @Nonnull public Map<String,> getNetworks(@Nonnull List<String> nameOrIds)
      List all requested network details.
      nameOrIds - List of network names/IDs.
      Map of ID and network.
    • getNetworksCapacity

      @Nonnull public Map<,Integer> getNetworksCapacity(@Nonnull Map<String,> 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.
      Map of requested networks and their free capacity. Might be empty.
    • getNetworkIPAvailability

      public List<? extends> getNetworkIPAvailability()
    • getImages

      @Nonnull public Map<String,List<org.openstack4j.model.image.v2.Image>> getImages()
      Finds all Images.
      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<>> getVolumeSnapshots()
      Finds all VolumeSnapshots that are Volume.Status.AVAILABLE.
      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).
      nameOrId - The Image name or ID.
      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).
      nameOrId - The VolumeSnapshot name or ID.
      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.
      volumeSnapshotId - The ID of the volume snapshot whose description is to be retrieved.
      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.
      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.
      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
    • 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.
      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.
    • 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.
      server - Server to assign FIP
      poolName - Name of the FIP pool to use.
      Updated server.
    • 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.
      Preferring IPv4 over IPv6 and floating address over fixed.
      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.