use of org.openstack4j.api.exceptions.OS4JException in project cloudbreak by hortonworks.
the class OpenStackInstanceBuilder method delete.
@Override
public CloudResource delete(OpenStackContext context, AuthenticatedContext auth, CloudResource resource) {
try {
OSClient<?> osClient = createOSClient(auth);
ActionResponse response = osClient.compute().servers().delete(resource.getReference());
return checkDeleteResponse(response, resourceType(), auth, resource, "Instance deletion failed");
} catch (OS4JException ex) {
throw new OpenStackResourceException("Instance deletion failed", resourceType(), resource.getName(), ex);
}
}
use of org.openstack4j.api.exceptions.OS4JException in project cloudbreak by hortonworks.
the class OpenStackPortBuilder method build.
@Override
public List<CloudResource> build(OpenStackContext context, long privateId, AuthenticatedContext auth, Group group, Image image, List<CloudResource> buildableResource, Map<String, String> tags) {
CloudResource resource = buildableResource.get(0);
try {
OSClient<?> osClient = createOSClient(auth);
Port port = Builders.port().tenantId(context.getStringParameter(OpenStackConstants.TENANT_ID)).networkId(context.getStringParameter(OpenStackConstants.NETWORK_ID)).fixedIp(null, context.getStringParameter(OpenStackConstants.SUBNET_ID)).securityGroup(context.getGroupResources(group.getName()).get(0).getReference()).build();
port = osClient.networking().port().create(port);
return Collections.singletonList(createPersistedResource(resource, group.getName(), port.getId(), Collections.singletonMap(OpenStackConstants.PORT_ID, port.getId())));
} catch (OS4JException ex) {
throw new OpenStackResourceException("Port creation failed", resourceType(), resource.getName(), ex);
}
}
use of org.openstack4j.api.exceptions.OS4JException in project cloudbreak by hortonworks.
the class OpenStackPortBuilder method delete.
@Override
public CloudResource delete(OpenStackContext context, AuthenticatedContext auth, CloudResource resource) {
try {
OSClient<?> osClient = createOSClient(auth);
ActionResponse response = osClient.networking().port().delete(resource.getReference());
return checkDeleteResponse(response, resourceType(), auth, resource, "Port deletion failed");
} catch (OS4JException ex) {
throw new OpenStackResourceException("Port deletion failed", resourceType(), resource.getName(), ex);
}
}
use of org.openstack4j.api.exceptions.OS4JException in project cloudbreak by hortonworks.
the class OpenStackSecurityGroupResourceBuilder method delete.
@Override
public CloudResource delete(OpenStackContext context, AuthenticatedContext auth, CloudResource resource, Network network) {
try {
OSClient<?> osClient = createOSClient(auth);
ActionResponse response = osClient.compute().securityGroups().delete(resource.getReference());
return checkDeleteResponse(response, resourceType(), auth, resource, "SecurityGroup deletion failed");
} catch (OS4JException ex) {
throw new OpenStackResourceException("SecurityGroup deletion failed", resourceType(), resource.getName(), ex);
}
}
use of org.openstack4j.api.exceptions.OS4JException in project cloudbreak by hortonworks.
the class OpenStackSecurityGroupResourceBuilder method build.
@Override
public CloudResource build(OpenStackContext context, AuthenticatedContext auth, Group group, Network network, Security security, CloudResource resource) {
try {
OSClient<?> osClient = createOSClient(auth);
ComputeSecurityGroupService securityGroupService = osClient.compute().securityGroups();
SecGroupExtension securityGroup = securityGroupService.create(resource.getName(), "");
String securityGroupId = securityGroup.getId();
for (SecurityRule rule : security.getRules()) {
IPProtocol osProtocol = getProtocol(rule.getProtocol());
String cidr = rule.getCidr();
for (PortDefinition portStr : rule.getPorts()) {
int from = Integer.parseInt(portStr.getFrom());
int to = Integer.parseInt(portStr.getTo());
securityGroupService.createRule(createRule(securityGroupId, osProtocol, cidr, from, to));
}
}
NeutronNetworkView neutronView = new NeutronNetworkView(network);
String subnetCidr = neutronView.isExistingSubnet() ? utils.getExistingSubnetCidr(auth, neutronView) : network.getSubnet().getCidr();
securityGroupService.createRule(createRule(securityGroupId, IPProtocol.TCP, subnetCidr, MIN_PORT, MAX_PORT));
securityGroupService.createRule(createRule(securityGroupId, IPProtocol.UDP, subnetCidr, MIN_PORT, MAX_PORT));
securityGroupService.createRule(createRule(securityGroupId, IPProtocol.ICMP, "0.0.0.0/0"));
return createPersistedResource(resource, group.getName(), securityGroup.getId());
} catch (OS4JException ex) {
throw new OpenStackResourceException("SecurityGroup creation failed", resourceType(), resource.getName(), ex);
}
}
Aggregations