Search in sources :

Example 66 with OpenStackBaseException

use of com.woorea.openstack.base.client.OpenStackBaseException in project AJSC by att.

the class OpenStackVolumeService method createSnapshot.

/**
 * This method is used to create a new snapshot using the Snapshot 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 snapshot to create. This must contain at least a name and volumeId. Other
 *            information will be supplied if not present. Any ID is ignored, and the ID of the created snapshot is
 *            returned in the connected snapshot object returned to the caller.
 * @return A Snapshot object that is connected to the service context and can be used to navigate the model.
 * @throws ZoneException
 *             - If the snapshot cannot be created for some reason.
 * @see com.att.cdp.zones.VolumeService#createSnapshot(com.att.cdp.zones.model.Snapshot)
 */
@SuppressWarnings("nls")
@Override
public Snapshot createSnapshot(Snapshot template) throws ZoneException {
    checkArg(template, "template");
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.SNAPSHOT, template.getName());
    RequestState.put(RequestState.VOLUME, template.getVolumeId());
    RequestState.put(RequestState.SERVICE, "Volume");
    RequestState.put(RequestState.SERVICE_URL, cinder.getEndpoint());
    try {
        com.woorea.openstack.cinder.model.SnapshotForCreate newSnapshot = new com.woorea.openstack.cinder.model.SnapshotForCreate();
        HashMap<String, String> dictionary = new HashMap<>();
        dictionary.put("name", "name");
        dictionary.put("description", "description");
        dictionary.put("size", "size");
        dictionary.put("volumeId", "volumeId");
        ObjectMapper.map(template, newSnapshot, dictionary);
        OpenStackSnapshot snapshot = new OpenStackSnapshot(context, cinder.getClient().snapshots().create(newSnapshot).execute());
        return snapshot;
    } 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) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) OpenStackSnapshot(com.att.cdp.openstack.model.OpenStackSnapshot)

Example 67 with OpenStackBaseException

use of com.woorea.openstack.base.client.OpenStackBaseException in project AJSC by att.

the class OpenStackStackService method createNativeStack.

/**
 * This method is used to request a stack construction using whatever the native capabilities of the provider are.
 * The caller of this method must know the inherent capabilities of the underlying provider they are using in order
 * to use this method. Also, using this method partially violates and nullifies the benefits of the abstraction. The
 * return value from this method will still be the <code>Stack</code> object that is represented in the abstraction.
 *
 * @throws ZoneException
 *             If there is a problem making the request
 * @see com.att.cdp.zones.StackService#createNativeStack(java.lang.String, java.lang.String)
 */
@Override
public Stack createNativeStack(String stackName, String content) throws ZoneException {
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.SERVICE, "Orchestration");
    RequestState.put(RequestState.SERVICE_URL, connector.getEndpoint());
    Heat heat = connector.getClient();
    StackResource resource = heat.getStacks();
    CreateStackParam model = new CreateStackParam();
    model.setTimeoutMinutes(5);
    model.setStackName(stackName);
    model.setTemplate(content);
    OpenStackStack stack = null;
    try {
        com.woorea.openstack.heat.model.Stack osStack = resource.create(model).execute();
        if (osStack != null) {
            stack = (OpenStackStack) getStack(stackName, osStack.getId());
        // stack = new OpenStackStack(context, osStack);
        // stack.setName(stackName);
        }
    } catch (OpenStackBaseException e) {
        ExceptionMapper.mapException(e);
    }
    return stack;
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) OpenStackStack(com.att.cdp.openstack.model.OpenStackStack) Heat(com.woorea.openstack.heat.Heat) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) CreateStackParam(com.woorea.openstack.heat.model.CreateStackParam) StackResource(com.woorea.openstack.heat.StackResource)

Example 68 with OpenStackBaseException

use of com.woorea.openstack.base.client.OpenStackBaseException in project AJSC by att.

the class OpenStackVolumeService method createSnapshot.

