Search in sources :

Example 11 with OpenStackResponseException

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

the class OpenStackComputeService method attachPort.

/**
 * @see com.att.cdp.zones.ComputeService#attachPort(com.att.cdp.zones.model.Server, com.att.cdp.zones.model.Port)
 */
@Override
public void attachPort(Server server, Port port) throws ZoneException {
    checkArg(server, "server");
    checkArg(port, "port");
    connect();
    trackRequest();
    RequestState.put(RequestState.PORT, port.getId());
    RequestState.put(RequestState.SERVER, server.getId());
    RequestState.put(RequestState.SERVICE, "Compute");
    RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
    InterfaceAttachmentForCreate iafc = new InterfaceAttachmentForCreate();
    iafc.setPortId(port.getId());
    try {
        nova.getClient().servers().createInterfaceAttachment(server.getId(), iafc).execute();
    } catch (OpenStackConnectException | OpenStackResponseException e) {
        ExceptionMapper.mapException(e);
    }
}
Also used : OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) InterfaceAttachmentForCreate(com.woorea.openstack.nova.model.InterfaceAttachmentForCreate) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException)

Example 12 with OpenStackResponseException

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

the class OpenStackComputeService method getPorts.

/**
 * Gets the ports connected to a specific server
 *
 * @throws ZoneException
 *             If the server is null or invalid, if the context is closed, or if the context has not been
 *             authenticated, or if the authentication has expired
 * @see com.att.cdp.zones.ComputeService#getPorts(com.att.cdp.zones.model.Server)
 */
@Override
public List<Port> getPorts(Server server) throws ZoneException {
    checkArg(server, "server");
    connect();
    trackRequest();
    RequestState.put(RequestState.SERVER, server.getId());
    RequestState.put(RequestState.SERVICE, "Compute");
    RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
    List<Port> list = new ArrayList<>();
    try {
        InterfaceAttachments attachments = nova.getClient().servers().listInterfaceAttachments(server.getId()).execute();
        for (InterfaceAttachment attachment : attachments.getList()) {
            OpenStackPort port = new OpenStackPort(getContext(), attachment);
            list.add(port);
        }
    } catch (OpenStackConnectException | OpenStackResponseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return list;
}
Also used : OpenStackPort(com.att.cdp.openstack.model.OpenStackPort) InterfaceAttachments(com.woorea.openstack.nova.model.InterfaceAttachments) InterfaceAttachment(com.woorea.openstack.nova.model.InterfaceAttachment) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) Port(com.att.cdp.zones.model.Port) OpenStackPort(com.att.cdp.openstack.model.OpenStackPort) ArrayList(java.util.ArrayList) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException)

Example 13 with OpenStackResponseException

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

the class OpenStackComputeService method attachPort.

/**
 * @see com.att.cdp.zones.ComputeService#attachPort(com.att.cdp.zones.model.Server,
 *      com.att.cdp.zones.model.Port)
 */
@Override
public void attachPort(Server server, Port port) throws ZoneException {
    checkArg(server, "server");
    checkArg(port, "port");
    connect();
    trackRequest();
    RequestState.put(RequestState.PORT, port.getId());
    RequestState.put(RequestState.SERVER, server.getId());
    RequestState.put(RequestState.SERVICE, "Compute");
    RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
    InterfaceAttachmentForCreate iafc = new InterfaceAttachmentForCreate();
    iafc.setPortId(port.getId());
    try {
        nova.getClient().servers().createInterfaceAttachment(server.getId(), iafc).execute();
    } catch (OpenStackConnectException | OpenStackResponseException e) {
        ExceptionMapper.mapException(e);
    }
}
Also used : OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) InterfaceAttachmentForCreate(com.woorea.openstack.nova.model.InterfaceAttachmentForCreate) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException)

Example 14 with OpenStackResponseException

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

the class AbstractOpenStackIdentityService method getTenant.

/**
 * All services must be able to return the tenant object that the user has connected to.
 *
 * @return The tenant object
 * @throws ZoneException
 *             If the user has not logged in
 * @see com.att.cdp.zones.Service#getTenant()
 */
