Search in sources :

Example 1 with OpenStackImage

use of com.att.cdp.openstack.model.OpenStackImage in project AJSC by att.

the class OpenStackImageService method getImageByName.

/**
 * This method is used to get the image where the name of the image exactly matches the supplied name.
 *
 * @param name
 *            The name that is compared to the image name to select it for the returned image.
 * @return The image that match the specified name
 * @throws ZoneException
 *             If anything fails
 * @see com.att.cdp.zones.ImageService#getImageByName(java.lang.String)
 */
@SuppressWarnings("nls")
@Override
public Image getImageByName(String name) throws ZoneException {
    checkArg(name, "name");
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.IMAGE, name);
    RequestState.put(RequestState.SERVICE, "Image");
    RequestState.put(RequestState.SERVICE_URL, glance.getEndpoint());
    Image image = null;
    try {
        com.woorea.openstack.glance.ImagesResource.List openStackRequest = glance.getClient().images().list(false);
        openStackRequest.queryParam("name", name);
        com.woorea.openstack.glance.model.Images images = openStackRequest.execute();
        if (images.getList() != null && images.getList().size() == 1) {
            image = new OpenStackImage(context, images.getList().get(0));
        }
    } catch (OpenStackBaseException ex) {
        ExceptionMapper.mapException(ex);
    }
    return image;
}
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) Image(com.att.cdp.zones.model.Image) AbstractImage(com.att.cdp.zones.spi.AbstractImage) OpenStackImage(com.att.cdp.openstack.model.OpenStackImage)

Example 2 with OpenStackImage

use of com.att.cdp.openstack.model.OpenStackImage 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)
 */
@SuppressWarnings("nls")
@Override
public List<Image> listImages(String pattern) throws ZoneException {
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.IMAGE, pattern);
    RequestState.put(RequestState.SERVICE, "Image");
    RequestState.put(RequestState.SERVICE_URL, glance.getEndpoint());
    ArrayList<Image> list = new ArrayList<>();
    try {
        /*
             * Since a subset of the collection of images is returned, next link is provided to get the next set of
             * images.
             */
        String next = null;
        do {
            com.woorea.openstack.glance.ImagesResource.List openStackRequest = glance.getClient().images().list(false);
            if (next != null) {
                int index = next.indexOf("?");
                openStackRequest.queryString(next.substring(++index));
            }
            com.woorea.openstack.glance.model.Images images = openStackRequest.execute();
            for (com.woorea.openstack.glance.model.Image osImage : images) {
                if (pattern != null) {
                    if (osImage.getName().matches(pattern)) {
                        list.add(new OpenStackImage(context, osImage));
                    }
                } else {
                    list.add(new OpenStackImage(context, osImage));
                }
            }
            next = images.getNext();
        } while (next != null);
    } 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 3 with OpenStackImage

use of com.att.cdp.openstack.model.OpenStackImage in project AJSC by att.

the class OpenStackImageService method getImage.

/**
 * @see com.att.cdp.zones.ImageService#getImage(java.lang.String)
 */
@SuppressWarnings("nls")
@Override
public Image getImage(String id) throws ZoneException {
    checkArg(id, "id");
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.IMAGE, id);
    RequestState.put(RequestState.SERVICE, "Image");
    RequestState.put(RequestState.SERVICE_URL, glance.getEndpoint());
    try {
        com.woorea.openstack.glance.model.Image image = glance.getClient().images().show(id).execute();
        return new OpenStackImage(context, image);
    } catch (OpenStackBaseException ex) {
        ExceptionMapper.mapException(ex);
    }
    // just for the compiler
    return null;
}
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)

Example 4 with OpenStackImage

use of com.att.cdp.openstack.model.OpenStackImage 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()
 */
@SuppressWarnings("nls")
@Override
public List<Image> listImages() throws ZoneException {
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.SERVICE, "Image");
    RequestState.put(RequestState.SERVICE_URL, glance.getEndpoint());
    ArrayList<Image> list = new ArrayList<>();
    try {
        /*
             * Since a subset of the collection of images is returned, next link is provided to get the next set of
             * images.
             */
        String next = null;
        do {
            com.woorea.openstack.glance.ImagesResource.List openStackRequest = glance.getClient().images().list(false);
            if (next != null) {
                int index = next.indexOf("?");
                openStackRequest.queryString(next.substring(++index));
            }
            com.woorea.openstack.glance.model.Images images = openStackRequest.execute();
            for (com.woorea.openstack.glance.model.Image osImage : images) {
                list.add(new OpenStackImage(context, osImage));
            }
            next = images.getNext();
        } while (next != null);
    } 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 5 with OpenStackImage

use of com.att.cdp.openstack.model.OpenStackImage in project AJSC by att.

the class OpenStackImageService method getImageByName.

/**
 * This method is used to get the image where the name of the image exactly matches the supplied name.
 *
 * @param name
 *            The name that is compared to the image name to select it for the returned image.
 * @return The image that match the specified name
 * @throws ZoneException
 *             If anything fails
 * @see com.att.cdp.zones.ImageService#getImageByName(java.lang.String)
 */
@SuppressWarnings("nls")
@Override
public Image getImageByName(String name) throws ZoneException {
    checkArg(name, "name");
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.IMAGE, name);
    RequestState.put(RequestState.SERVICE, "Compute");
    RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
    Image image = null;
    try {
        com.woorea.openstack.nova.api.ImagesResource.List openStackRequest = nova.getClient().images().list(true);
        openStackRequest.queryParam("name", name);
        Images images = openStackRequest.execute();
        if (images.getList() != null && images.getList().size() == 1) {
            image = new OpenStackImage(context, images.getList().get(0));
        }
    } catch (OpenStackBaseException ex) {
        ExceptionMapper.mapException(ex);
    }
    return image;
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) Images(com.woorea.openstack.nova.model.Images) OpenStackImage(com.att.cdp.openstack.model.OpenStackImage) Image(com.att.cdp.zones.model.Image) AbstractImage(com.att.cdp.zones.spi.AbstractImage) OpenStackImage(com.att.cdp.openstack.model.OpenStackImage)

Aggregations

OpenStackContext (com.att.cdp.openstack.OpenStackContext)8 OpenStackImage (com.att.cdp.openstack.model.OpenStackImage)8 Context (com.att.cdp.zones.Context)8 OpenStackBaseException (com.woorea.openstack.base.client.OpenStackBaseException)8 Image (com.att.cdp.zones.model.Image)6 AbstractImage (com.att.cdp.zones.spi.AbstractImage)6 ArrayList (java.util.ArrayList)4 Images (com.woorea.openstack.nova.model.Images)1