Search in sources :

Example 6 with OpenStackResponseException

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

the class AbstractOpenStackIdentityService method createKeyPair.

/**
 * @see com.att.cdp.zones.IdentityService#createKeyPair(com.att.cdp.zones.model.KeyPair)
 */
@SuppressWarnings("nls")
@Override
public KeyPair createKeyPair(KeyPair keyPair) throws ZoneException {
    trackRequest();
    RequestState.put(RequestState.KEYPAIR, keyPair.getName());
    Context context = getContext();
    if (context.isLoggedIn()) {
        NovaConnector connector = ((OpenStackContext) context).getNovaConnector();
        com.woorea.openstack.nova.model.KeyPair pair;
        try {
            pair = connector.getClient().keyPairs().create(keyPair.getName()).execute();
        } catch (OpenStackConnectException e) {
            throw new ContextConnectionException(EELFResourceManager.format(OSMsg.PAL_OS_CONNECTION_FAILED, "Compute", connector.getEndpoint()), e);
        } catch (OpenStackResponseException e) {
            String reason = null;
            if (e.getResponse() != null && e.getResponse().getInputStream() != null) {
                try {
                    reason = IOUtils.toString(e.getResponse().getInputStream(), "UTF-8");
                } catch (IOException e1) {
                }
                throw new ZoneException(EELFResourceManager.format(OSMsg.PAL_OS_REQUEST_FAILURE, "create key-pair " + keyPair.getName() + " " + reason), e);
            }
            throw new ZoneException(EELFResourceManager.format(OSMsg.PAL_OS_REQUEST_FAILURE, "create key-pair " + keyPair.getName()), e);
        }
        return new OpenStackKeyPair(context, pair);
    }
    throw new ZoneException("Unable to create 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) IOException(java.io.IOException) 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)

Example 7 with OpenStackResponseException

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

the class AbstractOpenStackIdentityService method deleteKeyPair.

/**
 * @see com.att.cdp.zones.IdentityService#deleteKeyPair(com.att.cdp.zones.model.KeyPair)
 */
@SuppressWarnings("nls")
@Override
public void deleteKeyPair(KeyPair keyPair) throws ZoneException {
    trackRequest();
    RequestState.put(RequestState.KEYPAIR, keyPair.getName());
    Context context = getContext();
    if (context.isLoggedIn()) {
        NovaConnector connector = ((OpenStackContext) context).getNovaConnector();
        try {
            connector.getClient().keyPairs().delete(keyPair.getName()).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, "delete key-pair " + keyPair.getName()), e);
        }
        return;
    }
    throw new ZoneException("Unable to delete 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) 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) NovaConnector(com.att.cdp.openstack.connectors.NovaConnector) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException)

Example 8 with OpenStackResponseException

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

the class AbstractOpenStackIdentityService method getRoles.

/**
 * @see com.att.cdp.zones.IdentityService#getRoles()
 */
@SuppressWarnings("nls")
@Override
public List<String> getRoles() throws ZoneException {
    trackRequest();
    Context context = getContext();
    ArrayList<String> list = new ArrayList<>();
    if (context.isLoggedIn()) {
        try {
            keystoneUrl = context.getProperties().getProperty(ContextFactory.PROPERTY_IDENTITY_URL);
            // tenantName = context.getProperties().getProperty(ContextFactory.PROPERTY_TENANT);
            Keystone keystone = new Keystone(keystoneUrl);
            OpenStackRequest<Roles> request = new OpenStackRequest<>(keystone, HttpMethod.GET, "/users/" + context.getPrincipal() + "/roles", null, Roles.class);
            Roles roles;
            try {
                roles = keystone.execute(request);
            } catch (OpenStackConnectException e) {
                throw new ContextConnectionException(EELFResourceManager.format(OSMsg.PAL_OS_CONNECTION_FAILED, "Identity", keystoneUrl), e);
            }
            for (Role role : roles.getList()) {
                list.add(role.getName());
            }
        } catch (OpenStackResponseException e) {
            if (e.getStatus() == 404) {
                throw new ResourceNotFoundException("Attempt to get roles for user " + context.getPrincipal(), e);
            }
            throw new ZoneException("Attempt to get roles for user " + context.getPrincipal(), e);
        }
    }
    return list;
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) ArrayList(java.util.ArrayList) OpenStackRequest(com.woorea.openstack.base.client.OpenStackRequest) Roles(com.woorea.openstack.keystone.model.Roles) Role(com.woorea.openstack.keystone.model.Role) 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) ResourceNotFoundException(com.att.cdp.exceptions.ResourceNotFoundException) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException)

Example 9 with OpenStackResponseException

use of com.woorea.openstack.base.client.OpenStackResponseException in project ovirt-engine by oVirt.

the class CinderBroker method updateConnectionInfoForDisk.

public void updateConnectionInfoForDisk(CinderDisk cinderDisk) {
    try {
        CinderConnectionInfo connectionInfo = initializeConnectionForDisk(cinderDisk);
        CinderVolumeDriver cinderVolumeDriver = CinderVolumeDriver.forValue(connectionInfo.getDriverVolumeType());
        if (cinderVolumeDriver == null) {
            logDiskEvent(cinderDisk, AuditLogType.CINDER_DISK_CONNECTION_VOLUME_DRIVER_UNSUPPORTED);
        }
        cinderDisk.setCinderConnectionInfo(connectionInfo);
    } catch (OpenStackResponseException ex) {
        logDiskEvent(cinderDisk, AuditLogType.CINDER_DISK_CONNECTION_FAILURE);
        throw ex;
    }
}
Also used : CinderConnectionInfo(org.ovirt.engine.core.common.businessentities.storage.CinderConnectionInfo) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) CinderVolumeDriver(org.ovirt.engine.core.common.businessentities.storage.CinderVolumeDriver)

Example 10 with OpenStackResponseException

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

the class OpenStackComputeService method getExtensions.

/**
 * Returns the set of extensions loaded, if any
 *
 * @return The list of extensions installed, if any
 * @throws ZoneException
 *             If anything fails
 */
public List<String> getExtensions() throws ZoneException {
    connect();
    trackRequest();
    RequestState.put(RequestState.SERVICE, "Compute");
    RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
    ArrayList<String> extensions = new ArrayList<>();
    try {
        for (Extension extension : nova.getClient().extensions().list(true).execute()) {
            extensions.add(extension.getName());
        }
    } catch (OpenStackBaseException ex) {
        if (ex instanceof OpenStackResponseException) {
            OpenStackResponseException osre = (OpenStackResponseException) ex;
            if (osre.getStatus() != 404) {
                ExceptionMapper.mapException(ex);
            }
        } else {
            ExceptionMapper.mapException(ex);
        }
    }
    return extensions;
}
Also used : Extension(com.woorea.openstack.nova.model.Extension) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) ArrayList(java.util.ArrayList)

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