Search in sources :

Example 76 with OpenStackBaseException

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

the class OpenStackComputeService method deleteServer.

/**
 * Delete the specified server using it's id.
 *
 * @param serverId
 *            The server to be deleted.
 * @throws ZoneException
 *             If the server does not exist or cannot be deleted for some reason.
 * @see com.att.cdp.zones.ComputeService#deleteServer(java.lang.String)
 */
@SuppressWarnings("nls")
@Override
public void deleteServer(String serverId) throws ZoneException {
    checkArg(serverId, "serverId");
    connect();
    trackRequest();
    RequestState.put(RequestState.SERVER, serverId);
    RequestState.put(RequestState.SERVICE, "Compute");
    RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
    try {
        Server server = getServer(serverId);
        Server.Status status = server.getStatus();
        RequestState.put(RequestState.STATUS, status.toString());
        if (status.equals(Server.Status.RUNNING) || status.equals(Server.Status.READY) || status.equals(Server.Status.ERROR)) {
            List<Port> ports = server.getPorts();
            for (Port port : ports) {
                port.delete();
            }
            nova.getClient().servers().delete(serverId).execute();
        } else {
            throw new ZoneException(EELFResourceManager.format(OSMsg.PAL_OS_INVALID_SERVER_STATE, server.getName(), server.getId().toString(), status.toString(), StringHelper.asList(Arrays.asList(Server.Status.READY.toString(), Server.Status.RUNNING.toString(), Server.Status.ERROR.toString()))));
        }
    } catch (OpenStackBaseException ex) {
        ExceptionMapper.mapException(ex);
    }
}
Also used : Server(com.att.cdp.zones.model.Server) ConnectedServer(com.att.cdp.zones.spi.model.ConnectedServer) OpenStackServer(com.att.cdp.openstack.model.OpenStackServer) ZoneException(com.att.cdp.exceptions.ZoneException) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) Port(com.att.cdp.zones.model.Port) OpenStackPort(com.att.cdp.openstack.model.OpenStackPort)

Example 77 with OpenStackBaseException

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

the class OpenStackComputeService method getAttachments.

/**
 * Returns a map of the volume attachments for the specified server. The key of the map is the device name for the
 * volume attachment. This is the device identification which the server will "see".
 *
 * @param id
 *            The server ID for which we wish to obtain all attachments (if any).
 * @return A map of the volume attachments, or an empty map if there are none. The map is keyed by the device name
 *         used to attach the volume. The value of the entry is the ID of the volume attached at that device.
 * @throws ZoneException
 *             - If the attachments cannot be obtained
 * @see com.att.cdp.zones.ComputeService#getAttachments(java.lang.String)
 */
@SuppressWarnings("nls")
@Override
public Map<String, String> getAttachments(String id) throws ZoneException {
    checkArg(id, "id");
    connect();
    trackRequest();
    RequestState.put(RequestState.SERVER, id);
    RequestState.put(RequestState.SERVICE, "Compute");
    RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
    HashMap<String, String> map = new HashMap<>();
    try {
        for (VolumeAttachment attachment : nova.getClient().servers().listVolumeAttachments(id).execute()) {
            RequestState.put(RequestState.VOLUME, attachment.getVolumeId());
            if (attachment.getDevice() != null) {
                RequestState.put(RequestState.DEVICE, attachment.getDevice());
                map.put(attachment.getDevice(), attachment.getVolumeId());
            } else {
                System.err.println("No device found for " + attachment);
            }
        }
    } catch (OpenStackBaseException ex) {
        ExceptionMapper.mapException(ex);
    } catch (Exception e) {
        throw new ZoneException("Error obtaining volume attachments.", e);
    }
    return map;
}
Also used : VolumeAttachment(com.woorea.openstack.nova.model.VolumeAttachment) ZoneException(com.att.cdp.exceptions.ZoneException) HashMap(java.util.HashMap) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) InvalidRequestException(com.att.cdp.exceptions.InvalidRequestException) ResourceNotFoundException(com.att.cdp.exceptions.ResourceNotFoundException) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) ZoneException(com.att.cdp.exceptions.ZoneException) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) ContextClosedException(com.att.cdp.exceptions.ContextClosedException) NotLoggedInException(com.att.cdp.exceptions.NotLoggedInException)