/**
 * This method is used to create a new snapshot using the Snapshot 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 snapshot to create. This must contain at least a name and volumeId. Other
 *            information will be supplied if not present. Any ID is ignored, and the ID of the created snapshot is
 *            returned in the connected snapshot object returned to the caller.
 * @return A Snapshot object that is connected to the service context and can be used to navigate the model.
 * @throws ZoneException
 *             - If the snapshot cannot be created for some reason.
 * @see com.att.cdp.zones.VolumeService#createSnapshot(com.att.cdp.zones.model.Snapshot)
 */
@SuppressWarnings("nls")
@Override
public Snapshot createSnapshot(Snapshot template) throws ZoneException {
    checkArg(template, "template");
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.SNAPSHOT, template.getName());
    RequestState.put(RequestState.VOLUME, template.getVolumeId());
    RequestState.put(RequestState.SERVICE, "Compute");
    RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
    try {
        com.woorea.openstack.nova.model.SnapshotForCreate newSnapshot = new com.woorea.openstack.nova.model.SnapshotForCreate();
        HashMap<String, String> dictionary = new HashMap<>();
        dictionary.put("name", "name");
        dictionary.put("description", "description");
        dictionary.put("size", "size");
        dictionary.put("volumeId", "volumeId");
        ObjectMapper.map(template, newSnapshot, dictionary);
        OpenStackSnapshot snapshot = new OpenStackSnapshot(context, nova.getClient().snapshots().create(newSnapshot).execute());
        return snapshot;
    } 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) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) OpenStackSnapshot(com.att.cdp.openstack.model.OpenStackSnapshot)

Example 69 with OpenStackBaseException

use of com.woorea.openstack.base.client.OpenStackBaseException in project AJSC by att.

the class OpenStackVolumeService method getVolumes.

/**
 * Retrieves the list of volumes defined for this service.
 *
 * @return The list of volumes for this tenant, if any. The list may be empty if there are no volumes defined.
 * @see com.att.cdp.zones.VolumeService#getVolumes()
 */
@Override
public List<Volume> getVolumes() throws ZoneException {
    connect();
    Context context = getContext();
    trackRequest();
    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) {
            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 70 with OpenStackBaseException

use of com.woorea.openstack.base.client.OpenStackBaseException in project AJSC by att.

the class OpenStackVolumeService method destroyVolume.

/**
 * This method can be called to destroy a volume.
 *
 * @param id
 *            The id of the volume to be destroyed.
 * @throws ZoneException
 *             - If the volume cannot be destroyed.
 * @see com.att.cdp.zones.VolumeService#destroyVolume(java.lang.String)
 */
@SuppressWarnings("nls")
@Override
public void destroyVolume(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 {
        nova.getClient().volumes().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

OpenStackBaseException (com.woorea.openstack.base.client.OpenStackBaseException)151 OpenStackContext (com.att.cdp.openstack.OpenStackContext)140 Context (com.att.cdp.zones.Context)140 ArrayList (java.util.ArrayList)54 Quantum (com.woorea.openstack.quantum.Quantum)36 OpenStackSnapshot (com.att.cdp.openstack.model.OpenStackSnapshot)18 ZoneException (com.att.cdp.exceptions.ZoneException)15 OpenStackServer (com.att.cdp.openstack.model.OpenStackServer)14 Server (com.att.cdp.zones.model.Server)11 ConnectedServer (com.att.cdp.zones.spi.model.ConnectedServer)11 HashMap (java.util.HashMap)11 ResourceNotFoundException (com.att.cdp.exceptions.ResourceNotFoundException)10 Snapshot (com.att.cdp.zones.model.Snapshot)10 OpenStackACL (com.att.cdp.openstack.model.OpenStackACL)8 OpenStackImage (com.att.cdp.openstack.model.OpenStackImage)8 OpenStackPort (com.att.cdp.openstack.model.OpenStackPort)8 OpenStackVolume (com.att.cdp.openstack.model.OpenStackVolume)8 OpenStackNetwork (com.att.cdp.openstack.model.OpenStackNetwork)7 Network (com.att.cdp.zones.model.Network)7 Port (com.att.cdp.zones.model.Port)7