@Override
public Tenant getTenant() throws ZoneException {
    checkLoggedIn();
    Context context = getContext();
    trackRequest();
    Keystone keystone = getKeystone();
    keystoneUrl = context.getProperties().getProperty(ContextFactory.PROPERTY_IDENTITY_URL);
    if (tenant == null) {
        com.woorea.openstack.keystone.model.Tenants tenants;
        try {
            tenants = keystone.tenants().list().execute();
        } catch (OpenStackConnectException e) {
            throw new ContextConnectionException(EELFResourceManager.format(OSMsg.PAL_OS_CONNECTION_FAILED, "Identity", keystoneUrl), e);
        } catch (OpenStackResponseException e) {
            throw new ZoneException(EELFResourceManager.format(OSMsg.PAL_OS_REQUEST_FAILURE, "get tenant " + tenantName), e);
        }
        for (com.woorea.openstack.keystone.model.Tenant t : tenants) {
            if (t.getName().equals(tenantName)) {
                tenant = new OpenStackTenant((OpenStackContext) context, t);
                break;
            }
        }
    }
    return tenant;
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) OpenStackTenant(com.att.cdp.openstack.model.OpenStackTenant) OpenStackContext(com.att.cdp.openstack.OpenStackContext) ContextConnectionException(com.att.cdp.exceptions.ContextConnectionException) Keystone(com.woorea.openstack.keystone.Keystone) ZoneException(com.att.cdp.exceptions.ZoneException) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) Tenants(com.woorea.openstack.keystone.model.Tenants) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException)

Example 15 with OpenStackResponseException

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

the class AbstractOpenStackIdentityService method getKeyPairs.

/**
 * @see com.att.cdp.zones.IdentityService#getKeyPairs()
 */
@SuppressWarnings("nls")
@Override
public List<KeyPair> getKeyPairs() throws ZoneException {
    trackRequest();
    Context context = getContext();
    if (context.isLoggedIn()) {
        NovaConnector connector = ((OpenStackContext) context).getNovaConnector();
        KeyPairs pairs = null;
        try {
            pairs = connector.getClient().keyPairs().list().execute();
        } catch (OpenStackConnectException e) {
            throw new ContextConnectionException(EELFResourceManager.format(OSMsg.PAL_OS_CONNECTION_FAILED, "Compute", connector.getEndpoint()), e);
        } catch (OpenStackResponseException e) {
            throw new ZoneException(EELFResourceManager.format(OSMsg.PAL_OS_REQUEST_FAILURE, "get key-pair list"), e);
        }
        ArrayList<KeyPair> list = new ArrayList<>();
        for (com.woorea.openstack.nova.model.KeyPair pair : pairs.getList()) {
            OpenStackKeyPair kp = new OpenStackKeyPair(context, pair);
            list.add(kp);
        }
        return list;
    }
    throw new ZoneException("Unable to retrieve key-pairs when the context has not been logged in and authenticated");
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) KeyPair(com.att.cdp.zones.model.KeyPair) OpenStackKeyPair(com.att.cdp.openstack.model.OpenStackKeyPair) KeyPairs(com.woorea.openstack.nova.model.KeyPairs) ArrayList(java.util.ArrayList) OpenStackContext(com.att.cdp.openstack.OpenStackContext) ContextConnectionException(com.att.cdp.exceptions.ContextConnectionException) ZoneException(com.att.cdp.exceptions.ZoneException) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) OpenStackKeyPair(com.att.cdp.openstack.model.OpenStackKeyPair) NovaConnector(com.att.cdp.openstack.connectors.NovaConnector) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException)

Aggregations

OpenStackResponseException (com.woorea.openstack.base.client.OpenStackResponseException)15 OpenStackConnectException (com.woorea.openstack.base.client.OpenStackConnectException)12 OpenStackContext (com.att.cdp.openstack.OpenStackContext)9 ContextConnectionException (com.att.cdp.exceptions.ContextConnectionException)8 Context (com.att.cdp.zones.Context)8 ZoneException (com.att.cdp.exceptions.ZoneException)7 ArrayList (java.util.ArrayList)6 NovaConnector (com.att.cdp.openstack.connectors.NovaConnector)4 Keystone (com.woorea.openstack.keystone.Keystone)4 OpenStackKeyPair (com.att.cdp.openstack.model.OpenStackKeyPair)3 OpenStackTenant (com.att.cdp.openstack.model.OpenStackTenant)3 Tenants (com.woorea.openstack.keystone.model.Tenants)3 OpenStackPort (com.att.cdp.openstack.model.OpenStackPort)2 Port (com.att.cdp.zones.model.Port)2 OpenStackBaseException (com.woorea.openstack.base.client.OpenStackBaseException)2 Extension (com.woorea.openstack.nova.model.Extension)2 InterfaceAttachment (com.woorea.openstack.nova.model.InterfaceAttachment)2 InterfaceAttachmentForCreate (com.woorea.openstack.nova.model.InterfaceAttachmentForCreate)2 InterfaceAttachments (com.woorea.openstack.nova.model.InterfaceAttachments)2 KeyPairs (com.woorea.openstack.nova.model.KeyPairs)2