Example 78 with OpenStackBaseException

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

the class OpenStackComputeService method getAccessControlList.

/**
 * @see com.att.cdp.zones.ComputeService#getAccessControlList(java.lang.String)
 */
@SuppressWarnings("nls")
@Override
public ACL getAccessControlList(String id) throws ZoneException {
    checkArg(id, "id");
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.SERVICE, "Compute");
    RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
    try {
        SecurityGroup group = nova.getClient().securityGroups().showSecurityGroup(id).execute();
        return new OpenStackACL(context, group);
    } catch (OpenStackBaseException ex) {
        ExceptionMapper.mapException(ex);
    }
    return null;
}
Also used : Context(com.att.cdp.zones.Context) OpenStackContext(com.att.cdp.openstack.OpenStackContext) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) SecurityGroup(com.woorea.openstack.nova.model.SecurityGroup) OpenStackACL(com.att.cdp.openstack.model.OpenStackACL)

Example 79 with OpenStackBaseException

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

the class OpenStackComputeService method getVirtualInterfaces.

/**
 * This method returns a list of OS Virtual Interfaces for a specified server instance.
 * <p>
 * This includes the ID for the virtual interface as well as the associated mac address.
 * </p>
 *
 * @return A list of virtual interfaces
 * @throws ZoneException
 *             If the virtual interfaces cannot be listed
 * @see com.att.cdp.zones.ComputeService#getVirtualInterfaces(java.lang.String)
 */
@SuppressWarnings("nls")
@Override
public List<VirtualInterface> getVirtualInterfaces(String id) throws ZoneException {
    checkArg(id, "id");
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.SERVICE, "Compute");
    RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
    ArrayList<VirtualInterface> list = new ArrayList<>();
    try {
        com.woorea.openstack.nova.model.VirtualInterfaces virtualInterfaces = nova.getClient().servers().listVirtualInterfaces(id).execute();
        for (com.woorea.openstack.nova.model.VirtualInterface vi : virtualInterfaces.getList()) {
            VirtualInterface virtualInterface = new OpenStackVirtualInterface(context, vi);
            list.add(virtualInterface);
        }
    } catch (OpenStackBaseException e) {
        ExceptionMapper.mapException(e);
    }
    return list;
}
Also used : Context(com.att.cdp.zones.Context) OpenStackContext(com.att.cdp.openstack.OpenStackContext) VirtualInterface(com.att.cdp.zones.model.VirtualInterface) OpenStackVirtualInterface(com.att.cdp.openstack.model.OpenStackVirtualInterface) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) ArrayList(java.util.ArrayList) OpenStackVirtualInterface(com.att.cdp.openstack.model.OpenStackVirtualInterface)

Example 80 with OpenStackBaseException

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

the class OpenStackComputeService method addACLRule.

/**
 * @see com.att.cdp.zones.ComputeService#addACLRule(java.lang.String, com.att.cdp.zones.model.Rule)
 */
@SuppressWarnings("nls")
@Override
public Rule addACLRule(String aclId, Rule rule) throws ZoneException {
    checkArg(aclId, "aclId");
    checkArg(rule, "rule");
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.SERVICE, "Compute");
    RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
    try {
        SecurityGroup group = nova.getClient().securityGroups().showSecurityGroup(aclId).execute();
        if (group != null) {
            com.woorea.openstack.nova.model.SecurityGroup.Rule createdRule = nova.getClient().securityGroups().createSecurityGroupRule(aclId, rule.getProtocol().toString(), rule.getFromPort(), rule.getToPort(), rule.getSourceIpRange()).execute();
            return new OpenStackRule(context, createdRule);
        }
    } catch (OpenStackBaseException ex) {
        ExceptionMapper.mapException(ex);
    }
    return null;
}
Also used : Context(com.att.cdp.zones.Context) OpenStackContext(com.att.cdp.openstack.OpenStackContext) OpenStackRule(com.att.cdp.openstack.model.OpenStackRule) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) SecurityGroup(com.woorea.openstack.nova.model.SecurityGroup)

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