我正在尝试使用Apache JClouds向区域中的某些实例(已在运行中)添加/删除特定安全组。我知道这可以使用Nova-CLI完成。有人可以指出如何使用jclouds完成这项工作吗?文档并没有真正说出那么多。
答案 0 :(得分:1)
NovaApi novaApi = ContextBuilder
.newBuilder("openstack-nova")
.credentials("username", "api_key")
.buildApi(NovaApi.class);
Ingress ingress = Ingress.builder().fromPort(80).toPort(80).ipProtocol(IpProtocol.TCP).build();
SecurityGroupApi securityGroupApi = novaApi.getSecurityGroupExtensionForZone("RegionOne").get();
SecurityGroup securityGroup = securityGroupApi.createWithDescription("name", "description");
SecurityGroupRule rule = securityGroupApi.createRuleAllowingCidrBlock(securityGroup.getName(), ingress, "0.0.0.0/0");
securityGroupApi.delete(securityGroup.getId());