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);
}
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;
}
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);
}
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;
}
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;
}
Aggregations