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");
}
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");
}
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;
}
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;
}
}
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;
}
Aggregations