use of com.att.cdp.zones.Context in project AJSC by att.
the class OpenStackStackService 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 {
checkLogin();
checkOpen();
Context context = getContext();
OpenStackContext osContext = (OpenStackContext) context;
connector = osContext.getHeatConnector();
((OpenStackContext) context).refreshIfStale(connector);
}
use of com.att.cdp.zones.Context in project AJSC by att.
the class OpenStackVolumeService method getVolumes.
/**
* Returns a list of volumes that match the supplied name
*
* @param name
* The name pattern of the volumes to be located. The name is a regular expression that is suitable for
* use in the Java String.matches() method.
* @return A list (potentially empty) of all volumes that match the specified name pattern
* @throws ZoneException
* - If the volume service cannot be accessed.
* @see java.lang.String#matches(String)
* @see com.att.cdp.zones.VolumeService#getVolumes(java.lang.String)
*/
@Override
public List<Volume> getVolumes(String name) throws ZoneException {
connect();
Context context = getContext();
trackRequest();
RequestState.put(RequestState.VOLUME, name);
RequestState.put(RequestState.SERVICE, "Compute");
RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
ArrayList<Volume> list = new ArrayList<>();
try {
com.woorea.openstack.nova.model.Volumes volumes = nova.getClient().volumes().list(true).execute();
for (com.woorea.openstack.nova.model.Volume volume : volumes) {
if (name != null) {
if (volume.getName() != null && volume.getName().matches(name)) {
list.add(new OpenStackVolume(context, volume));
}
} else {
list.add(new OpenStackVolume(context, volume));
}
}
} catch (OpenStackBaseException ex) {
ExceptionMapper.mapException(ex);
}
return list;
}
use of com.att.cdp.zones.Context in project AJSC by att.
the class OpenStackVolumeService method createVolume.
/**
* This method is used to create a new volume using the Volume object (disconnected) as the model. When the method
* returns, a connected model object is returned that should be used for any model navigation desired.
*
* @param template
* The template of the volume to create. This must contain at least a name and size. Other information
* will be supplied if not present. Any ID is ignored, and the ID of the created volume is returned in
* the connected volume object returned to the caller.
* @return A Volume object that is connected to the service context and can be used to navigate the model.
* @throws ZoneException
* - If the volume cannot be created for some reason.
* @see com.att.cdp.zones.VolumeService#createVolume(com.att.cdp.zones.model.Volume)
*/
@SuppressWarnings("nls")
@Override
public Volume createVolume(Volume template) throws ZoneException {
checkArg(template, "template");
connect();
Context context = getContext();
trackRequest();
RequestState.put(RequestState.VOLUME, template.getName());
RequestState.put(RequestState.SIZE, template.getSize());
RequestState.put(RequestState.SERVICE, "Compute");
RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
try {
com.woorea.openstack.nova.model.VolumeForCreate newVolume = new com.woorea.openstack.nova.model.VolumeForCreate();
HashMap<String, String> dictionary = new HashMap<>();
dictionary.put("name", "name");
dictionary.put("description", "description");
dictionary.put("size", "size");
dictionary.put("snapshotId", "snapshotId");
dictionary.put("availabilityZone", "availabilityZone");
ObjectMapper.map(template, newVolume, dictionary);
OpenStackVolume volume = new OpenStackVolume(context, nova.getClient().volumes().create(newVolume).execute());
return volume;
} catch (OpenStackBaseException ex) {
ExceptionMapper.mapException(ex);
}
// for the compiler
return null;
}
use of com.att.cdp.zones.Context in project AJSC by att.
the class OpenStackVolumeService method getVolume.
/**
* Returns information about the volume with the indicated id, if it exists.
*
* @param id
* The id of the volume that we want to find information about
* @return The volume if it exists
* @throws ZoneException
* - If the volume cannot be listed, or the volume does not exist
* @see com.att.cdp.zones.VolumeService#getVolume(java.lang.String)
*/
@SuppressWarnings("nls")
@Override
public Volume getVolume(String id) throws ZoneException {
checkArg(id, "id");
connect();
Context context = getContext();
trackRequest();
RequestState.put(RequestState.VOLUME, id);
RequestState.put(RequestState.SERVICE, "Compute");
RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
try {
com.woorea.openstack.nova.model.Volume volume = nova.getClient().volumes().show(id).execute();
if (volume == null) {
throw new ResourceNotFoundException(EELFResourceManager.format(OSMsg.PAL_OS_RESOURCE_NOT_FOUND, "Volume", id, context.getProvider().getName()));
}
return new OpenStackVolume(context, volume);
} catch (OpenStackBaseException ex) {
ExceptionMapper.mapException(ex);
}
// for the compiler
return null;
}
use of com.att.cdp.zones.Context in project AJSC by att.
the class OpenStackVolumeService method destroySnapshot.
/**
* This method can be called to destroy a snapshot.
*
* @param id
* The id of the snapshot to be destroyed.
* @throws ZoneException
* - If the snapshot cannot be destroyed.
* @see com.att.cdp.zones.VolumeService#destroySnapshot(java.lang.String)
*/
@SuppressWarnings("nls")
@Override
public void destroySnapshot(String id) throws ZoneException {
checkArg(id, "id");
connect();
Context context = getContext();
trackRequest();
RequestState.put(RequestState.SNAPSHOT, id);
RequestState.put(RequestState.SERVICE, "Compute");
RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
try {
nova.getClient().snapshots().delete(id).execute();
} catch (OpenStackBaseException ex) {
ExceptionMapper.mapException(ex);
}
}
Aggregations