Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding update and delete port group #14

Merged
merged 1 commit into from
Apr 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified local-maven-repo/net/nuagenetworks/bambou/2.0.0/bambou-2.0.0.jar
Binary file not shown.
104 changes: 95 additions & 9 deletions local-maven-repo/net/nuagenetworks/bambou/2.0.0/bambou-2.0.0.pom
Original file line number Diff line number Diff line change
@@ -1,9 +1,95 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>net.nuagenetworks</groupId>
<artifactId>bambou</artifactId>
<version>2.0.0</version>
<description>POM was created from install:install-file</description>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we see here the library was installed from command-line. Later we may do install the jars into local-maven-repo using the 'mvn install:install-file..'

</project>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.nuagenetworks</groupId>
<artifactId>bambou</artifactId>
<version>2.0.0</version>
<packaging>jar</packaging>

<name>${project.groupId}:${project.artifactId}</name>
<description>Bambou is a Java ReST layer for Nuage Networks' APIs base concepts</description>
<url>http://github.com/nuagenetworks/java-bambou</url>

<licenses>
<license>
<name>Alcatel-Lucent Inc. License</name>
<url>http://github.com/nuagenetworks/java-bambou/blob/master/LICENSE</url>
<distribution>repo</distribution>
</license>
</licenses>

<developers>
<developer>
<name>Nuage Networks</name>
<email>[email protected]</email>
<organization>Nuage Networks</organization>
<organizationUrl>http://www.nuagenetworks.net</organizationUrl>
</developer>
</developers>

<scm>
<connection>scm:git:[email protected]:nuagenetworks/java-bambou.git</connection>
<developerConnection>scm:git:[email protected]:nuagenetworks/java-bambou.git</developerConnection>
<url>[email protected]:nuagenetworks/java-bambou.git</url>
</scm>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.18</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.7.2</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.2.5.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>3.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.18</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
import net.nuagenetworks.vspk.v4_0.VPort;
import net.nuagenetworks.vspk.v4_0.VPort.AddressSpoofing;
import net.nuagenetworks.vspk.v4_0.fetchers.DomainsFetcher;
import net.nuagenetworks.vspk.v4_0.fetchers.IngressAdvFwdEntryTemplatesFetcher;
import net.nuagenetworks.vspk.v4_0.fetchers.IngressAdvFwdTemplatesFetcher;
import net.nuagenetworks.vspk.v4_0.fetchers.PolicyGroupsFetcher;
import net.nuagenetworks.vspk.v4_0.fetchers.RedirectionTargetsFetcher;
import net.nuagenetworks.vspk.v4_0.fetchers.VPortsFetcher;

Expand Down Expand Up @@ -86,25 +86,53 @@ public NetworkElement createPolicyGroup(List<NetworkElement> elements, String do
return portGroup;
}

private void addPolicyGroupPorts(Domain selectDomain, PolicyGroup pg, List<NetworkElement> elements) throws RestException{
List<VPort> vports =new ArrayList<>();
for (NetworkElement element: elements){
List<VPort> temp =new ArrayList<>();
//protected VM OS ID
String filter = String.format("name like '%s'", element.getElementId());
VPortsFetcher vportFet = selectDomain.getVPorts();
temp = vportFet.fetch(filter, null, null, null, null, null, Boolean.FALSE);
if (!CollectionUtils.isEmpty(temp)) {
vports.add(temp.get(0));
}
}

pg.assign(vports);
}

public NetworkElement updatePolicyGroup(NetworkElement policyGroup, List<NetworkElement> protectedPorts,
String domainId) throws RestException{

OSCVSDSession session = this.nuageRestApi.getVsdSession();
session.start();
Me me = session.getMe();
Enterprise enterprise = me.getEnterprises().getFirst();

PolicyGroup polGrp = null;
try {
polGrp = new PolicyGroup();
polGrp.setId(policyGroup.getElementId());
polGrp.fetch();
} catch (Exception e) {
polGrp = null;
}
if (polGrp == null){
return createPolicyGroup(protectedPorts, domainId);
} else {
//handle Security Group update add/remove workload VMs
return null;
Domain selectDomain = null;
DomainsFetcher fetcher = new DomainsFetcher(enterprise);
String filter = String.format("name like '%s'", domainId);
List<Domain> dms = fetcher.fetch(filter, null, null, null, null, null, Boolean.FALSE);
if (!CollectionUtils.isEmpty(dms)) {
selectDomain = dms.get(0);
PolicyGroup polGrp = null;
try {
polGrp = new PolicyGroup();
polGrp.setId(policyGroup.getElementId());
polGrp.fetch();
} catch (Exception e) {
polGrp = null;
}
if (polGrp == null){
return createPolicyGroup(protectedPorts, domainId);
} else {
addPolicyGroupPorts(selectDomain, polGrp, protectedPorts);
return policyGroup;
}
}

return null;
}

public void deletePolicyGroup(NetworkElement policyGroup) throws RestException {
Expand All @@ -121,40 +149,19 @@ public void deletePolicyGroup(NetworkElement policyGroup) throws RestException {
this.log.debug(format);
return;
}
//get FWD policy for pg and delete it after deleting pg

String selectDomainId = pg.getParentId();
Domain selectDomain = new Domain();
selectDomain.setId(selectDomainId);
selectDomain.fetch();

List<IngressAdvFwdTemplate> fwdPolicies = new ArrayList<>();
IngressAdvFwdTemplatesFetcher advFwdFetcher = selectDomain.getIngressAdvFwdTemplates();
List<IngressAdvFwdTemplate> list = advFwdFetcher.fetch();
String filter = String.format("networkID like '%s' or locationID like '%s'", pg.getId(), pg.getId());
for (IngressAdvFwdTemplate fwdPolicy : list){
IngressAdvFwdEntryTemplatesFetcher entryFetcher = fwdPolicy.getIngressAdvFwdEntryTemplates();
List<IngressAdvFwdEntryTemplate> entries = entryFetcher.fetch(filter, null, null, null, null, null, false);
if (!entries.isEmpty()){
fwdPolicies.add(fwdPolicy);
}
}
for (IngressAdvFwdTemplate fwdPolicy : fwdPolicies){
fwdPolicy.delete();
}
//unassign all VPorts
VPortsFetcher vpFetcher = pg.getVPorts();
for (VPort vport : vpFetcher.fetch()){
PolicyGroup removeThis = null;
for (PolicyGroup pgFor : vport.getPolicyGroups().fetch()){
if (pgFor.getId().equals(pg.getId())){
removeThis = pgFor;
break;
}
PolicyGroupsFetcher pgsFetcher = selectDomain.getPolicyGroups();
List<PolicyGroup> pgs = pgsFetcher.get();
for (PolicyGroup pg2 : pgs) {
if (pg2.getId().equals(policyGroup.getElementId())) {
pg2.assign(new ArrayList<VPort>(), VPort.class);
pg2.delete();
}
vport.getPolicyGroups().remove(removeThis);
vport.assign(vport.getPolicyGroups());
}
pg.delete();
}

private IngressAdvFwdTemplate getForwardingPolicy(Domain selectDomain, PolicyGroup polGrp) throws RestException {
Expand Down