use of com.woorea.openstack.base.client.OpenStackConnectException 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.OpenStackConnectException 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.OpenStackConnectException 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);
}
}
use of com.woorea.openstack.base.client.OpenStackConnectException 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;
}
use of com.woorea.openstack.base.client.OpenStackConnectException 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);
}
}
Aggregations