Search in sources :

Example 6 with Image

use of com.att.cdp.zones.model.Image in project AJSC by att.

the class OpenStackImageService method listImages.

/**
 * This method is used to list all of the images that are available within the context.
 *
 * @return The list of images or an empty list if there are none available.
 * @throws ZoneException
 *             If the service fails.
 * @see com.att.cdp.zones.ImageService#listImages()
 */
@Override
public List<Image> listImages() throws ZoneException {
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.SERVICE, "Compute");
    RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
    ArrayList<Image> list = new ArrayList<>();
    try {
        for (com.woorea.openstack.nova.model.Image osImage : nova.getClient().images().list(true).execute()) {
            list.add(new OpenStackImage(context, osImage));
        }
    } catch (OpenStackBaseException ex) {
        ExceptionMapper.mapException(ex);
    }
    return list;
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) OpenStackImage(com.att.cdp.openstack.model.OpenStackImage) ArrayList(java.util.ArrayList) Image(com.att.cdp.zones.model.Image) AbstractImage(com.att.cdp.zones.spi.AbstractImage) OpenStackImage(com.att.cdp.openstack.model.OpenStackImage)

Example 7 with Image

use of com.att.cdp.zones.model.Image in project AJSC by att.

the class TestImages method listImages.

/**
 * Verifies that we can list the existing templates on a provider. This test requires that the provider actually has
 * templates installed.
 *
 * @throws ZoneException
 */
@Ignore
@Test
public void listImages() throws ZoneException {
    Context context = connect();
    ImageService service = context.getImageService();
    List<Image> images = service.listImages();
    assertNotNull(images);
    assertFalse(images.isEmpty());
    for (Image image : images) {
        System.out.println(image.toString());
    }
}
Also used : Context(com.att.cdp.zones.Context) Image(com.att.cdp.zones.model.Image) ImageService(com.att.cdp.zones.ImageService) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with Image

use of com.att.cdp.zones.model.Image in project AJSC by att.

the class OpenStackImageService method listImages.

/**
 * This method is used to list all of the images where the name of the image matches the supplied pattern.
 *
 * @param pattern
 *            The pattern (regular expression) that is compared to the image name to select it for the returned
 *            list.
 * @return The list of images that match the specified name pattern
 * @throws ZoneException
 *             If anything fails
 * @see com.att.cdp.zones.ImageService#listImages(java.lang.String)
 */
@Override
public List<Image> listImages(String pattern) throws ZoneException {
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.IMAGE, pattern);
    RequestState.put(RequestState.SERVICE, "Compute");
    RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
    ArrayList<Image> list = new ArrayList<>();
    try {
        for (com.woorea.openstack.nova.model.Image osImage : nova.getClient().images().list(true).execute()) {
            if (pattern != null) {
                if (osImage.getName().matches(pattern)) {
                    list.add(new OpenStackImage(context, osImage));
                }
            } else {
                list.add(new OpenStackImage(context, osImage));
            }
        }
    } catch (OpenStackBaseException ex) {
        ExceptionMapper.mapException(ex);
    }
    return list;
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) OpenStackImage(com.att.cdp.openstack.model.OpenStackImage) ArrayList(java.util.ArrayList) Image(com.att.cdp.zones.model.Image) AbstractImage(com.att.cdp.zones.spi.AbstractImage) OpenStackImage(com.att.cdp.openstack.model.OpenStackImage)

Example 9 with Image

use of com.att.cdp.zones.model.Image in project AJSC by att.

the class TestImages method getImages.

/**
 * Verifies that we can list the existing templates on a provider. This test requires that the provider actually has
 * templates installed.
 *
 * @throws ZoneException
 */
// @Ignore
@Test
@Ignore
public void getImages() throws ZoneException {
    Context context = connect();
    ImageService service = context.getImageService();
    List<Image> images = service.listImages();
    assertNotNull(images);
    assertFalse(images.isEmpty());
    for (Image image : images) {
        service.getImage(image.getId());
    }
}
Also used : Context(com.att.cdp.zones.Context) Image(com.att.cdp.zones.model.Image) ImageService(com.att.cdp.zones.ImageService) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 10 with Image

use of com.att.cdp.zones.model.Image in project AJSC by att.

the class OpenStackServer method loadImageAndBootSource.

/**
 * This method loads the actual image object that the server was booted from, and also determines if there are any
 * snapshots of that image created from this server. If there are, it populates the snapshot list as well and sorts
 * that list into chronological order, most recent first.
 *
 * @param context
 *            The context we are servicing
 */
@SuppressWarnings("nls")
private void loadImageAndBootSource(Context context) {
    if (imagesProcessed.compareAndSet(false, true)) {
        /*
             * Now, lookup the image and attach it to the server
             */
        Image bootImage = null;
        if (novaModel.getImage() != null) {
            try {
                String serverImageId = novaModel.getImage().getId();
                ImageService imageService = context.getImageService();
                List<Image> images = imageService.listImages();
                for (Image image : images) {
                    if (image.getId().equals(serverImageId)) {
                        bootImage = image;
                    }
                    if (image.getImageType().equals(Image.Type.SNAPSHOT) && getId().equals(image.getInstanceId())) {
                        getSnapshots().add(image);
                    }
                }
            } catch (Exception e) {
                LOG.error(String.format("Unexpected exception %s retrieving images for server %s", e.getClass().getSimpleName(), getId()));
                LOG.error(EELFResourceManager.format(e));
            }
        }
        /*
             * Sort the snapshots into chronological order (newest first) if any snapshots exist
             */
        if (!getSnapshots().isEmpty()) {
            Collections.sort(getSnapshots(), new Comparator<Image>() {

                @Override
                public int compare(Image o1, Image o2) {
                    if (o2.getCreatedDate().before(o1.getCreatedDate())) {
                        return -1;
                    } else if (o2.getCreatedDate().after(o1.getCreatedDate())) {
                        return 1;
                    }
                    return 0;
                }
            });
        }
        if (bootImage == null) {
            setBootSource(ServerBootSource.VOLUME);
            setImage(null);
        } else {
            if (bootImage.getImageType().equals(Image.Type.SNAPSHOT)) {
                setBootSource(ServerBootSource.SNAPSHOT);
            } else {
                setBootSource(ServerBootSource.IMAGE);
            }
            setImage(bootImage);
        }
    }
}
Also used : Image(com.att.cdp.zones.model.Image) ImageService(com.att.cdp.zones.ImageService) ZoneException(com.att.cdp.exceptions.ZoneException)

Aggregations

Image (com.att.cdp.zones.model.Image)10 Context (com.att.cdp.zones.Context)9 OpenStackContext (com.att.cdp.openstack.OpenStackContext)6 OpenStackImage (com.att.cdp.openstack.model.OpenStackImage)6 AbstractImage (com.att.cdp.zones.spi.AbstractImage)6 OpenStackBaseException (com.woorea.openstack.base.client.OpenStackBaseException)6 ArrayList (java.util.ArrayList)4 ImageService (com.att.cdp.zones.ImageService)3 Ignore (org.junit.Ignore)2 Test (org.junit.Test)2 ZoneException (com.att.cdp.exceptions.ZoneException)1 Images (com.woorea.openstack.nova.model.Images)1