use of com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException 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 com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException 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 com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException 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 com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException 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);
}
}
use of com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException in project cloudbreak by hortonworks.
the class OpenStackNetworkResourceBuilder method build.
@Override
public CloudResource build(OpenStackContext context, AuthenticatedContext auth, Network network, Security security, CloudResource buildableResource) {
OSClient<?> osClient = createOSClient(auth);
try {
NeutronNetworkView neutronView = new NeutronNetworkView(network);
String networkId = neutronView.isExistingNetwork() ? neutronView.getCustomNetworkId() : context.getParameter(NETWORK_ID, String.class);
if (!neutronView.isExistingNetwork()) {
org.openstack4j.model.network.Network osNetwork = Builders.network().name(buildableResource.getName()).tenantId(context.getStringParameter(OpenStackConstants.TENANT_ID)).adminStateUp(true).build();
networkId = osClient.networking().network().create(osNetwork).getId();
}
context.putParameter(NETWORK_ID, networkId);
return createPersistedResource(buildableResource, networkId);
} catch (OS4JException ex) {
throw new OpenStackResourceException("Network creation failed", resourceType(), buildableResource.getName(), ex);
}
}
Aggregations