Search in sources :

Example 36 with Context

use of com.att.cdp.zones.Context in project AJSC by att.

the class OpenStackComputeService method connect.

/**
 * This is a helper method used to construct the Nova service object and setup the environment to access the
 * OpenStack compute service (Nova).
 *
 * @throws NotLoggedInException
 *             If the user is not logged in
 * @throws ContextClosedException
 *             If the user attempts an operation after the context is closed
 */
private void connect() throws NotLoggedInException, ContextClosedException {
    Context context = getContext();
    checkLogin();
    checkOpen();
    nova = ((OpenStackContext) context).getNovaConnector();
    ((OpenStackContext) context).refreshIfStale(nova);
}
Also used : Context(com.att.cdp.zones.Context) OpenStackContext(com.att.cdp.openstack.OpenStackContext) OpenStackContext(com.att.cdp.openstack.OpenStackContext)

Example 37 with Context

use of com.att.cdp.zones.Context 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 38 with Context

use of com.att.cdp.zones.Context in project AJSC by att.

the class OpenStackImageService method connect.

/**
 * This is a helper method used to construct the Glance service object and setup the environment to access the
 * OpenStack image service (Glance).
 *
 * @throws NotLoggedInException
 *             If the user is not logged in
 * @throws ContextClosedException
 *             If the user attempts an operation after the context is closed
 */
private void connect() throws NotLoggedInException, ContextClosedException {
    checkLogin();
    checkOpen();
    Context context = getContext();
    OpenStackContext osContext = (OpenStackContext) context;
    glance = osContext.getGlanceConnector();
    ((OpenStackContext) context).refreshIfStale(glance);
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) OpenStackContext(com.att.cdp.openstack.OpenStackContext)

Example 39 with Context

use of com.att.cdp.zones.Context 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 40 with Context

use of com.att.cdp.zones.Context 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)

Aggregations

Context (com.att.cdp.zones.Context)248 OpenStackContext (com.att.cdp.openstack.OpenStackContext)167 OpenStackBaseException (com.woorea.openstack.base.client.OpenStackBaseException)140 ArrayList (java.util.ArrayList)55 Ignore (org.junit.Ignore)50 Test (org.junit.Test)47 Quantum (com.woorea.openstack.quantum.Quantum)35 ZoneException (com.att.cdp.exceptions.ZoneException)30 NetworkService (com.att.cdp.zones.NetworkService)24 Server (com.att.cdp.zones.model.Server)22 ComputeService (com.att.cdp.zones.ComputeService)21 Network (com.att.cdp.zones.model.Network)19 OpenStackServer (com.att.cdp.openstack.model.OpenStackServer)18 OpenStackSnapshot (com.att.cdp.openstack.model.OpenStackSnapshot)18 Subnet (com.att.cdp.zones.model.Subnet)15 Port (com.att.cdp.zones.model.Port)14 Snapshot (com.att.cdp.zones.model.Snapshot)12 Volume (com.att.cdp.zones.model.Volume)11 OpenStackResponseException (com.woorea.openstack.base.client.OpenStackResponseException)11 ResourceNotFoundException (com.att.cdp.exceptions.ResourceNotFoundException)10