本文整理汇总了Java中org.openstack4j.model.network.SecurityGroup类的典型用法代码示例。如果您正苦于以下问题:Java SecurityGroup类的具体用法?Java SecurityGroup怎么用?Java SecurityGroup使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SecurityGroup类属于org.openstack4j.model.network包,在下文中一共展示了SecurityGroup类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeTransaction
import org.openstack4j.model.network.SecurityGroup; //导入依赖的package包/类
@Override
public void executeTransaction(EntityManager em) throws Exception {
this.ds = em.find(DeploymentSpec.class, this.ds.getId());
try (Openstack4JNeutron neutron = new Openstack4JNeutron(this.osEndPoint)) {
this.log.info("Creating Openstack Security Group " + this.sgName + " in project " + this.ds.getProjectName()
+ " for region " + this.ds.getRegion());
SecurityGroup securityGroup = neutron.createSecurityGroup(this.sgName, this.ds.getRegion());
neutron.addSecurityGroupRules(securityGroup, this.ds.getRegion(), createSecurityGroupRules());
OsSecurityGroupReference sgRef = new OsSecurityGroupReference(securityGroup.getId(), this.sgName, this.ds);
this.ds.setOsSecurityGroupReference(sgRef);
OSCEntityManager.create(em, sgRef, this.txBroadcastUtil);
}
}
示例2: createSecurityGroup
import org.openstack4j.model.network.SecurityGroup; //导入依赖的package包/类
public SecurityGroup createSecurityGroup(String sgName, String region) throws Exception {
Optional<? extends SecurityGroup> securityGroupByName = getSecurityGroupByName(region, sgName);
SecurityGroup securityGroup;
if (securityGroupByName.isPresent()) {
securityGroup = securityGroupByName.get();
log.info("Found security group with name: " + sgName + "and using it");
} else {
log.info("Creating security group with name: " + sgName);
getOs().useRegion(region);
NeutronSecurityGroup.SecurityGroupConcreteBuilder securityGroupConcreteBuilder =
new NeutronSecurityGroup.SecurityGroupConcreteBuilder();
NetSecurityGroupBuilder securityGroupBuilder = securityGroupConcreteBuilder
.description("OSC default Openstack Security Group for virtual system " + sgName)
.name(sgName);
securityGroup = getOs().networking().securitygroup().create(securityGroupBuilder.build());
}
if (securityGroup == null) {
String message = String.format("Cannot create Security group with name: %s in region: %s.", sgName, region);
log.warn(message);
throw new ResponseException(message, 500);
}
return securityGroup;
}
示例3: addSecurityGroupRules
import org.openstack4j.model.network.SecurityGroup; //导入依赖的package包/类
public void addSecurityGroupRules(SecurityGroup sg, String region, Collection<SecurityGroupRule> rules) {
getOs().useRegion(region);
for (SecurityGroupRule rule : rules) {
try {
getOs().networking().securityrule().create(rule.toBuilder().securityGroupId(sg.getId()).build());
} catch (ResponseException re) {
if (re instanceof ClientResponseException
&& ((ClientResponseException) re).getStatusCode().getCode() == OPENSTACK_CONFLICT_STATUS) {
log.info(String.format("Rule: %s already exists for Security Group: %s ", rule, sg.getName()));
} else {
String message = String.format("Unable to create rule: %s for Security Group: %s ", rule,
sg.getName());
log.error(message, re);
throw new ResponseException(message, 500);
}
}
}
}
示例4: deleteAllSecurityGroupRules
import org.openstack4j.model.network.SecurityGroup; //导入依赖的package包/类
/**
* @author viborole
*/
public static void deleteAllSecurityGroupRules() throws Exception {
System.out.println("This won't delete the default security group.");
List<? extends SecurityGroup> secGroups = NeutronAPI.getAllSecurityGroups();
System.out.println("Total number of Security Group found "+secGroups.size());
for(SecurityGroup secGrp : secGroups){
if(!"default".equals(secGrp.getName())){
List<? extends SecurityGroupRule> secRules = NeutronAPI.getAllSecurityRules(secGrp.getId());
System.out.println("Total number of Security Rules for Security Group "+secGrp.getName() +" found "+secRules.size());
System.out.println("Deleting Security Group Rules..");
for(SecurityGroupRule secGrpRule: secRules){
NeutronAPI.deleteSecurityRule(secGrpRule.getId());
}
System.out.println("Deleting Security Group..");
NeutronAPI.deleteSecurityGroup(secGrp.getId());
}
}
}
示例5: execute
import org.openstack4j.model.network.SecurityGroup; //导入依赖的package包/类
@Override
protected void execute() {
OpenstackSecurityGroupService service =
AbstractShellCommand.get(OpenstackSecurityGroupService.class);
List<SecurityGroup> sgs = Lists.newArrayList(service.securityGroups());
sgs.sort(Comparator.comparing(SecurityGroup::getId));
if (outputJson()) {
try {
print("%s", mapper().writeValueAsString(json(sgs)));
} catch (JsonProcessingException e) {
error("Failed to list security groups in JSON format");
}
return;
}
print("Hint: use --json option to see security group rules as well\n");
print(FORMAT, "ID", "Name");
for (SecurityGroup sg: service.securityGroups()) {
print(FORMAT, sg.getId(), sg.getName());
}
}
示例6: syncSGRules
import org.openstack4j.model.network.SecurityGroup; //导入依赖的package包/类
private void syncSGRules(SecurityGroup sg, Openstack4JNeutron neutron) throws Exception {
final List<? extends SecurityGroupRule> rules = sg.getRules();
List<SecurityGroupRule> expectedList = new ArrayList<>();
expectedList.add(Builders.securityGroupRule().protocol(null).ethertype(CreateOsSecurityGroupTask.IPV4)
.direction(CreateOsSecurityGroupTask.INGRESS).build());
expectedList.add(Builders.securityGroupRule().protocol(null).ethertype(CreateOsSecurityGroupTask.IPV4)
.direction(CreateOsSecurityGroupTask.EGRESS).build());
expectedList.add(Builders.securityGroupRule().protocol(null).ethertype(CreateOsSecurityGroupTask.IPV6)
.direction(CreateOsSecurityGroupTask.INGRESS).build());
expectedList.add(Builders.securityGroupRule().protocol(null).ethertype(CreateOsSecurityGroupTask.IPV6)
.direction(CreateOsSecurityGroupTask.EGRESS).build());
ImmutableList.<SecurityGroupRule>builder().addAll(expectedList);
// Filter the missing rules from the expected SG rules
Collection<SecurityGroupRule> missingRules = Collections2.filter(expectedList, expRule -> {
for (SecurityGroupRule osRule : rules) {
if (expRule != null && osRule.getDirection().equals(expRule.getDirection())
&& osRule.getEtherType().equals(expRule.getEtherType()) && osRule.getProtocol() == null) {
return false;
}
}
return true;
});
if (!missingRules.isEmpty()) {
neutron.addSecurityGroupRules(sg, this.ds.getRegion(), missingRules);
}
}
示例7: printSecurityGroup
import org.openstack4j.model.network.SecurityGroup; //导入依赖的package包/类
public static void printSecurityGroup(List<? extends SecurityGroup> secGrps){
TableBuilder tb = getTableBuilder("SecurityGroup");
for(SecurityGroup secGrp : secGrps){
addSecurityGroupRow(tb, secGrp);
}
System.out.println(tb.toString());
System.out.println("TOTAL RECORDS: "+tb.totalrecords());
}
示例8: createSecurityGroup
import org.openstack4j.model.network.SecurityGroup; //导入依赖的package包/类
@Override
public void createSecurityGroup(SecurityGroup sg) {
checkNotNull(sg, ERR_NULL_SG);
checkArgument(!Strings.isNullOrEmpty(sg.getId()), ERR_NULL_SG_ID);
osSecurityGroupStore.createSecurityGroup(sg);
log.info(String.format(MSG_SG, sg.getId(), MSG_CREATED));
}
示例9: updateSecurityGroup
import org.openstack4j.model.network.SecurityGroup; //导入依赖的package包/类
@Override
public void updateSecurityGroup(SecurityGroup sg) {
checkNotNull(sg, ERR_NULL_SG);
checkArgument(!Strings.isNullOrEmpty(sg.getId()), ERR_NULL_SG_ID);
osSecurityGroupStore.updateSecurityGroup(sg);
}
示例10: activate
import org.openstack4j.model.network.SecurityGroup; //导入依赖的package包/类
@Activate
protected void activate() {
ApplicationId appId = coreService.registerApplication(OPENSTACK_NETWORKING_APP_ID);
osSecurityGroupStore = storageService.<String, SecurityGroup>consistentMapBuilder()
.withSerializer(Serializer.using(SERIALIZER_SECURITY_GROUP))
.withName("openstack-securitygroupstore")
.withApplicationId(appId)
.build();
osSecurityGroupStore.addListener(securityGroupMapListener);
log.info("Started");
}
示例11: createSecurityGroup
import org.openstack4j.model.network.SecurityGroup; //导入依赖的package包/类
@Override
public void createSecurityGroup(SecurityGroup sg) {
osSecurityGroupStore.compute(sg.getId(), (id, existing) -> {
final String error = sg.getName() + ERR_DUPLICATE;
checkArgument(existing == null, error);
return sg;
});
}
示例12: updateSecurityGroup
import org.openstack4j.model.network.SecurityGroup; //导入依赖的package包/类
@Override
public void updateSecurityGroup(SecurityGroup sg) {
osSecurityGroupStore.compute(sg.getId(), (id, existing) -> {
final String error = sg.getName() + ERR_NOT_FOUND;
checkArgument(existing != null, error);
return sg;
});
}
示例13: securityGroups
import org.openstack4j.model.network.SecurityGroup; //导入依赖的package包/类
@Override
public Set<SecurityGroup> securityGroups() {
Set<SecurityGroup> osSgs = osSecurityGroupStore.values().stream()
.map(Versioned::value)
.collect(Collectors.toSet());
return ImmutableSet.copyOf(osSgs);
}
示例14: processUpdate
import org.openstack4j.model.network.SecurityGroup; //导入依赖的package包/类
private void processUpdate(SecurityGroup oldSg, SecurityGroup newSg) {
Set<String> oldSgRuleIds = oldSg.getRules().stream()
.map(SecurityGroupRule::getId).collect(Collectors.toSet());
Set<String> newSgRuleIds = newSg.getRules().stream()
.map(SecurityGroupRule::getId).collect(Collectors.toSet());
oldSg.getRules().stream().filter(sgRule -> !newSgRuleIds.contains(sgRule.getId()))
.forEach(sgRule -> notifyDelegate(new OpenstackSecurityGroupEvent(
OPENSTACK_SECURITY_GROUP_RULE_REMOVED, newSg, sgRule)
));
newSg.getRules().stream().filter(sgRule -> !oldSgRuleIds.contains(sgRule.getId()))
.forEach(sgRule -> notifyDelegate(new OpenstackSecurityGroupEvent(
OPENSTACK_SECURITY_GROUP_RULE_CREATED, newSg, sgRule)
));
}
示例15: setSecurityGroupRules
import org.openstack4j.model.network.SecurityGroup; //导入依赖的package包/类
private void setSecurityGroupRules(InstancePort instPort, Port port, boolean install) {
port.getSecurityGroups().forEach(sgId -> {
SecurityGroup sg = securityGroupService.securityGroup(sgId);
if (sg == null) {
log.error("Security Group Not Found : {}", sgId);
return;
}
sg.getRules().forEach(sgRule -> updateSecurityGroupRule(instPort, port, sgRule, install));
final String action = install ? "Installed " : "Removed ";
log.debug(action + "security group rule ID : " + sgId);
});
}