Search in sources :

Example 21 with Context

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);
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) OpenStackContext(com.att.cdp.openstack.OpenStackContext)

Example 22 with Context

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;
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) Volume(com.att.cdp.zones.model.Volume) OpenStackVolume(com.att.cdp.openstack.model.OpenStackVolume) AbstractVolume(com.att.cdp.zones.spi.AbstractVolume) OpenStackVolume(com.att.cdp.openstack.model.OpenStackVolume) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) ArrayList(java.util.ArrayList)

Example 23 with Context

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;
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) HashMap(java.util.HashMap) OpenStackVolume(com.att.cdp.openstack.model.OpenStackVolume) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException)

Example 24 with Context

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;
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) OpenStackVolume(com.att.cdp.openstack.model.OpenStackVolume) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) ResourceNotFoundException(com.att.cdp.exceptions.ResourceNotFoundException)

Example 25 with Context

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);
    }
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException)

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