From 1fb43331f769d750dc0419fb3a91c4deb1b725ad Mon Sep 17 00:00:00 2001 From: Oleksander Gozman Date: Tue, 21 Nov 2017 13:31:36 +0100 Subject: [PATCH 01/10] imp: start networks rework 1. security groups attach to interfaces now# 2. added some exception catching 3. interface ordering 4. work-in-progress --- .../drivers/amazon/AmazonDriver.java | 340 +++++++++++------- 1 file changed, 201 insertions(+), 139 deletions(-) diff --git a/src/main/java/org/openbaton/drivers/amazon/AmazonDriver.java b/src/main/java/org/openbaton/drivers/amazon/AmazonDriver.java index 54b62a1..77d05d7 100644 --- a/src/main/java/org/openbaton/drivers/amazon/AmazonDriver.java +++ b/src/main/java/org/openbaton/drivers/amazon/AmazonDriver.java @@ -16,6 +16,8 @@ package org.openbaton.drivers.amazon; +import com.amazonaws.AmazonClientException; +import com.amazonaws.AmazonServiceException; import com.amazonaws.auth.AWSStaticCredentialsProvider; import com.amazonaws.auth.BasicAWSCredentials; import com.amazonaws.regions.Regions; @@ -56,6 +58,8 @@ public AmazonDriver() { public static void main(String[] args) throws NoSuchMethodException, IOException, InstantiationException, TimeoutException, IllegalAccessException, InvocationTargetException, InterruptedException { + + if (args.length == 4) { log.info("Starting the plugin with CUSTOM parameters: "); log.info("name: " + args[0]); @@ -114,6 +118,7 @@ private AmazonEC2 createClient(VimInstance vimInstance) throws VimDriverExceptio client = AmazonEC2ClientBuilder.standard() .withRegion(regions) + .withCredentials(new AWSStaticCredentialsProvider(awsCreds)) .build(); } catch (IllegalArgumentException e) { @@ -163,8 +168,9 @@ public Server launchInstance( log.info("Retrieved security ids"); int deviceIndex = 0; for (Network net : searchForRelevantSubnets(presentSubnets, newNetworks)) { - inters.add(createInterface(net, deviceIndex, newNetworks)); + inters.add(createInterface(net, deviceIndex, newNetworks, groupIds)); deviceIndex++; + log.info("Interface " + deviceIndex); } log.info("Created interfaces"); String amiID = imageExistsOnAWS(image, client); @@ -202,10 +208,10 @@ public Server launchInstance( tags.add(tag); CreateTagsRequest tagsRequest = new CreateTagsRequest().withTags(tags).withResources(id); client.createTags(tagsRequest); - ModifyInstanceAttributeRequest groupsReq = + /*ModifyInstanceAttributeRequest groupsReq = new ModifyInstanceAttributeRequest().withGroups(groupIds).withInstanceId(id); log.info("Assigning security groups to instance " + id); - ModifyInstanceAttributeResult groupRes = client.modifyInstanceAttribute(groupsReq); + ModifyInstanceAttributeResult groupRes = client.modifyInstanceAttribute(groupsReq);*/ List servers = listServer(vimInstance); for (Server ser : servers) { if (ser.getHostName().equals(name)) { @@ -220,11 +226,15 @@ public Server launchInstance( } catch (UnsupportedEncodingException e) { VimDriverException vimDriverException = new VimDriverException(e.getMessage()); throw vimDriverException; + } catch (AmazonClientException e) { + VimDriverException vimDriverException = new VimDriverException(e.getMessage()); + throw vimDriverException; } log.info("Instance " + name + " launched"); return server; } + /** * Checks if the image exists inside AWS and returns its ID * @@ -232,7 +242,7 @@ public Server launchInstance( * @param client AmazonEC2 client to make a request * @return id of the image or null if no image is there */ - private String imageExistsOnAWS(String nameId, AmazonEC2 client) { + private String imageExistsOnAWS(String nameId, AmazonEC2 client) throws AmazonClientException { Filter filter = new Filter(); filter.setName("name"); filter.setValues(Arrays.asList(nameId)); @@ -263,12 +273,12 @@ private String imageExistsOnAWS(String nameId, AmazonEC2 client) { * @return the list of interfaces */ private InstanceNetworkInterfaceSpecification createInterface( - Network net, int deviceIndex, Set cps) { + Network net, int deviceIndex, Set cps, Set secIDs) { InstanceNetworkInterfaceSpecification interSpec = new InstanceNetworkInterfaceSpecification() .withDeleteOnTermination(true) .withSubnetId(net.getExtId()) - .withDeviceIndex(deviceIndex); + .withDeviceIndex(deviceIndex).withGroups(secIDs); String floatingIp = ""; for (VNFDConnectionPoint cp : cps) { if (net.getName().equals(cp.getVirtual_link_reference())) { @@ -289,14 +299,32 @@ private InstanceNetworkInterfaceSpecification createInterface( * @return subnets the instance is connected to */ private List searchForRelevantSubnets(List nets, Set cps) { + log.info(nets.get(0).toString()); + log.info(nets.get(1).toString()); + ArrayList cpList = new ArrayList<>(cps); + Collections.sort(cpList, new Comparator() { + @Override + public int compare(VNFDConnectionPoint t, VNFDConnectionPoint t1) { + if (t.getInterfaceId() > t1.getInterfaceId()) { + return -1; + } if (t.getInterfaceId() == t1.getInterfaceId()) { + return 0; + } else { + return 1; + } + } + }); List relevantSubnets = new ArrayList<>(); - for (VNFDConnectionPoint cp : cps) { + for (VNFDConnectionPoint cp : cpList) { + log.info("loop1"); for (Network net : nets) { if (net.getName().equals(cp.getVirtual_link_reference())) { + log.info("loop2"); relevantSubnets.add(net); } } } + return relevantSubnets; } @@ -311,7 +339,7 @@ private List searchForRelevantSubnets(List nets, Set getSecurityIdFromName( - Set groupNames, AmazonEC2 client, VimInstance vimInstance) throws VimDriverException { + Set groupNames, AmazonEC2 client, VimInstance vimInstance) throws VimDriverException, AmazonClientException { String vpcId = getVpcsMap(vimInstance).get(vimInstance.getTenant()); if (vpcId == null) { throw new VimDriverException("No such VPC " + vimInstance.getTenant() + " exists"); @@ -343,66 +371,78 @@ private Set getSecurityIdFromName( @java.lang.Override public java.util.List listImages(VimInstance vimInstance) throws VimDriverException { - AmazonEC2 client = createClient(vimInstance); - String keyWord = properties.getProperty("image-key-word", "*"); - String keyWords[] = keyWord.split(","); - for (int i = 0; i < keyWords.length; i++) { - keyWords[i] = "*" + keyWords[i] + "*"; - } - Filter filter = new Filter(); - filter.setName("name"); - filter.setValues(Arrays.asList(keyWords)); - DescribeImagesRequest describeImagesRequest = new DescribeImagesRequest(); - describeImagesRequest.setFilters(Arrays.asList(filter)); - DescribeImagesResult describeImagesResult = client.describeImages(describeImagesRequest); - List images = new ArrayList<>(); - for (Image image : describeImagesResult.getImages()) { - images.add(Utils.getImage(image)); - } - filter.setName("image-id"); - filter.setValues(Arrays.asList(keyWords)); - describeImagesRequest = new DescribeImagesRequest(); - describeImagesRequest.setFilters(Arrays.asList(filter)); - describeImagesResult = client.describeImages(describeImagesRequest); - for (Image image : describeImagesResult.getImages()) { - images.add(Utils.getImage(image)); - } + try { + AmazonEC2 client = createClient(vimInstance); + String keyWord = properties.getProperty("image-key-word", "*"); + String keyWords[] = keyWord.split(","); + for (int i = 0; i < keyWords.length; i++) { + keyWords[i] = "*" + keyWords[i] + "*"; + } + Filter filter = new Filter(); + filter.setName("name"); + filter.setValues(Arrays.asList(keyWords)); + DescribeImagesRequest describeImagesRequest = new DescribeImagesRequest(); + describeImagesRequest.setFilters(Arrays.asList(filter)); + DescribeImagesResult describeImagesResult = client.describeImages(describeImagesRequest); + List images = new ArrayList<>(); + for (Image image : describeImagesResult.getImages()) { + images.add(Utils.getImage(image)); + } + filter.setName("image-id"); + filter.setValues(Arrays.asList(keyWords)); + describeImagesRequest = new DescribeImagesRequest(); + describeImagesRequest.setFilters(Arrays.asList(filter)); + describeImagesResult = client.describeImages(describeImagesRequest); + for (Image image : describeImagesResult.getImages()) { + images.add(Utils.getImage(image)); + } + + return images; + } catch (AmazonClientException e) { + VimDriverException vimDriverException = new VimDriverException(e.getMessage()); + throw vimDriverException; + } - return images; } @java.lang.Override public java.util.List listServer(VimInstance vimInstance) throws VimDriverException { - List servers = new ArrayList<>(); - AmazonEC2 client = createClient(vimInstance); - String vpcId = getVpcsMap(vimInstance).get(vimInstance.getTenant()); - if (vpcId == null) { - throw new VimDriverException("No such VPC " + vimInstance.getTenant() + " exists"); - } - Filter filter = new Filter(); - filter.setName("vpc-id"); - filter.setValues(Arrays.asList(vpcId)); - boolean done = false; - List nets = listNetworks(vimInstance); - while (!done) { - DescribeInstancesRequest request = new DescribeInstancesRequest(); - request.setFilters(Arrays.asList(filter)); - DescribeInstancesResult response = client.describeInstances(request); - for (Reservation reservation : response.getReservations()) { - for (Instance instance : reservation.getInstances()) { - servers.add(Utils.getServer(instance, nets)); - } - } - request.setNextToken(response.getNextToken()); - if (response.getNextToken() == null) { - done = true; + try { + List servers = new ArrayList<>(); + AmazonEC2 client = createClient(vimInstance); + String vpcId = getVpcsMap(vimInstance).get(vimInstance.getTenant()); + if (vpcId == null) { + throw new VimDriverException("No such VPC " + vimInstance.getTenant() + " exists"); + } + Filter filter = new Filter(); + filter.setName("vpc-id"); + filter.setValues(Arrays.asList(vpcId)); + boolean done = false; + List nets = listNetworks(vimInstance); + while (!done) { + DescribeInstancesRequest request = new DescribeInstancesRequest(); + request.setFilters(Arrays.asList(filter)); + DescribeInstancesResult response = client.describeInstances(request); + for (Reservation reservation : response.getReservations()) { + for (Instance instance : reservation.getInstances()) { + servers.add(Utils.getServer(instance, nets)); + } + } + request.setNextToken(response.getNextToken()); + if (response.getNextToken() == null) { + done = true; + } + } + return servers; + } catch (AmazonClientException e) { + VimDriverException vimDriverException = new VimDriverException(e.getMessage()); + throw vimDriverException; } - } - return servers; } @java.lang.Override public java.util.List listNetworks(VimInstance vimInstance) throws VimDriverException { + log.info("Listing networks"); List nfvoNetworks = new ArrayList<>(); AmazonEC2 client = createClient(vimInstance); String vpcId = getVpcsMap(vimInstance).get(vimInstance.getTenant()); @@ -449,7 +489,6 @@ public Server launchInstanceAndWait( java.util.Map floatingIps, java.util.Set keys) throws VimDriverException { - AmazonEC2 client = createClient(vimInstance); Server server = launchInstance( @@ -485,91 +524,104 @@ public Server launchInstanceAndWait( @java.lang.Override public void deleteServerByIdAndWait(VimInstance vimInstance, String id) throws VimDriverException { - AmazonEC2 client = createClient(vimInstance); - TerminateInstancesRequest req = new TerminateInstancesRequest().withInstanceIds(id); - TerminateInstancesResult res = client.terminateInstances(req); + try { + AmazonEC2 client = createClient(vimInstance); + TerminateInstancesRequest req = new TerminateInstancesRequest().withInstanceIds(id); + TerminateInstancesResult res = client.terminateInstances(req); + } catch (AmazonClientException e) { + VimDriverException vimDriverException = new VimDriverException(e.getMessage()); + throw vimDriverException; + } } @java.lang.Override public Network createNetwork(VimInstance vimInstance, Network network) throws VimDriverException { AmazonEC2 client = createClient(vimInstance); - - String vpcId = getVpcsMap(vimInstance).get(vimInstance.getTenant()); - if (vpcId == null) { - throw new VimDriverException("No such VPC " + vimInstance.getTenant() + " exists"); - } - CreateSubnetResult res; try { - CreateSubnetRequest req = - new CreateSubnetRequest() - .withVpcId(vpcId) - .withCidrBlock(network.getSubnets().iterator().next().getCidr()); - res = client.createSubnet(req); - } catch (Exception e) { - log.debug("Provided CIDR is invalid, generating different one"); - DescribeVpcsRequest req = new DescribeVpcsRequest(); - DescribeVpcsResult resVpc = client.describeVpcs(req); - Vpc vpc = null; - for (Vpc vpc1 : resVpc.getVpcs()) { - if (vpc1.getVpcId().equals(vpcId)) { - vpc = vpc1; + String vpcId = getVpcsMap(vimInstance).get(vimInstance.getTenant()); + if (vpcId == null) { + throw new VimDriverException("No such VPC " + vimInstance.getTenant() + " exists"); + } + CreateSubnetResult res; + try { + CreateSubnetRequest req = + new CreateSubnetRequest() + .withVpcId(vpcId) + .withCidrBlock(network.getSubnets().iterator().next().getCidr()); + res = client.createSubnet(req); + } catch (Exception e) { + log.debug("Provided CIDR is invalid, generating different one"); + DescribeVpcsRequest req = new DescribeVpcsRequest(); + DescribeVpcsResult resVpc = client.describeVpcs(req); + Vpc vpc = null; + for (Vpc vpc1 : resVpc.getVpcs()) { + if (vpc1.getVpcId().equals(vpcId)) { + vpc = vpc1; + } + } + if (vpc == null) { + throw new VimDriverException("The vpc with id " + vpcId + " might not exist anymore"); + } + String vpcCidr = vpc.getCidrBlock(); + String adrMask[] = vpcCidr.split("/"); + String adr[] = adrMask[0].split("…\\.")[0].split("\\."); + Random random = new Random(); + int number = random.nextInt(255); + String subnetCidr = adr[0] + "." + adr[1] + "." + number + "." + "0" + "/24"; + log.info("Generated CIDR " + subnetCidr); + CreateSubnetRequest newReq = + new CreateSubnetRequest().withVpcId(vpcId).withCidrBlock(subnetCidr); + res = client.createSubnet(newReq); + } + String id = res.getSubnet().getSubnetId(); + List tags = new ArrayList<>(); + Tag tag = new Tag(); + tag.setKey("Name"); + tag.setValue(network.getName()); + tags.add(tag); + CreateTagsRequest tagsRequest = new CreateTagsRequest().withTags(tags).withResources(id); + client.createTags(tagsRequest); + List nets = listNetworks(vimInstance); + Network returnNetwork = null; + for (Network net : nets) { + if (net.getExtId().equals(res.getSubnet().getSubnetId())) { + returnNetwork = net; + } } - } - if (vpc == null) { - throw new VimDriverException("The vpc with id " + vpcId + " might not exist anymore"); - } - String vpcCidr = vpc.getCidrBlock(); - String adrMask[] = vpcCidr.split("/"); - String adr[] = adrMask[0].split("…\\.")[0].split("\\."); - Random random = new Random(); - int number = random.nextInt(255); - String subnetCidr = adr[0] + "." + adr[1] + "." + number + "." + "0" + "/24"; - log.info("Generated CIDR " + subnetCidr); - CreateSubnetRequest newReq = - new CreateSubnetRequest().withVpcId(vpcId).withCidrBlock(subnetCidr); - res = client.createSubnet(newReq); - } - String id = res.getSubnet().getSubnetId(); - List tags = new ArrayList<>(); - Tag tag = new Tag(); - tag.setKey("Name"); - tag.setValue(network.getName()); - tags.add(tag); - CreateTagsRequest tagsRequest = new CreateTagsRequest().withTags(tags).withResources(id); - client.createTags(tagsRequest); - List nets = listNetworks(vimInstance); - Network returnNetwork = null; - for (Network net : nets) { - if (net.getExtId().equals(res.getSubnet().getSubnetId())) { - returnNetwork = net; - } - } - return returnNetwork; + return returnNetwork; + } catch (AmazonClientException e) { + VimDriverException vimDriverException = new VimDriverException(e.getMessage()); + throw vimDriverException; + } } private HashMap getVpcsMap(VimInstance vimInstance) throws VimDriverException { AmazonEC2 client = createClient(vimInstance); - DescribeVpcsRequest describeVpcsRequest = new DescribeVpcsRequest(); - DescribeVpcsResult describeVpcsResult = client.describeVpcs(describeVpcsRequest); - HashMap vpcNameId = new HashMap<>(); - for (Vpc vpc : describeVpcsResult.getVpcs()) { - String id = vpc.getVpcId(); - String name = ""; - for (Tag tag : vpc.getTags()) { - if (tag.getKey().equals("Name")) { - name = tag.getValue(); + try { + DescribeVpcsRequest describeVpcsRequest = new DescribeVpcsRequest(); + DescribeVpcsResult describeVpcsResult = client.describeVpcs(describeVpcsRequest); + HashMap vpcNameId = new HashMap<>(); + for (Vpc vpc : describeVpcsResult.getVpcs()) { + String id = vpc.getVpcId(); + String name = ""; + for (Tag tag : vpc.getTags()) { + if (tag.getKey().equals("Name")) { + name = tag.getValue(); + } + } + vpcNameId.put(name, id); } - } - vpcNameId.put(name, id); + return vpcNameId; + } catch (AmazonClientException e) { + VimDriverException vimDriverException = new VimDriverException(e.getMessage()); + throw vimDriverException; } - return vpcNameId; } @java.lang.Override public DeploymentFlavour addFlavor(VimInstance vimInstance, DeploymentFlavour deploymentFlavour) throws VimDriverException { - AmazonEC2 client = createClient(vimInstance); return null; } @@ -713,24 +765,34 @@ public boolean deleteSubnet(VimInstance vimInstance, String existingSubnetExtId) @java.lang.Override public boolean deleteNetwork(VimInstance vimInstance, String extId) throws VimDriverException { - AmazonEC2 client = createClient(vimInstance); - DeleteSubnetRequest req = new DeleteSubnetRequest().withSubnetId(extId); - DeleteSubnetResult res = client.deleteSubnet(req); - return true; + try { + AmazonEC2 client = createClient(vimInstance); + DeleteSubnetRequest req = new DeleteSubnetRequest().withSubnetId(extId); + DeleteSubnetResult res = client.deleteSubnet(req); + return true; + } catch (AmazonClientException e) { + VimDriverException vimDriverException = new VimDriverException(e.getMessage()); + throw vimDriverException; + } } @java.lang.Override public Network getNetworkById(VimInstance vimInstance, String id) throws VimDriverException { - AmazonEC2 client = createClient(vimInstance); - Filter filter = new Filter(); - filter.setName("subnet-id"); - filter.setValues(Arrays.asList(id)); - DescribeSubnetsRequest req = new DescribeSubnetsRequest().withFilters(filter); - DescribeSubnetsResult res = client.describeSubnets(req); - if (res.getSubnets().size() < 1) { - throw new VimDriverException("Network with id " + id + " does not exist"); - } - return Utils.getNetworkFromSubnet(res.getSubnets().get(0)); + AmazonEC2 client = createClient(vimInstance); + try { + Filter filter = new Filter(); + filter.setName("subnet-id"); + filter.setValues(Arrays.asList(id)); + DescribeSubnetsRequest req = new DescribeSubnetsRequest().withFilters(filter); + DescribeSubnetsResult res = client.describeSubnets(req); + if (res.getSubnets().size() < 1) { + throw new VimDriverException("Network with id " + id + " does not exist"); + } + return Utils.getNetworkFromSubnet(res.getSubnets().get(0)); + } catch (AmazonClientException e) { + VimDriverException vimDriverException = new VimDriverException(e.getMessage()); + throw vimDriverException; + } } @java.lang.Override From 3768dc54e6f24657375ef9229d9e4a7f8c1896df Mon Sep 17 00:00:00 2001 From: flaviomu Date: Thu, 23 Nov 2017 18:04:26 +0100 Subject: [PATCH 02/10] Imp: update deb packaging plugin --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 257ed71..52da0af 100644 --- a/build.gradle +++ b/build.gradle @@ -23,7 +23,7 @@ buildscript { } plugins { id 'net.researchgate.release' version '2.1.2' - id "nebula.os-package" version "2.2.6" + id "nebula.ospackage" version "4.5.1" id 'com.github.sherter.google-java-format' version '0.5' } From dfbce7248839fa45b327fa5b2daa659648108e73 Mon Sep 17 00:00:00 2001 From: Oleksander Gozman Date: Mon, 27 Nov 2017 17:18:35 +0100 Subject: [PATCH 03/10] imp: use elastic ip adresses 1. use elastic ip adresses 2. adresses are attached after instances creation 3. one elastic ip is attached to every instances primary networkinterface 4. work-in-progress --- .../drivers/amazon/AmazonDriver.java | 93 ++++++++++++++----- 1 file changed, 69 insertions(+), 24 deletions(-) diff --git a/src/main/java/org/openbaton/drivers/amazon/AmazonDriver.java b/src/main/java/org/openbaton/drivers/amazon/AmazonDriver.java index 77d05d7..4cec777 100644 --- a/src/main/java/org/openbaton/drivers/amazon/AmazonDriver.java +++ b/src/main/java/org/openbaton/drivers/amazon/AmazonDriver.java @@ -32,6 +32,7 @@ import java.io.UnsupportedEncodingException; import java.lang.reflect.InvocationTargetException; import java.util.*; +import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -58,9 +59,7 @@ public AmazonDriver() { public static void main(String[] args) throws NoSuchMethodException, IOException, InstantiationException, TimeoutException, IllegalAccessException, InvocationTargetException, InterruptedException { - - - if (args.length == 4) { + if (args.length == 4) { log.info("Starting the plugin with CUSTOM parameters: "); log.info("name: " + args[0]); log.info("brokerIp: " + args[1]); @@ -157,8 +156,6 @@ public Server launchInstance( } log.info("Found the VPC ID: " + vpcId); byte[] encodedData = Base64.encodeBase64(changeUserData.getBytes()); - DescribeVpcsRequest describeVpcsRequest = new DescribeVpcsRequest(); - DescribeVpcsResult describeVpcsResult = client.describeVpcs(describeVpcsRequest); List flavours = listFlavors(vimInstance); log.info("Listed flavours"); List presentSubnets = listNetworks(vimInstance); @@ -168,7 +165,7 @@ public Server launchInstance( log.info("Retrieved security ids"); int deviceIndex = 0; for (Network net : searchForRelevantSubnets(presentSubnets, newNetworks)) { - inters.add(createInterface(net, deviceIndex, newNetworks, groupIds)); + inters.add(createInterface(net, deviceIndex, groupIds)); deviceIndex++; log.info("Interface " + deviceIndex); } @@ -212,12 +209,32 @@ public Server launchInstance( new ModifyInstanceAttributeRequest().withGroups(groupIds).withInstanceId(id); log.info("Assigning security groups to instance " + id); ModifyInstanceAttributeResult groupRes = client.modifyInstanceAttribute(groupsReq);*/ - List servers = listServer(vimInstance); - for (Server ser : servers) { - if (ser.getHostName().equals(name)) { - server = ser; - } + boolean ready = false; + while (!ready) { + List servers = listServer(vimInstance); + for (Server ser : servers) { + if (ser != null && ser.getHostName().equals(name) && ser.getStatus().equals("running")) { + server = ser; + ready = true; + + } + try { + TimeUnit.SECONDS.sleep(7); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } } + DescribeAddressesRequest addReq = new DescribeAddressesRequest(); + DescribeAddressesResult re = client.describeAddresses(addReq); + int i = 0; + while (re.getAddresses().get(i).getAssociationId() != null) { + i++; + } + AssociateAddressRequest addrReq = new AssociateAddressRequest().withNetworkInterfaceId(listIntrefaceByAttachment(client, server.getExtId()).get(0).getNetworkInterfaceId()) + .withAllocationId(re.getAddresses().get(i).getAllocationId()).withAllowReassociation(false); + client.associateAddress(addrReq); + } catch (VimException e) { log.error(e.getMessage(), e); @@ -234,6 +251,35 @@ public Server launchInstance( return server; } + private List listIntrefaceByAttachment(AmazonEC2 client, String instanceId) { + Filter filter = new Filter(); + filter.setName("attachment.instance-id"); + filter.setValues(Collections.singletonList(instanceId)); + Filter filter1 = new Filter(); + filter1.setName("attachment.device-index"); + filter1.setValues(Collections.singletonList("0")); + DescribeNetworkInterfacesRequest req = new DescribeNetworkInterfacesRequest().withFilters(Arrays.asList(filter, filter1)); + DescribeNetworkInterfacesResult res = client.describeNetworkInterfaces(req); + return res.getNetworkInterfaces(); + } + private List getInternetGatewaysByVPC(AmazonEC2 client, String vpcId) { + Filter filter = new Filter(); + filter.setName("attachment.vpc-id"); + filter.setValues(Collections.singletonList(vpcId)); + DescribeInternetGatewaysRequest request = new DescribeInternetGatewaysRequest(); + request.setFilters(Collections.singletonList(filter)); + DescribeInternetGatewaysResult result = client.describeInternetGateways(request); + return result.getInternetGateways(); + } + + private InternetGateway createAndAttachInternetGateway(AmazonEC2 client, String vpcId) { + CreateInternetGatewayRequest request = new CreateInternetGatewayRequest(); + CreateInternetGatewayResult result = client.createInternetGateway(request); + InternetGateway gateway = result.getInternetGateway(); + AttachInternetGatewayRequest attach = new AttachInternetGatewayRequest().withVpcId(vpcId).withInternetGatewayId(gateway.getInternetGatewayId()); + client.attachInternetGateway(attach); + return gateway; + } /** * Checks if the image exists inside AWS and returns its ID @@ -269,26 +315,25 @@ private String imageExistsOnAWS(String nameId, AmazonEC2 client) throws AmazonCl * * @param net subnet inside AWS represented through NFVO network * @param deviceIndex device index for the interface is required by AWS - * @param cps VNFD connection points * @return the list of interfaces */ private InstanceNetworkInterfaceSpecification createInterface( - Network net, int deviceIndex, Set cps, Set secIDs) { - InstanceNetworkInterfaceSpecification interSpec = - new InstanceNetworkInterfaceSpecification() - .withDeleteOnTermination(true) - .withSubnetId(net.getExtId()) - .withDeviceIndex(deviceIndex).withGroups(secIDs); - String floatingIp = ""; + Network net, int deviceIndex, Set secIDs) { + InstanceNetworkInterfaceSpecification interSpec = + new InstanceNetworkInterfaceSpecification() + .withDeleteOnTermination(true) + .withSubnetId(net.getExtId()) + .withGroups(secIDs).withDeviceIndex(deviceIndex); + log.info("Device index" + deviceIndex); + return interSpec; + + /*String floatingIp = ""; for (VNFDConnectionPoint cp : cps) { if (net.getName().equals(cp.getVirtual_link_reference())) { floatingIp = cp.getFloatingIp(); } - } - if (floatingIp != null) { - interSpec.setAssociatePublicIpAddress(true); - } - return interSpec; + }*/ + } /** From 2f5b75ea4cc8de538632a052aee319d674d69603 Mon Sep 17 00:00:00 2001 From: Oleksander Gozman Date: Thu, 30 Nov 2017 15:26:00 +0100 Subject: [PATCH 04/10] imp: assign elastic ips to all interfaces elastic ips will be allocated if not present have to solve a problem with limit of ips though because the default limit is 5 which is not a lot --- .../drivers/amazon/AmazonDriver.java | 111 ++++++++++++------ src/main/resources/plugin.conf.properties | 1 + 2 files changed, 77 insertions(+), 35 deletions(-) diff --git a/src/main/java/org/openbaton/drivers/amazon/AmazonDriver.java b/src/main/java/org/openbaton/drivers/amazon/AmazonDriver.java index 4cec777..dab36e5 100644 --- a/src/main/java/org/openbaton/drivers/amazon/AmazonDriver.java +++ b/src/main/java/org/openbaton/drivers/amazon/AmazonDriver.java @@ -59,7 +59,8 @@ public AmazonDriver() { public static void main(String[] args) throws NoSuchMethodException, IOException, InstantiationException, TimeoutException, IllegalAccessException, InvocationTargetException, InterruptedException { - if (args.length == 4) { + + if (args.length == 4) { log.info("Starting the plugin with CUSTOM parameters: "); log.info("name: " + args[0]); log.info("brokerIp: " + args[1]); @@ -205,37 +206,14 @@ public Server launchInstance( tags.add(tag); CreateTagsRequest tagsRequest = new CreateTagsRequest().withTags(tags).withResources(id); client.createTags(tagsRequest); - /*ModifyInstanceAttributeRequest groupsReq = - new ModifyInstanceAttributeRequest().withGroups(groupIds).withInstanceId(id); - log.info("Assigning security groups to instance " + id); - ModifyInstanceAttributeResult groupRes = client.modifyInstanceAttribute(groupsReq);*/ - boolean ready = false; - while (!ready) { - List servers = listServer(vimInstance); - for (Server ser : servers) { - if (ser != null && ser.getHostName().equals(name) && ser.getStatus().equals("running")) { - server = ser; - ready = true; - - } - try { - TimeUnit.SECONDS.sleep(7); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } - DescribeAddressesRequest addReq = new DescribeAddressesRequest(); - DescribeAddressesResult re = client.describeAddresses(addReq); - int i = 0; - while (re.getAddresses().get(i).getAssociationId() != null) { - i++; + server = waitForInstance(name, vimInstance); + setupInstanceNetwork(client, server); + List servers = listServer(vimInstance); + for (Server ser : servers) { + if (ser != null && ser.getHostName().equals(name)) { + server = ser; + } } - AssociateAddressRequest addrReq = new AssociateAddressRequest().withNetworkInterfaceId(listIntrefaceByAttachment(client, server.getExtId()).get(0).getNetworkInterfaceId()) - .withAllocationId(re.getAddresses().get(i).getAllocationId()).withAllowReassociation(false); - client.associateAddress(addrReq); - - } catch (VimException e) { log.error(e.getMessage(), e); VimDriverException vimDriverException = new VimDriverException(e.getMessage()); @@ -246,19 +224,82 @@ public Server launchInstance( } catch (AmazonClientException e) { VimDriverException vimDriverException = new VimDriverException(e.getMessage()); throw vimDriverException; + } catch (InterruptedException e) { + throw new VimDriverException(e.getMessage()); } log.info("Instance " + name + " launched"); return server; } - private List listIntrefaceByAttachment(AmazonEC2 client, String instanceId) { + private Server waitForInstance(String name, VimInstance vimInstance) throws VimDriverException, InterruptedException { + int timeOut = Integer.parseInt(properties.getProperty("launchTimeout")); + log.info("Waiting for instance. LaunchTimeout is " + timeOut); + int waitTime = 4; + while (waitTime < timeOut) { + List servers = listServer(vimInstance); + for (Server ser : servers) { + if (ser != null && ser.getHostName().equals(name) && ser.getStatus().equals("running")) { + return ser; + } + try { + TimeUnit.SECONDS.sleep(waitTime); + waitTime = waitTime * 2; + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + throw new VimDriverException("Launch Timeout reached, seems that the instance never went into running status"); + } + + private void setupInstanceNetwork(AmazonEC2 client, Server server) { + List
freeAddresses = getUnallocatedAddresses(client); + List instanceInterfaces = listInterfaceByAttachment(client, server.getExtId()); + + if (freeAddresses.size() < instanceInterfaces.size()) { + allocateElasticIps(client, instanceInterfaces.size() - freeAddresses.size()); + } + freeAddresses = getUnallocatedAddresses(client); + int i = 0; + for (NetworkInterface inter: instanceInterfaces) { + AssociateAddressRequest addrReq = new AssociateAddressRequest().withNetworkInterfaceId(inter.getNetworkInterfaceId()) + .withAllocationId(freeAddresses.get(i).getAllocationId()).withAllowReassociation(false); + client.associateAddress(addrReq); + i++; + } + } + + private void allocateElasticIps(AmazonEC2 client, int number) { + log.info("Allocating " + number + " elastic ips"); + AllocateAddressRequest req = new AllocateAddressRequest(); + for (int i = 0; i < number; i++) { + client.allocateAddress(req); + } + } + + private List
getUnallocatedAddresses(AmazonEC2 client) { + DescribeAddressesRequest addReq = new DescribeAddressesRequest(); + DescribeAddressesResult re = client.describeAddresses(addReq); + List
unAllockAddrs = new ArrayList<>(); + for (Address addr: re.getAddresses()) { + if (addr.getAssociationId() == null) { + unAllockAddrs.add(addr); + } + } + return unAllockAddrs; + + } + + private List listInterfaceByAttachment(AmazonEC2 client, String instanceId) { Filter filter = new Filter(); filter.setName("attachment.instance-id"); filter.setValues(Collections.singletonList(instanceId)); Filter filter1 = new Filter(); - filter1.setName("attachment.device-index"); - filter1.setValues(Collections.singletonList("0")); - DescribeNetworkInterfacesRequest req = new DescribeNetworkInterfacesRequest().withFilters(Arrays.asList(filter, filter1)); +// filter1.setName("attachment.device-index"); +// filter1.setValues(Collections.singletonList("0")); +// +// DescribeNetworkInterfacesRequest req = new DescribeNetworkInterfacesRequest().withFilters(Arrays.asList(filter, filter1)); + DescribeNetworkInterfacesRequest req = new DescribeNetworkInterfacesRequest().withFilters(Collections.singletonList(filter)); DescribeNetworkInterfacesResult res = client.describeNetworkInterfaces(req); return res.getNetworkInterfaces(); } diff --git a/src/main/resources/plugin.conf.properties b/src/main/resources/plugin.conf.properties index f033e83..6aa6ea1 100644 --- a/src/main/resources/plugin.conf.properties +++ b/src/main/resources/plugin.conf.properties @@ -18,3 +18,4 @@ type = amazon external-properties-file = /etc/openbaton/plugin/amazon/driver.properties image-key-word = ubuntu/images/hvm-ssd/ubuntu-trusty-14.04-amd64-server-20170727,ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-20170721,CentOS Linux 7 x86_64 HVM EBS 1708_01-b7ee8a69-ee97-4a49-9e68-afaee216db2e-ami-0d8f9576.4 +launchTimeout = 64 \ No newline at end of file From bc8b0aca885c7112d34d234ed500faed4d672129 Mon Sep 17 00:00:00 2001 From: Oleksander Gozman Date: Thu, 14 Dec 2017 13:27:31 +0100 Subject: [PATCH 05/10] fea: started move to new catalogue --- build.gradle | 2 +- .../drivers/amazon/AmazonDriver.java | 70 +++++++++++++++---- .../org/openbaton/drivers/amazon/Utils.java | 19 +++-- src/main/resources/plugin.conf.properties | 2 +- 4 files changed, 69 insertions(+), 24 deletions(-) diff --git a/build.gradle b/build.gradle index 52da0af..85e70e7 100644 --- a/build.gradle +++ b/build.gradle @@ -64,7 +64,7 @@ project.ext { * gradle Related Vars */ mainClass = 'org.openbaton.drivers.amazon.AmazonDriver' - obVersion = '5.0.0-RC3-SNAPSHOT' + obVersion = '5.1.1' //------------------------------------------------// } diff --git a/src/main/java/org/openbaton/drivers/amazon/AmazonDriver.java b/src/main/java/org/openbaton/drivers/amazon/AmazonDriver.java index dab36e5..cccd702 100644 --- a/src/main/java/org/openbaton/drivers/amazon/AmazonDriver.java +++ b/src/main/java/org/openbaton/drivers/amazon/AmazonDriver.java @@ -40,6 +40,9 @@ import org.openbaton.catalogue.mano.common.DeploymentFlavour; import org.openbaton.catalogue.mano.descriptor.VNFDConnectionPoint; import org.openbaton.catalogue.nfvo.*; +import org.openbaton.catalogue.nfvo.viminstances.BaseVimInstance; +import org.openbaton.catalogue.nfvo.viminstances.AmazonVimInstance; +import org.openbaton.catalogue.nfvo.networks.AWSNetwork; import org.openbaton.catalogue.security.Key; import org.openbaton.exceptions.VimDriverException; import org.openbaton.exceptions.VimException; @@ -60,6 +63,8 @@ public static void main(String[] args) throws NoSuchMethodException, IOException, InstantiationException, TimeoutException, IllegalAccessException, InvocationTargetException, InterruptedException { + + if (args.length == 4) { log.info("Starting the plugin with CUSTOM parameters: "); log.info("name: " + args[0]); @@ -108,7 +113,7 @@ private String changeHostname(String userdata, String hostname) { * @return amazonEc2 client ready to handle requests * @throws VimDriverException if one of the arguments is not correctly set */ - private AmazonEC2 createClient(VimInstance vimInstance) throws VimDriverException { + private AmazonEC2 createClient(AmazonVimInstance vimInstance) throws VimDriverException { BasicAWSCredentials awsCreds = new BasicAWSCredentials(vimInstance.getUsername(), vimInstance.getPassword()); Regions regions; @@ -130,7 +135,7 @@ private AmazonEC2 createClient(VimInstance vimInstance) throws VimDriverExceptio @java.lang.Override public Server launchInstance( - VimInstance vimInstance, + BaseVimInstance vimInstance, String name, String image, String flavor, @@ -145,7 +150,7 @@ public Server launchInstance( try { String changeUserData = changeHostname(userData, name); log.info(changeUserData); - AmazonEC2 client = createClient(vimInstance); + AmazonEC2 client = createClient((AmazonVimInstance) vimInstance); Gson gson = new Gson(); String oldVNFDCP = gson.toJson(networks); Set newNetworks = @@ -207,6 +212,7 @@ public Server launchInstance( CreateTagsRequest tagsRequest = new CreateTagsRequest().withTags(tags).withResources(id); client.createTags(tagsRequest); server = waitForInstance(name, vimInstance); + log.info("Instance is up, handling networking"); setupInstanceNetwork(client, server); List servers = listServer(vimInstance); for (Server ser : servers) { @@ -231,7 +237,46 @@ public Server launchInstance( return server; } - private Server waitForInstance(String name, VimInstance vimInstance) throws VimDriverException, InterruptedException { + @Override + public BaseVimInstance refresh(BaseVimInstance vimInstance) throws VimDriverException { + AmazonVimInstance amazon = (AmazonVimInstance) vimInstance; + List newImages = listImages(vimInstance); + if (amazon.getImages() == null) { + amazon.setImages(new HashSet<>()); + } + amazon.getImages().clear(); + amazon.addAllImages(newImages); + + List newNetworks = listNetworks(vimInstance); + + if (amazon.getNetworks() == null) { + amazon.setNetworks(new HashSet<>()); + } + amazon.getNetworks().clear(); + amazon.addAllNetworks(newNetworks); + + List newFlavors = listFlavors(vimInstance); + if (amazon.getFlavours() == null) { + amazon.setFlavours(new HashSet<>()); + } + amazon.getFlavours().clear(); + amazon.getFlavours().addAll(newFlavors); + + List newAvalabilityZones = + listAvailabilityZone(vimInstance); + if (amazon.getZones() == null) { + amazon.setZones(new HashSet<>()); + } + amazon.getZones().clear(); + amazon.getZones().addAll(newAvalabilityZones); + + amazon.setVpcId(getVpcsMap(amazon).get(vimInstance.getVpcName()); + + return amazon; + } + + + private Server waitForInstance(String name, BaseVimInstance vimInstance) throws VimDriverException, InterruptedException { int timeOut = Integer.parseInt(properties.getProperty("launchTimeout")); log.info("Waiting for instance. LaunchTimeout is " + timeOut); int waitTime = 4; @@ -425,8 +470,8 @@ public int compare(VNFDConnectionPoint t, VNFDConnectionPoint t1) { * does not exits */ private Set getSecurityIdFromName( - Set groupNames, AmazonEC2 client, VimInstance vimInstance) throws VimDriverException, AmazonClientException { - String vpcId = getVpcsMap(vimInstance).get(vimInstance.getTenant()); + Set groupNames, AmazonEC2 client, BaseVimInstance vimInstance) throws VimDriverException, AmazonClientException { + String vpcId = ((AmazonVimInstance) vimInstance).getVpcId; if (vpcId == null) { throw new VimDriverException("No such VPC " + vimInstance.getTenant() + " exists"); } @@ -456,9 +501,9 @@ private Set getSecurityIdFromName( } @java.lang.Override - public java.util.List listImages(VimInstance vimInstance) throws VimDriverException { + public java.util.List listImages(BaseVimInstance vimInstance) throws VimDriverException { try { - AmazonEC2 client = createClient(vimInstance); + AmazonEC2 client = createClient((AmazonVimInstance) vimInstance); String keyWord = properties.getProperty("image-key-word", "*"); String keyWords[] = keyWord.split(","); for (int i = 0; i < keyWords.length; i++) { @@ -470,7 +515,7 @@ public java.util.List listImages(VimInstance vimInstance) throws VimDr DescribeImagesRequest describeImagesRequest = new DescribeImagesRequest(); describeImagesRequest.setFilters(Arrays.asList(filter)); DescribeImagesResult describeImagesResult = client.describeImages(describeImagesRequest); - List images = new ArrayList<>(); + List images = new ArrayList<>(); for (Image image : describeImagesResult.getImages()) { images.add(Utils.getImage(image)); } @@ -492,13 +537,14 @@ public java.util.List listImages(VimInstance vimInstance) throws VimDr } @java.lang.Override - public java.util.List listServer(VimInstance vimInstance) throws VimDriverException { + public java.util.List listServer(BaseVimInstance vimInstanceBase) throws VimDriverException { + AmazonVimInstance vimInstance = (AmazonVimInstance) vimInstanceBase; try { List servers = new ArrayList<>(); AmazonEC2 client = createClient(vimInstance); - String vpcId = getVpcsMap(vimInstance).get(vimInstance.getTenant()); + String vpcId = getVpcsMap(vimInstance).get(vimInstance.getVpcName()); if (vpcId == null) { - throw new VimDriverException("No such VPC " + vimInstance.getTenant() + " exists"); + throw new VimDriverException("No such VPC " + vimInstance.getVpcName() + " exists"); } Filter filter = new Filter(); filter.setName("vpc-id"); diff --git a/src/main/java/org/openbaton/drivers/amazon/Utils.java b/src/main/java/org/openbaton/drivers/amazon/Utils.java index 632fd0a..e4e2b0b 100644 --- a/src/main/java/org/openbaton/drivers/amazon/Utils.java +++ b/src/main/java/org/openbaton/drivers/amazon/Utils.java @@ -2,15 +2,12 @@ import com.amazonaws.services.ec2.model.*; import java.util.*; -import org.openbaton.catalogue.nfvo.NFVImage; -import org.openbaton.catalogue.nfvo.Network; +import org.openbaton.catalogue.nfvo.images.AWSImage; import org.openbaton.catalogue.nfvo.Server; -import org.openbaton.catalogue.nfvo.Subnet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; class Utils { - private static Logger log = LoggerFactory.getLogger(Utils.class); static org.openbaton.catalogue.nfvo.Server getServer(Instance instance, List nets) { Server server = new Server(); @@ -100,13 +97,15 @@ static org.openbaton.catalogue.nfvo.Network getNetworkFromSubnet( return nfvoNetwork; } - static org.openbaton.catalogue.nfvo.NFVImage getImage( + static org.openbaton.catalogue.nfvo.images.AWSImage getImage( com.amazonaws.services.ec2.model.Image image) { - NFVImage nfvoImage = new NFVImage(); - nfvoImage.setName(image.getName()); - nfvoImage.setExtId(image.getImageId()); - nfvoImage.setDiskFormat(image.getImageType()); - nfvoImage.setStatus("ACTIVE"); + AWSImage nfvoImage = new AWSImage(); + AWSImage.setName(image.getName()); + AWSImage.setExtId(image.getImageId()); + AWSImage.setHypervisor(image.getHypervisor()); + AWSImage.setDescripton(image.getDescription()); + AWSImage.setImageOwner(image.getImageOwnerAlias()); + AWSImage.setPublic(image.getPublic()); return nfvoImage; } } diff --git a/src/main/resources/plugin.conf.properties b/src/main/resources/plugin.conf.properties index 6aa6ea1..b0c7010 100644 --- a/src/main/resources/plugin.conf.properties +++ b/src/main/resources/plugin.conf.properties @@ -18,4 +18,4 @@ type = amazon external-properties-file = /etc/openbaton/plugin/amazon/driver.properties image-key-word = ubuntu/images/hvm-ssd/ubuntu-trusty-14.04-amd64-server-20170727,ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-20170721,CentOS Linux 7 x86_64 HVM EBS 1708_01-b7ee8a69-ee97-4a49-9e68-afaee216db2e-ami-0d8f9576.4 -launchTimeout = 64 \ No newline at end of file +launchTimeout = 128 \ No newline at end of file From 1de509574ece188029a10733484fff99b818f207 Mon Sep 17 00:00:00 2001 From: Oleksander Gozman Date: Mon, 18 Dec 2017 17:16:55 +0100 Subject: [PATCH 06/10] fea: move to new catalogue in progress --- build.gradle | 4 +- .../drivers/amazon/AmazonDriver.java | 257 +++++++----------- .../org/openbaton/drivers/amazon/Utils.java | 38 +-- 3 files changed, 127 insertions(+), 172 deletions(-) diff --git a/build.gradle b/build.gradle index 85e70e7..3ae0fbe 100644 --- a/build.gradle +++ b/build.gradle @@ -64,7 +64,7 @@ project.ext { * gradle Related Vars */ mainClass = 'org.openbaton.drivers.amazon.AmazonDriver' - obVersion = '5.1.1' + obVersion = '5.1.3-SNAPSHOT' //------------------------------------------------// } @@ -91,6 +91,8 @@ dependencies { compile 'org.slf4j:slf4j-simple:1.7.12' testCompile("junit:junit:4.12") + + } apply from: 'gradle/gradle/packaging.plugin-vimdriver-amazon.debian.gradle' diff --git a/src/main/java/org/openbaton/drivers/amazon/AmazonDriver.java b/src/main/java/org/openbaton/drivers/amazon/AmazonDriver.java index cccd702..507f92b 100644 --- a/src/main/java/org/openbaton/drivers/amazon/AmazonDriver.java +++ b/src/main/java/org/openbaton/drivers/amazon/AmazonDriver.java @@ -26,6 +26,7 @@ import com.amazonaws.services.ec2.model.*; import com.amazonaws.services.ec2.model.InstanceType; import com.amazonaws.services.ec2.model.Subnet; +import com.fasterxml.jackson.databind.ser.Serializers; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import java.io.IOException; @@ -40,6 +41,9 @@ import org.openbaton.catalogue.mano.common.DeploymentFlavour; import org.openbaton.catalogue.mano.descriptor.VNFDConnectionPoint; import org.openbaton.catalogue.nfvo.*; +import org.openbaton.catalogue.nfvo.images.AWSImage; +import org.openbaton.catalogue.nfvo.images.BaseNfvImage; +import org.openbaton.catalogue.nfvo.networks.BaseNetwork; import org.openbaton.catalogue.nfvo.viminstances.BaseVimInstance; import org.openbaton.catalogue.nfvo.viminstances.AmazonVimInstance; import org.openbaton.catalogue.nfvo.networks.AWSNetwork; @@ -115,7 +119,7 @@ private String changeHostname(String userdata, String hostname) { */ private AmazonEC2 createClient(AmazonVimInstance vimInstance) throws VimDriverException { BasicAWSCredentials awsCreds = - new BasicAWSCredentials(vimInstance.getUsername(), vimInstance.getPassword()); + new BasicAWSCredentials(vimInstance.getAccessKey(), vimInstance.getSecretKey()); Regions regions; AmazonEC2 client; try { @@ -135,7 +139,7 @@ private AmazonEC2 createClient(AmazonVimInstance vimInstance) throws VimDriverEx @java.lang.Override public Server launchInstance( - BaseVimInstance vimInstance, + BaseVimInstance vimInstanceBase, String name, String image, String flavor, @@ -148,29 +152,30 @@ public Server launchInstance( log.info("Launching instance " + name); Server server = null; try { + AmazonVimInstance vimInstance = (AmazonVimInstance) vimInstanceBase; String changeUserData = changeHostname(userData, name); log.info(changeUserData); - AmazonEC2 client = createClient((AmazonVimInstance) vimInstance); + AmazonEC2 client = createClient(vimInstance); Gson gson = new Gson(); String oldVNFDCP = gson.toJson(networks); Set newNetworks = gson.fromJson(oldVNFDCP, new TypeToken>() {}.getType()); RunInstancesRequest runInstancesRequest = new RunInstancesRequest(); - String vpcId = getVpcsMap(vimInstance).get(vimInstance.getTenant()); + String vpcId = getVpcsMap(vimInstance).get(vimInstance.getVpcName()); if (vpcId == null) { - throw new VimDriverException("No such VPC " + vimInstance.getTenant() + " exists"); + throw new VimDriverException("No such VPC " + vimInstance.getVpcName() + " exists"); } log.info("Found the VPC ID: " + vpcId); byte[] encodedData = Base64.encodeBase64(changeUserData.getBytes()); List flavours = listFlavors(vimInstance); log.info("Listed flavours"); - List presentSubnets = listNetworks(vimInstance); + List presentSubnets = listNetworks(vimInstance); log.info("Listed subents"); Collection inters = new ArrayList<>(); Set groupIds = getSecurityIdFromName(secGroup, client, vimInstance); log.info("Retrieved security ids"); int deviceIndex = 0; - for (Network net : searchForRelevantSubnets(presentSubnets, newNetworks)) { + for (BaseNetwork net : searchForRelevantSubnets(presentSubnets, newNetworks)) { inters.add(createInterface(net, deviceIndex, groupIds)); deviceIndex++; log.info("Interface " + deviceIndex); @@ -240,7 +245,7 @@ public Server launchInstance( @Override public BaseVimInstance refresh(BaseVimInstance vimInstance) throws VimDriverException { AmazonVimInstance amazon = (AmazonVimInstance) vimInstance; - List newImages = listImages(vimInstance); + List newImages = listImages(vimInstance); if (amazon.getImages() == null) { amazon.setImages(new HashSet<>()); } @@ -254,23 +259,7 @@ public BaseVimInstance refresh(BaseVimInstance vimInstance) throws VimDriverExce } amazon.getNetworks().clear(); amazon.addAllNetworks(newNetworks); - - List newFlavors = listFlavors(vimInstance); - if (amazon.getFlavours() == null) { - amazon.setFlavours(new HashSet<>()); - } - amazon.getFlavours().clear(); - amazon.getFlavours().addAll(newFlavors); - - List newAvalabilityZones = - listAvailabilityZone(vimInstance); - if (amazon.getZones() == null) { - amazon.setZones(new HashSet<>()); - } - amazon.getZones().clear(); - amazon.getZones().addAll(newAvalabilityZones); - - amazon.setVpcId(getVpcsMap(amazon).get(vimInstance.getVpcName()); + amazon.setVpcId(getVpcsMap(amazon).get(amazon.getVpcName())); return amazon; } @@ -404,7 +393,7 @@ private String imageExistsOnAWS(String nameId, AmazonEC2 client) throws AmazonCl * @return the list of interfaces */ private InstanceNetworkInterfaceSpecification createInterface( - Network net, int deviceIndex, Set secIDs) { + BaseNetwork net, int deviceIndex, Set secIDs) { InstanceNetworkInterfaceSpecification interSpec = new InstanceNetworkInterfaceSpecification() .withDeleteOnTermination(true) @@ -429,7 +418,7 @@ private InstanceNetworkInterfaceSpecification createInterface( * @param cps All connection points * @return subnets the instance is connected to */ - private List searchForRelevantSubnets(List nets, Set cps) { + private List searchForRelevantSubnets(List nets, Set cps) { log.info(nets.get(0).toString()); log.info(nets.get(1).toString()); ArrayList cpList = new ArrayList<>(cps); @@ -445,13 +434,13 @@ public int compare(VNFDConnectionPoint t, VNFDConnectionPoint t1) { } } }); - List relevantSubnets = new ArrayList<>(); + List relevantSubnets = new ArrayList<>(); for (VNFDConnectionPoint cp : cpList) { log.info("loop1"); - for (Network net : nets) { + for (BaseNetwork net : nets) { if (net.getName().equals(cp.getVirtual_link_reference())) { log.info("loop2"); - relevantSubnets.add(net); + relevantSubnets.add((AWSNetwork) net); } } } @@ -471,9 +460,9 @@ public int compare(VNFDConnectionPoint t, VNFDConnectionPoint t1) { */ private Set getSecurityIdFromName( Set groupNames, AmazonEC2 client, BaseVimInstance vimInstance) throws VimDriverException, AmazonClientException { - String vpcId = ((AmazonVimInstance) vimInstance).getVpcId; + String vpcId = ((AmazonVimInstance) vimInstance).getVpcId(); if (vpcId == null) { - throw new VimDriverException("No such VPC " + vimInstance.getTenant() + " exists"); + throw new VimDriverException("No such VPC " + ((AmazonVimInstance) vimInstance).getVpcName() + " exists"); } Filter filter = new Filter(); filter.setName("vpc-id"); @@ -493,7 +482,7 @@ private Set getSecurityIdFromName( groupIds.add(id); } else { throw new VimDriverException( - "No group " + name + "exists on VPC " + vimInstance.getTenant()); + "No group " + name + "exists on VPC " + ((AmazonVimInstance) vimInstance).getVpcName()); } } @@ -501,7 +490,7 @@ private Set getSecurityIdFromName( } @java.lang.Override - public java.util.List listImages(BaseVimInstance vimInstance) throws VimDriverException { + public java.util.List listImages(BaseVimInstance vimInstance) throws VimDriverException { try { AmazonEC2 client = createClient((AmazonVimInstance) vimInstance); String keyWord = properties.getProperty("image-key-word", "*"); @@ -515,7 +504,7 @@ public java.util.List listImages(BaseVimInstance vimInstance) throws V DescribeImagesRequest describeImagesRequest = new DescribeImagesRequest(); describeImagesRequest.setFilters(Arrays.asList(filter)); DescribeImagesResult describeImagesResult = client.describeImages(describeImagesRequest); - List images = new ArrayList<>(); + List images = new ArrayList<>(); for (Image image : describeImagesResult.getImages()) { images.add(Utils.getImage(image)); } @@ -550,7 +539,7 @@ public java.util.List listServer(BaseVimInstance vimInstanceBase) throws filter.setName("vpc-id"); filter.setValues(Arrays.asList(vpcId)); boolean done = false; - List nets = listNetworks(vimInstance); + List nets = listNetworks(vimInstance); while (!done) { DescribeInstancesRequest request = new DescribeInstancesRequest(); request.setFilters(Arrays.asList(filter)); @@ -573,13 +562,14 @@ public java.util.List listServer(BaseVimInstance vimInstanceBase) throws } @java.lang.Override - public java.util.List listNetworks(VimInstance vimInstance) throws VimDriverException { + public List listNetworks(BaseVimInstance vimInstanceBase) throws VimDriverException { log.info("Listing networks"); - List nfvoNetworks = new ArrayList<>(); + AmazonVimInstance vimInstance = (AmazonVimInstance) vimInstanceBase; + List nfvoNetworks = new ArrayList<>(); AmazonEC2 client = createClient(vimInstance); - String vpcId = getVpcsMap(vimInstance).get(vimInstance.getTenant()); + String vpcId = getVpcsMap(vimInstance).get(vimInstance.getVpcName()); if (vpcId == null) { - throw new VimDriverException("No such VPC " + vimInstance.getTenant() + " exists"); + throw new VimDriverException("No such VPC " + vimInstance.getVpcName() + " exists"); } Filter filter = new Filter(); filter.setName("vpc-id"); @@ -589,15 +579,14 @@ public java.util.List listNetworks(VimInstance vimInstance) throws VimD DescribeSubnetsResult subnetsResult = client.describeSubnets(describeSubnetsRequest); List subnets = subnetsResult.getSubnets(); for (Subnet subnet : subnets) { - nfvoNetworks.add(Utils.getNetworkFromSubnet(subnet)); + nfvoNetworks.add((BaseNetwork)Utils.getNetworkFromSubnet(subnet)); } return nfvoNetworks; } @java.lang.Override - public java.util.List listFlavors(VimInstance vimInstance) + public java.util.List listFlavors(BaseVimInstance vimInstanceBase) throws VimDriverException { - AmazonEC2 client = createClient(vimInstance); List flavours = new ArrayList<>(); for (InstanceType type : InstanceType.values()) { DeploymentFlavour flavour = new DeploymentFlavour(); @@ -610,7 +599,7 @@ public java.util.List listFlavors(VimInstance vimInstance) @java.lang.Override public Server launchInstanceAndWait( - VimInstance vimInstance, + BaseVimInstance vimInstance, String hostname, String image, String flavorExtId, @@ -631,7 +620,7 @@ public Server launchInstanceAndWait( @Override public Server launchInstanceAndWait( - VimInstance vimInstance, + BaseVimInstance vimInstance, String hostname, String image, String extId, @@ -654,10 +643,10 @@ public Server launchInstanceAndWait( } @java.lang.Override - public void deleteServerByIdAndWait(VimInstance vimInstance, String id) + public void deleteServerByIdAndWait(BaseVimInstance vimInstance, String id) throws VimDriverException { try { - AmazonEC2 client = createClient(vimInstance); + AmazonEC2 client = createClient((AmazonVimInstance) vimInstance); TerminateInstancesRequest req = new TerminateInstancesRequest().withInstanceIds(id); TerminateInstancesResult res = client.terminateInstances(req); } catch (AmazonClientException e) { @@ -667,44 +656,37 @@ public void deleteServerByIdAndWait(VimInstance vimInstance, String id) } @java.lang.Override - public Network createNetwork(VimInstance vimInstance, Network network) throws VimDriverException { - AmazonEC2 client = createClient(vimInstance); + public BaseNetwork createNetwork(BaseVimInstance vimInstanceBase, BaseNetwork networkBase) throws VimDriverException { + AmazonVimInstance vimInstance = (AmazonVimInstance) vimInstanceBase; + AWSNetwork network = (AWSNetwork) networkBase; + AmazonEC2 client = createClient(vimInstance); try { - String vpcId = getVpcsMap(vimInstance).get(vimInstance.getTenant()); + String vpcId = getVpcsMap(vimInstance).get(vimInstance.getVpcName()); if (vpcId == null) { - throw new VimDriverException("No such VPC " + vimInstance.getTenant() + " exists"); + throw new VimDriverException("No such VPC " + vimInstance.getVpcName() + " exists"); } CreateSubnetResult res; - try { - CreateSubnetRequest req = - new CreateSubnetRequest() - .withVpcId(vpcId) - .withCidrBlock(network.getSubnets().iterator().next().getCidr()); - res = client.createSubnet(req); - } catch (Exception e) { - log.debug("Provided CIDR is invalid, generating different one"); - DescribeVpcsRequest req = new DescribeVpcsRequest(); - DescribeVpcsResult resVpc = client.describeVpcs(req); - Vpc vpc = null; - for (Vpc vpc1 : resVpc.getVpcs()) { - if (vpc1.getVpcId().equals(vpcId)) { - vpc = vpc1; - } - } - if (vpc == null) { - throw new VimDriverException("The vpc with id " + vpcId + " might not exist anymore"); + log.debug("Generating CIDR"); + DescribeVpcsRequest req = new DescribeVpcsRequest(); + DescribeVpcsResult resVpc = client.describeVpcs(req); + Vpc vpc = null; + for (Vpc vpc1 : resVpc.getVpcs()) { + if (vpc1.getVpcId().equals(vpcId)) { + vpc = vpc1; } - String vpcCidr = vpc.getCidrBlock(); - String adrMask[] = vpcCidr.split("/"); - String adr[] = adrMask[0].split("…\\.")[0].split("\\."); - Random random = new Random(); - int number = random.nextInt(255); - String subnetCidr = adr[0] + "." + adr[1] + "." + number + "." + "0" + "/24"; - log.info("Generated CIDR " + subnetCidr); - CreateSubnetRequest newReq = - new CreateSubnetRequest().withVpcId(vpcId).withCidrBlock(subnetCidr); - res = client.createSubnet(newReq); } + if (vpc == null) { + throw new VimDriverException("The vpc with id " + vpcId + " might not exist anymore"); + } + String vpcCidr = vpc.getCidrBlock(); + String adrMask[] = vpcCidr.split("/"); + String adr[] = adrMask[0].split("…\\.")[0].split("\\."); + Random random = new Random(); + int number = random.nextInt(255); + String subnetCidr = adr[0] + "." + adr[1] + "." + number + "." + "0" + "/24"; + log.info("Generated CIDR " + subnetCidr); + CreateSubnetRequest newReq = new CreateSubnetRequest().withVpcId(vpcId).withCidrBlock(subnetCidr); + res = client.createSubnet(newReq); String id = res.getSubnet().getSubnetId(); List tags = new ArrayList<>(); Tag tag = new Tag(); @@ -713,11 +695,11 @@ public Network createNetwork(VimInstance vimInstance, Network network) throws Vi tags.add(tag); CreateTagsRequest tagsRequest = new CreateTagsRequest().withTags(tags).withResources(id); client.createTags(tagsRequest); - List nets = listNetworks(vimInstance); - Network returnNetwork = null; - for (Network net : nets) { + List nets = listNetworks(vimInstanceBase); + BaseNetwork returnNetwork = null; + for (BaseNetwork net : nets) { if (net.getExtId().equals(res.getSubnet().getSubnetId())) { - returnNetwork = net; + returnNetwork = net; } } @@ -728,7 +710,7 @@ public Network createNetwork(VimInstance vimInstance, Network network) throws Vi } } - private HashMap getVpcsMap(VimInstance vimInstance) throws VimDriverException { + private HashMap getVpcsMap(AmazonVimInstance vimInstance) throws VimDriverException { AmazonEC2 client = createClient(vimInstance); try { DescribeVpcsRequest describeVpcsRequest = new DescribeVpcsRequest(); @@ -752,16 +734,18 @@ private HashMap getVpcsMap(VimInstance vimInstance) throws VimDr } @java.lang.Override - public DeploymentFlavour addFlavor(VimInstance vimInstance, DeploymentFlavour deploymentFlavour) + public DeploymentFlavour addFlavor(BaseVimInstance vimInstance, DeploymentFlavour deploymentFlavour) throws VimDriverException { return null; } @java.lang.Override - public NFVImage addImage(VimInstance vimInstance, NFVImage image, byte[] imageFile) + public BaseNfvImage addImage(BaseVimInstance vimInstanceBase, BaseNfvImage imageBase, byte[] imageFile) throws VimDriverException { + AmazonVimInstance vimInstance = (AmazonVimInstance) vimInstanceBase; + AWSImage image = (AWSImage) imageBase; AmazonEC2 client = createClient(vimInstance); - NFVImage newImage; + AWSImage newImage; Filter filter = new Filter(); filter.setName("image-id"); filter.setValues(Arrays.asList(image.getName())); @@ -792,66 +776,46 @@ public NFVImage addImage(VimInstance vimInstance, NFVImage image, byte[] imageFi } @java.lang.Override - public NFVImage addImage(VimInstance vimInstance, NFVImage image, String image_url) + public BaseNfvImage addImage(BaseVimInstance vimInstance, BaseNfvImage image, String image_url) throws VimDriverException { return addImage(vimInstance, image, "".getBytes()); } @java.lang.Override - public NFVImage updateImage(VimInstance vimInstance, NFVImage image) throws VimDriverException { + public BaseNfvImage updateImage(BaseVimInstance vimInstance, BaseNfvImage image) throws VimDriverException { return addImage(vimInstance, image, "".getBytes()); } @java.lang.Override - public NFVImage copyImage(VimInstance vimInstance, NFVImage image, byte[] imageFile) + public BaseNfvImage copyImage(BaseVimInstance vimInstance, BaseNfvImage image, byte[] imageFile) throws VimDriverException { - AmazonEC2 client = createClient(vimInstance); return null; } @java.lang.Override - public boolean deleteImage(VimInstance vimInstance, NFVImage image) throws VimDriverException { - AmazonEC2 client = createClient(vimInstance); + public boolean deleteImage(BaseVimInstance vimInstance, BaseNfvImage image) throws VimDriverException { return false; } @java.lang.Override public DeploymentFlavour updateFlavor( - VimInstance vimInstance, DeploymentFlavour deploymentFlavour) throws VimDriverException { - AmazonEC2 client = createClient(vimInstance); + BaseVimInstance vimInstance, DeploymentFlavour deploymentFlavour) throws VimDriverException { + return null; } @java.lang.Override - public boolean deleteFlavor(VimInstance vimInstance, String extId) throws VimDriverException { - AmazonEC2 client = createClient(vimInstance); + public boolean deleteFlavor(BaseVimInstance vimInstance, String extId) throws VimDriverException { return false; } - /** - * This - * - * @param vimInstance - * @param createdNetwork - * @param subnet - * @return - * @throws VimDriverException - */ - @java.lang.Override - public org.openbaton.catalogue.nfvo.Subnet createSubnet( - VimInstance vimInstance, Network createdNetwork, org.openbaton.catalogue.nfvo.Subnet subnet) - throws VimDriverException { - log.info("Creating subnet " + subnet.getName() + " on by return the subnet:"); - log.info(createdNetwork.toString()); - org.openbaton.catalogue.nfvo.Subnet sub = new org.openbaton.catalogue.nfvo.Subnet(); - sub.setName(createdNetwork.getName() + "_subnet"); - sub.setExtId(createdNetwork.getExtId()); - sub.setCidr(createdNetwork.getSubnets().iterator().next().getCidr()); - sub.setNetworkId(createdNetwork.getExtId()); - return sub; - } + @Override + public org.openbaton.catalogue.nfvo.networks.Subnet createSubnet(BaseVimInstance vimInstance, BaseNetwork createdNetwork, org.openbaton.catalogue.nfvo.networks.Subnet subnet) throws VimDriverException { + return null; + } - /** + + /** * This is a stub that simply return the same network to avoid null pointer exceptions * * @param vimInstance vim @@ -859,45 +823,31 @@ public org.openbaton.catalogue.nfvo.Subnet createSubnet( * @return same network */ @java.lang.Override - public Network updateNetwork(VimInstance vimInstance, Network network) { + public BaseNetwork updateNetwork(BaseVimInstance vimInstance, BaseNetwork network) { log.info("Called the update network method which is not implemented"); return network; } - /** - * This is a stub that simply return the same network to avoid null pointer exceptions - * - * @param vimInstance vim - * @param subnet network data - * @return same network - */ - @java.lang.Override - public org.openbaton.catalogue.nfvo.Subnet updateSubnet( - VimInstance vimInstance, Network updatedNetwork, org.openbaton.catalogue.nfvo.Subnet subnet) { - log.info("Called the update subnet method which is not implemented"); - return subnet; - } + @Override + public org.openbaton.catalogue.nfvo.networks.Subnet updateSubnet(BaseVimInstance vimInstance, BaseNetwork updatedNetwork, org.openbaton.catalogue.nfvo.networks.Subnet subnet) throws VimDriverException { + return null; + } - @java.lang.Override - public java.util.List getSubnetsExtIds(VimInstance vimInstance, String network_extId) - throws VimDriverException { - List nets = listNetworks(vimInstance); - List ids = new ArrayList<>(); - for (Network net : nets) { - ids.add(net.getExtId()); + @Override + public List getSubnetsExtIds(BaseVimInstance vimInstance, String network_extId) throws VimDriverException { + return null; } - return ids; - } - @java.lang.Override - public boolean deleteSubnet(VimInstance vimInstance, String existingSubnetExtId) - throws VimDriverException { - return true; - } + @Override + public boolean deleteSubnet(BaseVimInstance vimInstance, String existingSubnetExtId) throws VimDriverException { + return false; + } - @java.lang.Override - public boolean deleteNetwork(VimInstance vimInstance, String extId) throws VimDriverException { + + @java.lang.Override + public boolean deleteNetwork(BaseVimInstance vimInstanceBase, String extId) throws VimDriverException { try { + AmazonVimInstance vimInstance = (AmazonVimInstance) vimInstanceBase; AmazonEC2 client = createClient(vimInstance); DeleteSubnetRequest req = new DeleteSubnetRequest().withSubnetId(extId); DeleteSubnetResult res = client.deleteSubnet(req); @@ -909,7 +859,8 @@ public boolean deleteNetwork(VimInstance vimInstance, String extId) throws VimDr } @java.lang.Override - public Network getNetworkById(VimInstance vimInstance, String id) throws VimDriverException { + public BaseNetwork getNetworkById(BaseVimInstance vimInstanceBase, String id) throws VimDriverException { + AmazonVimInstance vimInstance = (AmazonVimInstance) vimInstanceBase; AmazonEC2 client = createClient(vimInstance); try { Filter filter = new Filter(); @@ -928,7 +879,7 @@ public Network getNetworkById(VimInstance vimInstance, String id) throws VimDriv } @java.lang.Override - public Quota getQuota(VimInstance vimInstance) throws VimDriverException { + public Quota getQuota(BaseVimInstance vimInstance) throws VimDriverException { log.info("Returning fake quota"); Quota quota = new Quota(); quota.setCores(99999); @@ -939,7 +890,7 @@ public Quota getQuota(VimInstance vimInstance) throws VimDriverException { } @java.lang.Override - public String getType(VimInstance vimInstance) throws VimDriverException { + public String getType(BaseVimInstance vimInstance) throws VimDriverException { return "amazon"; } } diff --git a/src/main/java/org/openbaton/drivers/amazon/Utils.java b/src/main/java/org/openbaton/drivers/amazon/Utils.java index e4e2b0b..e7525dc 100644 --- a/src/main/java/org/openbaton/drivers/amazon/Utils.java +++ b/src/main/java/org/openbaton/drivers/amazon/Utils.java @@ -4,12 +4,15 @@ import java.util.*; import org.openbaton.catalogue.nfvo.images.AWSImage; import org.openbaton.catalogue.nfvo.Server; +import org.openbaton.catalogue.nfvo.networks.AWSNetwork; +import org.openbaton.catalogue.nfvo.networks.BaseNetwork; +import org.openbaton.catalogue.nfvo.networks.Network; import org.slf4j.Logger; import org.slf4j.LoggerFactory; class Utils { - static org.openbaton.catalogue.nfvo.Server getServer(Instance instance, List nets) { + static org.openbaton.catalogue.nfvo.Server getServer(Instance instance, List nets) { Server server = new Server(); server.setExtId(instance.getInstanceId()); server.setStatus(instance.getState().getName()); @@ -25,12 +28,12 @@ static org.openbaton.catalogue.nfvo.Server getServer(Instance instance, List netNameId = new HashMap<>(); - for (Network net : nets) { + for (BaseNetwork net : nets) { netNameId.put(net.getExtId(), net.getName()); } String primarySubnetId = instance.getSubnetId(); String primarySubnetName = ""; - for (Network net : nets) { + for (BaseNetwork net : nets) { if (net.getExtId().equals(primarySubnetId)) { primarySubnetName = net.getName(); } @@ -78,34 +81,33 @@ static org.openbaton.catalogue.nfvo.Server getServer(Instance instance, List subs = new HashSet<>(); - Subnet sub = new Subnet(); - sub.setExtId(subnet.getSubnetId()); - sub.setCidr(subnet.getCidrBlock()); - sub.setNetworkId(subnet.getSubnetId()); - subs.add(sub); - nfvoNetwork.setSubnets(subs); + nfvoNetwork.setIpv4cidr(subnet.getCidrBlock()); + nfvoNetwork.setAvZone(subnet.getAvailabilityZone()); + nfvoNetwork.setExtId(subnet.getSubnetId()); + nfvoNetwork.setVpcId(subnet.getVpcId()); + nfvoNetwork.setState(subnet.getState()); + nfvoNetwork.setDef(subnet.getDefaultForAz()); return nfvoNetwork; } static org.openbaton.catalogue.nfvo.images.AWSImage getImage( com.amazonaws.services.ec2.model.Image image) { AWSImage nfvoImage = new AWSImage(); - AWSImage.setName(image.getName()); - AWSImage.setExtId(image.getImageId()); - AWSImage.setHypervisor(image.getHypervisor()); - AWSImage.setDescripton(image.getDescription()); - AWSImage.setImageOwner(image.getImageOwnerAlias()); - AWSImage.setPublic(image.getPublic()); + nfvoImage.setName(image.getName()); + nfvoImage.setExtId(image.getImageId()); + nfvoImage.setHypervisor(image.getHypervisor()); + nfvoImage.setDescription(image.getDescription()); + nfvoImage.setImageOwner(image.getImageOwnerAlias()); + nfvoImage.setPublic(image.getPublic()); return nfvoImage; } } From 99614ea7fba350bad4fac9bcd66dfe2dde325426 Mon Sep 17 00:00:00 2001 From: Oleksander Gozman Date: Tue, 19 Dec 2017 14:18:50 +0100 Subject: [PATCH 07/10] fea: move to new catalogue in progress --- .../drivers/amazon/AmazonDriver.java | 24 ++++++++++++------- .../org/openbaton/drivers/amazon/Utils.java | 4 ++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/openbaton/drivers/amazon/AmazonDriver.java b/src/main/java/org/openbaton/drivers/amazon/AmazonDriver.java index 507f92b..0bf0059 100644 --- a/src/main/java/org/openbaton/drivers/amazon/AmazonDriver.java +++ b/src/main/java/org/openbaton/drivers/amazon/AmazonDriver.java @@ -69,7 +69,8 @@ public static void main(String[] args) - if (args.length == 4) { + + if (args.length == 4) { log.info("Starting the plugin with CUSTOM parameters: "); log.info("name: " + args[0]); log.info("brokerIp: " + args[1]); @@ -123,7 +124,7 @@ private AmazonEC2 createClient(AmazonVimInstance vimInstance) throws VimDriverEx Regions regions; AmazonEC2 client; try { - regions = Regions.fromName(vimInstance.getLocation().getName()); + regions = Regions.fromName(vimInstance.getRegion()); client = AmazonEC2ClientBuilder.standard() .withRegion(regions) @@ -249,7 +250,7 @@ public BaseVimInstance refresh(BaseVimInstance vimInstance) throws VimDriverExce if (amazon.getImages() == null) { amazon.setImages(new HashSet<>()); } - amazon.getImages().clear(); + amazon.removeAllImages(); amazon.addAllImages(newImages); List newNetworks = listNetworks(vimInstance); @@ -257,11 +258,17 @@ public BaseVimInstance refresh(BaseVimInstance vimInstance) throws VimDriverExce if (amazon.getNetworks() == null) { amazon.setNetworks(new HashSet<>()); } - amazon.getNetworks().clear(); + amazon.removeAllNetworks(); amazon.addAllNetworks(newNetworks); amazon.setVpcId(getVpcsMap(amazon).get(amazon.getVpcName())); - return amazon; + List newFlavors = listFlavors(vimInstance); + if (amazon.getFlavours() == null) { + amazon.setFlavours(new HashSet<>()); + } + amazon.removeAllFlavours(); + amazon.addAllFlavours(newFlavors); + return (BaseVimInstance) amazon; } @@ -453,14 +460,15 @@ public int compare(VNFDConnectionPoint t, VNFDConnectionPoint t1) { * * @param groupNames Group names that come from NFVO * @param client ec2 client - * @param vimInstance vim description + * @param vimInstanceBase vim description * @return list of the security groups ids * @throws VimDriverException in case there is no VPC with such name or one of the security groups * does not exits */ private Set getSecurityIdFromName( - Set groupNames, AmazonEC2 client, BaseVimInstance vimInstance) throws VimDriverException, AmazonClientException { - String vpcId = ((AmazonVimInstance) vimInstance).getVpcId(); + Set groupNames, AmazonEC2 client, BaseVimInstance vimInstanceBase) throws VimDriverException, AmazonClientException { + AmazonVimInstance vimInstance = (AmazonVimInstance) vimInstanceBase; + String vpcId = getVpcsMap(vimInstance).get(vimInstance.getVpcName()); if (vpcId == null) { throw new VimDriverException("No such VPC " + ((AmazonVimInstance) vimInstance).getVpcName() + " exists"); } diff --git a/src/main/java/org/openbaton/drivers/amazon/Utils.java b/src/main/java/org/openbaton/drivers/amazon/Utils.java index e7525dc..ce19d81 100644 --- a/src/main/java/org/openbaton/drivers/amazon/Utils.java +++ b/src/main/java/org/openbaton/drivers/amazon/Utils.java @@ -4,6 +4,7 @@ import java.util.*; import org.openbaton.catalogue.nfvo.images.AWSImage; import org.openbaton.catalogue.nfvo.Server; +import org.openbaton.catalogue.nfvo.images.NFVImage; import org.openbaton.catalogue.nfvo.networks.AWSNetwork; import org.openbaton.catalogue.nfvo.networks.BaseNetwork; import org.openbaton.catalogue.nfvo.networks.Network; @@ -18,6 +19,9 @@ static org.openbaton.catalogue.nfvo.Server getServer(Instance instance, List Date: Wed, 17 Jan 2018 14:03:57 +0100 Subject: [PATCH 08/10] fea: move to new catalogue, assign non-elastic public ips if possible --- .../drivers/amazon/AmazonDriver.java | 741 ++++++++++-------- .../org/openbaton/drivers/amazon/Utils.java | 11 +- 2 files changed, 411 insertions(+), 341 deletions(-) diff --git a/src/main/java/org/openbaton/drivers/amazon/AmazonDriver.java b/src/main/java/org/openbaton/drivers/amazon/AmazonDriver.java index 0bf0059..428fdd5 100644 --- a/src/main/java/org/openbaton/drivers/amazon/AmazonDriver.java +++ b/src/main/java/org/openbaton/drivers/amazon/AmazonDriver.java @@ -17,7 +17,6 @@ package org.openbaton.drivers.amazon; import com.amazonaws.AmazonClientException; -import com.amazonaws.AmazonServiceException; import com.amazonaws.auth.AWSStaticCredentialsProvider; import com.amazonaws.auth.BasicAWSCredentials; import com.amazonaws.regions.Regions; @@ -26,7 +25,6 @@ import com.amazonaws.services.ec2.model.*; import com.amazonaws.services.ec2.model.InstanceType; import com.amazonaws.services.ec2.model.Subnet; -import com.fasterxml.jackson.databind.ser.Serializers; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import java.io.IOException; @@ -43,10 +41,10 @@ import org.openbaton.catalogue.nfvo.*; import org.openbaton.catalogue.nfvo.images.AWSImage; import org.openbaton.catalogue.nfvo.images.BaseNfvImage; +import org.openbaton.catalogue.nfvo.networks.AWSNetwork; import org.openbaton.catalogue.nfvo.networks.BaseNetwork; -import org.openbaton.catalogue.nfvo.viminstances.BaseVimInstance; import org.openbaton.catalogue.nfvo.viminstances.AmazonVimInstance; -import org.openbaton.catalogue.nfvo.networks.AWSNetwork; +import org.openbaton.catalogue.nfvo.viminstances.BaseVimInstance; import org.openbaton.catalogue.security.Key; import org.openbaton.exceptions.VimDriverException; import org.openbaton.exceptions.VimException; @@ -67,10 +65,7 @@ public static void main(String[] args) throws NoSuchMethodException, IOException, InstantiationException, TimeoutException, IllegalAccessException, InvocationTargetException, InterruptedException { - - - - if (args.length == 4) { + if (args.length == 4) { log.info("Starting the plugin with CUSTOM parameters: "); log.info("name: " + args[0]); log.info("brokerIp: " + args[1]); @@ -128,7 +123,6 @@ private AmazonEC2 createClient(AmazonVimInstance vimInstance) throws VimDriverEx client = AmazonEC2ClientBuilder.standard() .withRegion(regions) - .withCredentials(new AWSStaticCredentialsProvider(awsCreds)) .build(); } catch (IllegalArgumentException e) { @@ -153,9 +147,8 @@ public Server launchInstance( log.info("Launching instance " + name); Server server = null; try { - AmazonVimInstance vimInstance = (AmazonVimInstance) vimInstanceBase; + AmazonVimInstance vimInstance = (AmazonVimInstance) vimInstanceBase; String changeUserData = changeHostname(userData, name); - log.info(changeUserData); AmazonEC2 client = createClient(vimInstance); Gson gson = new Gson(); String oldVNFDCP = gson.toJson(networks); @@ -176,10 +169,15 @@ public Server launchInstance( Set groupIds = getSecurityIdFromName(secGroup, client, vimInstance); log.info("Retrieved security ids"); int deviceIndex = 0; - for (BaseNetwork net : searchForRelevantSubnets(presentSubnets, newNetworks)) { - inters.add(createInterface(net, deviceIndex, groupIds)); - deviceIndex++; - log.info("Interface " + deviceIndex); + List relevantSubnets = searchForRelevantSubnets(presentSubnets, newNetworks); + if (relevantSubnets.size() < 2) { + inters.add(createInterfaceWithPublicIp(relevantSubnets.get(0), 0, groupIds)); + } else { + for (BaseNetwork net : relevantSubnets) { + inters.add(createInterface(net, deviceIndex, groupIds)); + deviceIndex++; + log.info("Interface " + deviceIndex); + } } log.info("Created interfaces"); String amiID = imageExistsOnAWS(image, client); @@ -217,27 +215,27 @@ public Server launchInstance( tags.add(tag); CreateTagsRequest tagsRequest = new CreateTagsRequest().withTags(tags).withResources(id); client.createTags(tagsRequest); - server = waitForInstance(name, vimInstance); log.info("Instance is up, handling networking"); - setupInstanceNetwork(client, server); + if (networks.size() > 1) { + server = waitForInstance(name, vimInstance); + setupInstanceNetwork(client, server); + } List servers = listServer(vimInstance); - for (Server ser : servers) { - if (ser != null && ser.getHostName().equals(name)) { - server = ser; - } + for (Server ser : servers) { + if (ser != null && ser.getHostName().equals(name)) { + server = ser; } + } } catch (VimException e) { log.error(e.getMessage(), e); - VimDriverException vimDriverException = new VimDriverException(e.getMessage()); - throw vimDriverException; + throw new VimDriverException(e.getMessage()); } catch (UnsupportedEncodingException e) { - VimDriverException vimDriverException = new VimDriverException(e.getMessage()); - throw vimDriverException; + throw new VimDriverException(e.getMessage()); } catch (AmazonClientException e) { - VimDriverException vimDriverException = new VimDriverException(e.getMessage()); - throw vimDriverException; + log.info("Amazon has thrown an exception: " + e.getMessage()); + throw new VimDriverException(e.getMessage()); } catch (InterruptedException e) { - throw new VimDriverException(e.getMessage()); + throw new VimDriverException(e.getMessage()); } log.info("Instance " + name + " launched"); return server; @@ -245,122 +243,138 @@ public Server launchInstance( @Override public BaseVimInstance refresh(BaseVimInstance vimInstance) throws VimDriverException { - AmazonVimInstance amazon = (AmazonVimInstance) vimInstance; - List newImages = listImages(vimInstance); - if (amazon.getImages() == null) { - amazon.setImages(new HashSet<>()); - } - amazon.removeAllImages(); - amazon.addAllImages(newImages); + AmazonVimInstance amazon = (AmazonVimInstance) vimInstance; + List newImages = listImages(vimInstance); + if (amazon.getImages() == null) { + amazon.setImages(new HashSet<>()); + } + amazon.removeAllImages(); + amazon.addAllImages(newImages); - List newNetworks = listNetworks(vimInstance); + List newNetworks = listNetworks(vimInstance); - if (amazon.getNetworks() == null) { - amazon.setNetworks(new HashSet<>()); - } - amazon.removeAllNetworks(); - amazon.addAllNetworks(newNetworks); - amazon.setVpcId(getVpcsMap(amazon).get(amazon.getVpcName())); + if (amazon.getNetworks() == null) { + amazon.setNetworks(new HashSet<>()); + } + amazon.removeAllNetworks(); + amazon.addAllNetworks(newNetworks); + amazon.setVpcId(getVpcsMap(amazon).get(amazon.getVpcName())); - List newFlavors = listFlavors(vimInstance); - if (amazon.getFlavours() == null) { - amazon.setFlavours(new HashSet<>()); - } - amazon.removeAllFlavours(); - amazon.addAllFlavours(newFlavors); - return (BaseVimInstance) amazon; - } - - - private Server waitForInstance(String name, BaseVimInstance vimInstance) throws VimDriverException, InterruptedException { - int timeOut = Integer.parseInt(properties.getProperty("launchTimeout")); - log.info("Waiting for instance. LaunchTimeout is " + timeOut); - int waitTime = 4; - while (waitTime < timeOut) { - List servers = listServer(vimInstance); - for (Server ser : servers) { - if (ser != null && ser.getHostName().equals(name) && ser.getStatus().equals("running")) { - return ser; - } - try { - TimeUnit.SECONDS.sleep(waitTime); - waitTime = waitTime * 2; - } catch (InterruptedException e) { - e.printStackTrace(); - } - } + List newFlavors = listFlavors(vimInstance); + if (amazon.getFlavours() == null) { + amazon.setFlavours(new HashSet<>()); + } + amazon.removeAllFlavours(); + amazon.addAllFlavours(newFlavors); + return (BaseVimInstance) amazon; + } + + private Server waitForInstance(String name, BaseVimInstance vimInstance) + throws VimDriverException, InterruptedException { + int timeOut = Integer.parseInt(properties.getProperty("launchTimeout")); + log.info("Waiting for instance. LaunchTimeout is " + timeOut); + int waitTime = 4; + while (waitTime < timeOut) { + List servers = listServer(vimInstance); + for (Server ser : servers) { + if (ser != null && ser.getHostName().equals(name) && ser.getStatus().equals("running")) { + return ser; + } + try { + TimeUnit.SECONDS.sleep(waitTime); + waitTime = waitTime * 2; + } catch (InterruptedException e) { + e.printStackTrace(); + } } - throw new VimDriverException("Launch Timeout reached, seems that the instance never went into running status"); + } + throw new VimDriverException( + "Launch Timeout reached, seems that the instance never went into running status"); } private void setupInstanceNetwork(AmazonEC2 client, Server server) { - List
freeAddresses = getUnallocatedAddresses(client); - List instanceInterfaces = listInterfaceByAttachment(client, server.getExtId()); + List
freeAddresses = getUnallocatedAddresses(client); + List instanceInterfaces = + listInterfaceByAttachment(client, server.getExtId()); - if (freeAddresses.size() < instanceInterfaces.size()) { - allocateElasticIps(client, instanceInterfaces.size() - freeAddresses.size()); - } - freeAddresses = getUnallocatedAddresses(client); - int i = 0; - for (NetworkInterface inter: instanceInterfaces) { - AssociateAddressRequest addrReq = new AssociateAddressRequest().withNetworkInterfaceId(inter.getNetworkInterfaceId()) - .withAllocationId(freeAddresses.get(i).getAllocationId()).withAllowReassociation(false); - client.associateAddress(addrReq); - i++; - } + if (freeAddresses.size() < instanceInterfaces.size()) { + allocateElasticIps(client, instanceInterfaces.size() - freeAddresses.size()); + } + freeAddresses = getUnallocatedAddresses(client); + int i = 0; + for (NetworkInterface inter : instanceInterfaces) { + AssociateAddressRequest addrReq = + new AssociateAddressRequest() + .withNetworkInterfaceId(inter.getNetworkInterfaceId()) + .withAllocationId(freeAddresses.get(i).getAllocationId()) + .withAllowReassociation(false); + client.associateAddress(addrReq); + i++; + } } private void allocateElasticIps(AmazonEC2 client, int number) { - log.info("Allocating " + number + " elastic ips"); - AllocateAddressRequest req = new AllocateAddressRequest(); - for (int i = 0; i < number; i++) { - client.allocateAddress(req); - } + log.info("Allocating " + number + " elastic ips"); + AllocateAddressRequest req = new AllocateAddressRequest(); + for (int i = 0; i < number; i++) { + client.allocateAddress(req); + } } private List
getUnallocatedAddresses(AmazonEC2 client) { - DescribeAddressesRequest addReq = new DescribeAddressesRequest(); - DescribeAddressesResult re = client.describeAddresses(addReq); - List
unAllockAddrs = new ArrayList<>(); - for (Address addr: re.getAddresses()) { - if (addr.getAssociationId() == null) { - unAllockAddrs.add(addr); - } + DescribeAddressesRequest addReq = new DescribeAddressesRequest(); + DescribeAddressesResult re = client.describeAddresses(addReq); + List
unAllockAddrs = new ArrayList<>(); + for (Address addr : re.getAddresses()) { + if (addr.getAssociationId() == null) { + unAllockAddrs.add(addr); } - return unAllockAddrs; - + } + return unAllockAddrs; } private List listInterfaceByAttachment(AmazonEC2 client, String instanceId) { - Filter filter = new Filter(); - filter.setName("attachment.instance-id"); - filter.setValues(Collections.singletonList(instanceId)); - Filter filter1 = new Filter(); -// filter1.setName("attachment.device-index"); -// filter1.setValues(Collections.singletonList("0")); -// -// DescribeNetworkInterfacesRequest req = new DescribeNetworkInterfacesRequest().withFilters(Arrays.asList(filter, filter1)); - DescribeNetworkInterfacesRequest req = new DescribeNetworkInterfacesRequest().withFilters(Collections.singletonList(filter)); - DescribeNetworkInterfacesResult res = client.describeNetworkInterfaces(req); - return res.getNetworkInterfaces(); + Filter filter = new Filter(); + filter.setName("attachment.instance-id"); + filter.setValues(Collections.singletonList(instanceId)); + Filter filter1 = new Filter(); + // filter1.setName("attachment.device-index"); + // filter1.setValues(Collections.singletonList("0")); + // + // DescribeNetworkInterfacesRequest req = new DescribeNetworkInterfacesRequest().withFilters(Arrays.asList(filter, filter1)); + DescribeNetworkInterfacesRequest req = + new DescribeNetworkInterfacesRequest().withFilters(Collections.singletonList(filter)); + DescribeNetworkInterfacesResult res = client.describeNetworkInterfaces(req); + return res.getNetworkInterfaces(); } + private List getInternetGatewaysByVPC(AmazonEC2 client, String vpcId) { - Filter filter = new Filter(); - filter.setName("attachment.vpc-id"); - filter.setValues(Collections.singletonList(vpcId)); - DescribeInternetGatewaysRequest request = new DescribeInternetGatewaysRequest(); - request.setFilters(Collections.singletonList(filter)); - DescribeInternetGatewaysResult result = client.describeInternetGateways(request); - return result.getInternetGateways(); + Filter filter = new Filter(); + filter.setName("attachment.vpc-id"); + filter.setValues(Collections.singletonList(vpcId)); + DescribeInternetGatewaysRequest request = new DescribeInternetGatewaysRequest(); + request.setFilters(Collections.singletonList(filter)); + DescribeInternetGatewaysResult result = client.describeInternetGateways(request); + return result.getInternetGateways(); } + /** + * Creates the internet gateway in a particaular vpc + * + * @param client amazon client to make calls to api + * @param vpcId the id of the VPC where gateway should be attached + * @return + */ private InternetGateway createAndAttachInternetGateway(AmazonEC2 client, String vpcId) { - CreateInternetGatewayRequest request = new CreateInternetGatewayRequest(); - CreateInternetGatewayResult result = client.createInternetGateway(request); - InternetGateway gateway = result.getInternetGateway(); - AttachInternetGatewayRequest attach = new AttachInternetGatewayRequest().withVpcId(vpcId).withInternetGatewayId(gateway.getInternetGatewayId()); - client.attachInternetGateway(attach); - return gateway; + CreateInternetGatewayRequest request = new CreateInternetGatewayRequest(); + CreateInternetGatewayResult result = client.createInternetGateway(request); + InternetGateway gateway = result.getInternetGateway(); + AttachInternetGatewayRequest attach = + new AttachInternetGatewayRequest() + .withVpcId(vpcId) + .withInternetGatewayId(gateway.getInternetGatewayId()); + client.attachInternetGateway(attach); + return gateway; } /** @@ -392,22 +406,53 @@ private String imageExistsOnAWS(String nameId, AmazonEC2 client) throws AmazonCl } /** - * Creates an interface for the instance in order to connect to subnet. Cross checks for floating - * ips and enables it if necessary. Currently supports only random floating ips. - * + * Creates an interface for the instance in order to connect to subnet. Does not assign floating ip, + * this method is used in case multiple interfaces are supposed to be created for on instance. Elastic ips + * are then assgined after creation. * @param net subnet inside AWS represented through NFVO network * @param deviceIndex device index for the interface is required by AWS + * @param secIDs security group ID * @return the list of interfaces */ private InstanceNetworkInterfaceSpecification createInterface( BaseNetwork net, int deviceIndex, Set secIDs) { - InstanceNetworkInterfaceSpecification interSpec = - new InstanceNetworkInterfaceSpecification() - .withDeleteOnTermination(true) - .withSubnetId(net.getExtId()) - .withGroups(secIDs).withDeviceIndex(deviceIndex); - log.info("Device index" + deviceIndex); - return interSpec; + InstanceNetworkInterfaceSpecification interSpec = + new InstanceNetworkInterfaceSpecification() + .withDeleteOnTermination(true) + .withSubnetId(net.getExtId()) + .withGroups(secIDs) + .withDeviceIndex(deviceIndex); + log.info("Device index" + deviceIndex); + return interSpec; + + /*String floatingIp = ""; + for (VNFDConnectionPoint cp : cps) { + if (net.getName().equals(cp.getVirtual_link_reference())) { + floatingIp = cp.getFloatingIp(); + } + }*/ + + } + + /** + * Creates an interface for the instance in order to connect to subnet and assigns public ip to it connecting + * the instance to internet. Used only if the instance has no more than one network interface. It is made in order + * to conserve the limited amount of elastic ips on AWS (5 only generally) and not use them if not necessary. + * @param net subnet inside AWS represented through NFVO network + * @param deviceIndex device index for the interface is required by AWS + * @param secIDs security group ID + * @return + */ + private InstanceNetworkInterfaceSpecification createInterfaceWithPublicIp( + BaseNetwork net, int deviceIndex, Set secIDs) { + InstanceNetworkInterfaceSpecification interSpec = + new InstanceNetworkInterfaceSpecification() + .withDeleteOnTermination(true) + .withSubnetId(net.getExtId()) + .withGroups(secIDs) + .withDeviceIndex(deviceIndex).withAssociatePublicIpAddress(true); + log.info("Device index" + deviceIndex); + return interSpec; /*String floatingIp = ""; for (VNFDConnectionPoint cp : cps) { @@ -425,28 +470,28 @@ private InstanceNetworkInterfaceSpecification createInterface( * @param cps All connection points * @return subnets the instance is connected to */ - private List searchForRelevantSubnets(List nets, Set cps) { - log.info(nets.get(0).toString()); - log.info(nets.get(1).toString()); - ArrayList cpList = new ArrayList<>(cps); - Collections.sort(cpList, new Comparator() { - @Override - public int compare(VNFDConnectionPoint t, VNFDConnectionPoint t1) { + private List searchForRelevantSubnets( + List nets, Set cps) { + ArrayList cpList = new ArrayList<>(cps); + Collections.sort( + cpList, + new Comparator() { + @Override + public int compare(VNFDConnectionPoint t, VNFDConnectionPoint t1) { if (t.getInterfaceId() > t1.getInterfaceId()) { - return -1; - } if (t.getInterfaceId() == t1.getInterfaceId()) { - return 0; + return -1; + } + if (t.getInterfaceId() == t1.getInterfaceId()) { + return 0; } else { - return 1; + return 1; } - } - }); + } + }); List relevantSubnets = new ArrayList<>(); for (VNFDConnectionPoint cp : cpList) { - log.info("loop1"); for (BaseNetwork net : nets) { if (net.getName().equals(cp.getVirtual_link_reference())) { - log.info("loop2"); relevantSubnets.add((AWSNetwork) net); } } @@ -466,11 +511,13 @@ public int compare(VNFDConnectionPoint t, VNFDConnectionPoint t1) { * does not exits */ private Set getSecurityIdFromName( - Set groupNames, AmazonEC2 client, BaseVimInstance vimInstanceBase) throws VimDriverException, AmazonClientException { - AmazonVimInstance vimInstance = (AmazonVimInstance) vimInstanceBase; - String vpcId = getVpcsMap(vimInstance).get(vimInstance.getVpcName()); + Set groupNames, AmazonEC2 client, BaseVimInstance vimInstanceBase) + throws VimDriverException, AmazonClientException { + AmazonVimInstance vimInstance = (AmazonVimInstance) vimInstanceBase; + String vpcId = getVpcsMap(vimInstance).get(vimInstance.getVpcName()); if (vpcId == null) { - throw new VimDriverException("No such VPC " + ((AmazonVimInstance) vimInstance).getVpcName() + " exists"); + throw new VimDriverException( + "No such VPC " + ((AmazonVimInstance) vimInstance).getVpcName() + " exists"); } Filter filter = new Filter(); filter.setName("vpc-id"); @@ -498,80 +545,81 @@ private Set getSecurityIdFromName( } @java.lang.Override - public java.util.List listImages(BaseVimInstance vimInstance) throws VimDriverException { - try { - AmazonEC2 client = createClient((AmazonVimInstance) vimInstance); - String keyWord = properties.getProperty("image-key-word", "*"); - String keyWords[] = keyWord.split(","); - for (int i = 0; i < keyWords.length; i++) { - keyWords[i] = "*" + keyWords[i] + "*"; - } - Filter filter = new Filter(); - filter.setName("name"); - filter.setValues(Arrays.asList(keyWords)); - DescribeImagesRequest describeImagesRequest = new DescribeImagesRequest(); - describeImagesRequest.setFilters(Arrays.asList(filter)); - DescribeImagesResult describeImagesResult = client.describeImages(describeImagesRequest); - List images = new ArrayList<>(); - for (Image image : describeImagesResult.getImages()) { - images.add(Utils.getImage(image)); - } - filter.setName("image-id"); - filter.setValues(Arrays.asList(keyWords)); - describeImagesRequest = new DescribeImagesRequest(); - describeImagesRequest.setFilters(Arrays.asList(filter)); - describeImagesResult = client.describeImages(describeImagesRequest); - for (Image image : describeImagesResult.getImages()) { - images.add(Utils.getImage(image)); - } - - return images; - } catch (AmazonClientException e) { - VimDriverException vimDriverException = new VimDriverException(e.getMessage()); - throw vimDriverException; + public java.util.List listImages(BaseVimInstance vimInstance) + throws VimDriverException { + try { + AmazonEC2 client = createClient((AmazonVimInstance) vimInstance); + String keyWord = properties.getProperty("image-key-word", "*"); + String keyWords[] = keyWord.split(","); + for (int i = 0; i < keyWords.length; i++) { + keyWords[i] = "*" + keyWords[i] + "*"; + } + Filter filter = new Filter(); + filter.setName("name"); + filter.setValues(Arrays.asList(keyWords)); + DescribeImagesRequest describeImagesRequest = new DescribeImagesRequest(); + describeImagesRequest.setFilters(Arrays.asList(filter)); + DescribeImagesResult describeImagesResult = client.describeImages(describeImagesRequest); + List images = new ArrayList<>(); + for (Image image : describeImagesResult.getImages()) { + images.add(Utils.getImage(image)); + } + filter.setName("image-id"); + filter.setValues(Arrays.asList(keyWords)); + describeImagesRequest = new DescribeImagesRequest(); + describeImagesRequest.setFilters(Arrays.asList(filter)); + describeImagesResult = client.describeImages(describeImagesRequest); + for (Image image : describeImagesResult.getImages()) { + images.add(Utils.getImage(image)); } + return images; + } catch (AmazonClientException e) { + VimDriverException vimDriverException = new VimDriverException(e.getMessage()); + throw vimDriverException; + } } @java.lang.Override - public java.util.List listServer(BaseVimInstance vimInstanceBase) throws VimDriverException { - AmazonVimInstance vimInstance = (AmazonVimInstance) vimInstanceBase; - try { - List servers = new ArrayList<>(); - AmazonEC2 client = createClient(vimInstance); - String vpcId = getVpcsMap(vimInstance).get(vimInstance.getVpcName()); - if (vpcId == null) { - throw new VimDriverException("No such VPC " + vimInstance.getVpcName() + " exists"); - } - Filter filter = new Filter(); - filter.setName("vpc-id"); - filter.setValues(Arrays.asList(vpcId)); - boolean done = false; - List nets = listNetworks(vimInstance); - while (!done) { - DescribeInstancesRequest request = new DescribeInstancesRequest(); - request.setFilters(Arrays.asList(filter)); - DescribeInstancesResult response = client.describeInstances(request); - for (Reservation reservation : response.getReservations()) { - for (Instance instance : reservation.getInstances()) { - servers.add(Utils.getServer(instance, nets)); - } - } - request.setNextToken(response.getNextToken()); - if (response.getNextToken() == null) { - done = true; - } + public java.util.List listServer(BaseVimInstance vimInstanceBase) + throws VimDriverException { + AmazonVimInstance vimInstance = (AmazonVimInstance) vimInstanceBase; + try { + List servers = new ArrayList<>(); + AmazonEC2 client = createClient(vimInstance); + String vpcId = getVpcsMap(vimInstance).get(vimInstance.getVpcName()); + if (vpcId == null) { + throw new VimDriverException("No such VPC " + vimInstance.getVpcName() + " exists"); + } + Filter filter = new Filter(); + filter.setName("vpc-id"); + filter.setValues(Arrays.asList(vpcId)); + boolean done = false; + List nets = listNetworks(vimInstance); + while (!done) { + DescribeInstancesRequest request = new DescribeInstancesRequest(); + request.setFilters(Arrays.asList(filter)); + DescribeInstancesResult response = client.describeInstances(request); + for (Reservation reservation : response.getReservations()) { + for (Instance instance : reservation.getInstances()) { + servers.add(Utils.getServer(instance, nets)); } - return servers; - } catch (AmazonClientException e) { - VimDriverException vimDriverException = new VimDriverException(e.getMessage()); - throw vimDriverException; + } + request.setNextToken(response.getNextToken()); + if (response.getNextToken() == null) { + done = true; + } } + return servers; + } catch (AmazonClientException e) { + VimDriverException vimDriverException = new VimDriverException(e.getMessage()); + throw vimDriverException; + } } @java.lang.Override public List listNetworks(BaseVimInstance vimInstanceBase) throws VimDriverException { - log.info("Listing networks"); + log.info("Listing networks"); AmazonVimInstance vimInstance = (AmazonVimInstance) vimInstanceBase; List nfvoNetworks = new ArrayList<>(); AmazonEC2 client = createClient(vimInstance); @@ -587,7 +635,7 @@ public List listNetworks(BaseVimInstance vimInstanceBase) throws Vi DescribeSubnetsResult subnetsResult = client.describeSubnets(describeSubnetsRequest); List subnets = subnetsResult.getSubnets(); for (Subnet subnet : subnets) { - nfvoNetworks.add((BaseNetwork)Utils.getNetworkFromSubnet(subnet)); + nfvoNetworks.add((BaseNetwork) Utils.getNetworkFromSubnet(subnet)); } return nfvoNetworks; } @@ -653,102 +701,111 @@ public Server launchInstanceAndWait( @java.lang.Override public void deleteServerByIdAndWait(BaseVimInstance vimInstance, String id) throws VimDriverException { - try { - AmazonEC2 client = createClient((AmazonVimInstance) vimInstance); - TerminateInstancesRequest req = new TerminateInstancesRequest().withInstanceIds(id); - TerminateInstancesResult res = client.terminateInstances(req); - } catch (AmazonClientException e) { - VimDriverException vimDriverException = new VimDriverException(e.getMessage()); - throw vimDriverException; - } + try { + AmazonEC2 client = createClient((AmazonVimInstance) vimInstance); + TerminateInstancesRequest req = new TerminateInstancesRequest().withInstanceIds(id); + TerminateInstancesResult res = client.terminateInstances(req); + } catch (AmazonClientException e) { + VimDriverException vimDriverException = new VimDriverException(e.getMessage()); + throw vimDriverException; + } } @java.lang.Override - public BaseNetwork createNetwork(BaseVimInstance vimInstanceBase, BaseNetwork networkBase) throws VimDriverException { - AmazonVimInstance vimInstance = (AmazonVimInstance) vimInstanceBase; - AWSNetwork network = (AWSNetwork) networkBase; - AmazonEC2 client = createClient(vimInstance); + public BaseNetwork createNetwork(BaseVimInstance vimInstanceBase, BaseNetwork network) + throws VimDriverException { + AmazonVimInstance vimInstance = (AmazonVimInstance) vimInstanceBase; + AmazonEC2 client = createClient(vimInstance); try { - String vpcId = getVpcsMap(vimInstance).get(vimInstance.getVpcName()); - if (vpcId == null) { - throw new VimDriverException("No such VPC " + vimInstance.getVpcName() + " exists"); - } - CreateSubnetResult res; - log.debug("Generating CIDR"); - DescribeVpcsRequest req = new DescribeVpcsRequest(); - DescribeVpcsResult resVpc = client.describeVpcs(req); - Vpc vpc = null; - for (Vpc vpc1 : resVpc.getVpcs()) { - if (vpc1.getVpcId().equals(vpcId)) { - vpc = vpc1; - } - } - if (vpc == null) { - throw new VimDriverException("The vpc with id " + vpcId + " might not exist anymore"); + String vpcId = getVpcsMap(vimInstance).get(vimInstance.getVpcName()); + if (vpcId == null) { + throw new VimDriverException("No such VPC " + vimInstance.getVpcName() + " exists"); + } + CreateSubnetResult res; + log.debug("Generating CIDR"); + DescribeVpcsRequest req = new DescribeVpcsRequest(); + DescribeVpcsResult resVpc = client.describeVpcs(req); + Vpc vpc = null; + for (Vpc vpc1 : resVpc.getVpcs()) { + if (vpc1.getVpcId().equals(vpcId)) { + vpc = vpc1; } - String vpcCidr = vpc.getCidrBlock(); - String adrMask[] = vpcCidr.split("/"); - String adr[] = adrMask[0].split("…\\.")[0].split("\\."); - Random random = new Random(); - int number = random.nextInt(255); - String subnetCidr = adr[0] + "." + adr[1] + "." + number + "." + "0" + "/24"; - log.info("Generated CIDR " + subnetCidr); - CreateSubnetRequest newReq = new CreateSubnetRequest().withVpcId(vpcId).withCidrBlock(subnetCidr); - res = client.createSubnet(newReq); - String id = res.getSubnet().getSubnetId(); - List tags = new ArrayList<>(); - Tag tag = new Tag(); - tag.setKey("Name"); - tag.setValue(network.getName()); - tags.add(tag); - CreateTagsRequest tagsRequest = new CreateTagsRequest().withTags(tags).withResources(id); - client.createTags(tagsRequest); - List nets = listNetworks(vimInstanceBase); - BaseNetwork returnNetwork = null; - for (BaseNetwork net : nets) { - if (net.getExtId().equals(res.getSubnet().getSubnetId())) { - returnNetwork = net; - } + } + if (vpc == null) { + throw new VimDriverException("The vpc with id " + vpcId + " might not exist anymore"); + } + String vpcCidr = vpc.getCidrBlock(); + String adrMask[] = vpcCidr.split("/"); + String adr[] = adrMask[0].split("…\\.")[0].split("\\."); + Random random = new Random(); + int number = random.nextInt(255); + String subnetCidr = adr[0] + "." + adr[1] + "." + number + "." + "0" + "/24"; + log.info("Generated CIDR " + subnetCidr); + CreateSubnetRequest newReq = + new CreateSubnetRequest().withVpcId(vpcId).withCidrBlock(subnetCidr); + res = client.createSubnet(newReq); + String id = res.getSubnet().getSubnetId(); + List tags = new ArrayList<>(); + Tag tag = new Tag(); + tag.setKey("Name"); + tag.setValue(network.getName()); + tags.add(tag); + CreateTagsRequest tagsRequest = new CreateTagsRequest().withTags(tags).withResources(id); + client.createTags(tagsRequest); + List nets = listNetworks(vimInstanceBase); + BaseNetwork returnNetwork = null; + for (BaseNetwork net : nets) { + if (net.getExtId().equals(res.getSubnet().getSubnetId())) { + returnNetwork = net; } + } - return returnNetwork; + return returnNetwork; } catch (AmazonClientException e) { - VimDriverException vimDriverException = new VimDriverException(e.getMessage()); - throw vimDriverException; + VimDriverException vimDriverException = new VimDriverException(e.getMessage()); + throw vimDriverException; } } - private HashMap getVpcsMap(AmazonVimInstance vimInstance) throws VimDriverException { + /** + * Get the table of VPCs name to id by name + * @param vimInstance + * @return + * @throws VimDriverException + */ + private HashMap getVpcsMap(AmazonVimInstance vimInstance) + throws VimDriverException { AmazonEC2 client = createClient(vimInstance); try { - DescribeVpcsRequest describeVpcsRequest = new DescribeVpcsRequest(); - DescribeVpcsResult describeVpcsResult = client.describeVpcs(describeVpcsRequest); - HashMap vpcNameId = new HashMap<>(); - for (Vpc vpc : describeVpcsResult.getVpcs()) { - String id = vpc.getVpcId(); - String name = ""; - for (Tag tag : vpc.getTags()) { - if (tag.getKey().equals("Name")) { - name = tag.getValue(); - } - } - vpcNameId.put(name, id); + DescribeVpcsRequest describeVpcsRequest = new DescribeVpcsRequest(); + DescribeVpcsResult describeVpcsResult = client.describeVpcs(describeVpcsRequest); + HashMap vpcNameId = new HashMap<>(); + for (Vpc vpc : describeVpcsResult.getVpcs()) { + String id = vpc.getVpcId(); + String name = ""; + for (Tag tag : vpc.getTags()) { + if (tag.getKey().equals("Name")) { + name = tag.getValue(); + } } - return vpcNameId; + vpcNameId.put(name, id); + } + return vpcNameId; } catch (AmazonClientException e) { - VimDriverException vimDriverException = new VimDriverException(e.getMessage()); - throw vimDriverException; + VimDriverException vimDriverException = new VimDriverException(e.getMessage()); + throw vimDriverException; } } @java.lang.Override - public DeploymentFlavour addFlavor(BaseVimInstance vimInstance, DeploymentFlavour deploymentFlavour) - throws VimDriverException { + public DeploymentFlavour addFlavor( + BaseVimInstance vimInstance, DeploymentFlavour deploymentFlavour) throws VimDriverException { return null; } @java.lang.Override - public BaseNfvImage addImage(BaseVimInstance vimInstanceBase, BaseNfvImage imageBase, byte[] imageFile) + public BaseNfvImage addImage( + BaseVimInstance vimInstanceBase, BaseNfvImage imageBase, byte[] imageFile) throws VimDriverException { AmazonVimInstance vimInstance = (AmazonVimInstance) vimInstanceBase; AWSImage image = (AWSImage) imageBase; @@ -790,7 +847,8 @@ public BaseNfvImage addImage(BaseVimInstance vimInstance, BaseNfvImage image, St } @java.lang.Override - public BaseNfvImage updateImage(BaseVimInstance vimInstance, BaseNfvImage image) throws VimDriverException { + public BaseNfvImage updateImage(BaseVimInstance vimInstance, BaseNfvImage image) + throws VimDriverException { return addImage(vimInstance, image, "".getBytes()); } @@ -801,7 +859,8 @@ public BaseNfvImage copyImage(BaseVimInstance vimInstance, BaseNfvImage image, b } @java.lang.Override - public boolean deleteImage(BaseVimInstance vimInstance, BaseNfvImage image) throws VimDriverException { + public boolean deleteImage(BaseVimInstance vimInstance, BaseNfvImage image) + throws VimDriverException { return false; } @@ -817,13 +876,16 @@ public boolean deleteFlavor(BaseVimInstance vimInstance, String extId) throws Vi return false; } - @Override - public org.openbaton.catalogue.nfvo.networks.Subnet createSubnet(BaseVimInstance vimInstance, BaseNetwork createdNetwork, org.openbaton.catalogue.nfvo.networks.Subnet subnet) throws VimDriverException { - return null; - } - + @Override + public org.openbaton.catalogue.nfvo.networks.Subnet createSubnet( + BaseVimInstance vimInstance, + BaseNetwork createdNetwork, + org.openbaton.catalogue.nfvo.networks.Subnet subnet) + throws VimDriverException { + return null; + } - /** + /** * This is a stub that simply return the same network to avoid null pointer exceptions * * @param vimInstance vim @@ -836,54 +898,61 @@ public BaseNetwork updateNetwork(BaseVimInstance vimInstance, BaseNetwork networ return network; } - @Override - public org.openbaton.catalogue.nfvo.networks.Subnet updateSubnet(BaseVimInstance vimInstance, BaseNetwork updatedNetwork, org.openbaton.catalogue.nfvo.networks.Subnet subnet) throws VimDriverException { - return null; - } - - @Override - public List getSubnetsExtIds(BaseVimInstance vimInstance, String network_extId) throws VimDriverException { - return null; - } - - @Override - public boolean deleteSubnet(BaseVimInstance vimInstance, String existingSubnetExtId) throws VimDriverException { - return false; - } + @Override + public org.openbaton.catalogue.nfvo.networks.Subnet updateSubnet( + BaseVimInstance vimInstance, + BaseNetwork updatedNetwork, + org.openbaton.catalogue.nfvo.networks.Subnet subnet) + throws VimDriverException { + return null; + } + @Override + public List getSubnetsExtIds(BaseVimInstance vimInstance, String network_extId) + throws VimDriverException { + return null; + } - @java.lang.Override - public boolean deleteNetwork(BaseVimInstance vimInstanceBase, String extId) throws VimDriverException { - try { - AmazonVimInstance vimInstance = (AmazonVimInstance) vimInstanceBase; - AmazonEC2 client = createClient(vimInstance); - DeleteSubnetRequest req = new DeleteSubnetRequest().withSubnetId(extId); - DeleteSubnetResult res = client.deleteSubnet(req); - return true; - } catch (AmazonClientException e) { - VimDriverException vimDriverException = new VimDriverException(e.getMessage()); - throw vimDriverException; - } + @Override + public boolean deleteSubnet(BaseVimInstance vimInstance, String existingSubnetExtId) + throws VimDriverException { + return false; } @java.lang.Override - public BaseNetwork getNetworkById(BaseVimInstance vimInstanceBase, String id) throws VimDriverException { + public boolean deleteNetwork(BaseVimInstance vimInstanceBase, String extId) + throws VimDriverException { + try { AmazonVimInstance vimInstance = (AmazonVimInstance) vimInstanceBase; AmazonEC2 client = createClient(vimInstance); - try { - Filter filter = new Filter(); - filter.setName("subnet-id"); - filter.setValues(Arrays.asList(id)); - DescribeSubnetsRequest req = new DescribeSubnetsRequest().withFilters(filter); - DescribeSubnetsResult res = client.describeSubnets(req); - if (res.getSubnets().size() < 1) { - throw new VimDriverException("Network with id " + id + " does not exist"); - } - return Utils.getNetworkFromSubnet(res.getSubnets().get(0)); - } catch (AmazonClientException e) { - VimDriverException vimDriverException = new VimDriverException(e.getMessage()); - throw vimDriverException; + DeleteSubnetRequest req = new DeleteSubnetRequest().withSubnetId(extId); + DeleteSubnetResult res = client.deleteSubnet(req); + return true; + } catch (AmazonClientException e) { + VimDriverException vimDriverException = new VimDriverException(e.getMessage()); + throw vimDriverException; + } + } + + @java.lang.Override + public BaseNetwork getNetworkById(BaseVimInstance vimInstanceBase, String id) + throws VimDriverException { + AmazonVimInstance vimInstance = (AmazonVimInstance) vimInstanceBase; + AmazonEC2 client = createClient(vimInstance); + try { + Filter filter = new Filter(); + filter.setName("subnet-id"); + filter.setValues(Arrays.asList(id)); + DescribeSubnetsRequest req = new DescribeSubnetsRequest().withFilters(filter); + DescribeSubnetsResult res = client.describeSubnets(req); + if (res.getSubnets().size() < 1) { + throw new VimDriverException("Network with id " + id + " does not exist"); } + return Utils.getNetworkFromSubnet(res.getSubnets().get(0)); + } catch (AmazonClientException e) { + VimDriverException vimDriverException = new VimDriverException(e.getMessage()); + throw vimDriverException; + } } @java.lang.Override @@ -892,7 +961,7 @@ public Quota getQuota(BaseVimInstance vimInstance) throws VimDriverException { Quota quota = new Quota(); quota.setCores(99999); quota.setFloatingIps(444); - quota.setInstances(20 - listServer(vimInstance).size()); + quota.setInstances(20); quota.setRam(9999); return quota; } diff --git a/src/main/java/org/openbaton/drivers/amazon/Utils.java b/src/main/java/org/openbaton/drivers/amazon/Utils.java index ce19d81..8fd0d2e 100644 --- a/src/main/java/org/openbaton/drivers/amazon/Utils.java +++ b/src/main/java/org/openbaton/drivers/amazon/Utils.java @@ -2,14 +2,11 @@ import com.amazonaws.services.ec2.model.*; import java.util.*; -import org.openbaton.catalogue.nfvo.images.AWSImage; import org.openbaton.catalogue.nfvo.Server; +import org.openbaton.catalogue.nfvo.images.AWSImage; import org.openbaton.catalogue.nfvo.images.NFVImage; import org.openbaton.catalogue.nfvo.networks.AWSNetwork; import org.openbaton.catalogue.nfvo.networks.BaseNetwork; -import org.openbaton.catalogue.nfvo.networks.Network; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; class Utils { @@ -80,7 +77,8 @@ static org.openbaton.catalogue.nfvo.Server getServer(Instance instance, ListAWS EC2 VPCs do not have internal networks. Subnet is converted to network with one subnet - * in order to map the resource as precisely as possible + * in order to map the resource as precisely as possible Is the subnet has not name tag, which is allowed + * in AWS the id will be assigned to name to ensure consistency * * @param subnet aws subnet * @return created nfvo network @@ -94,6 +92,9 @@ static org.openbaton.catalogue.nfvo.networks.AWSNetwork getNetworkFromSubnet( nfvoNetwork.setName(tag.getValue()); } } + if (nfvoNetwork.getName() == null || nfvoNetwork.getName().isEmpty() || nfvoNetwork.equals("")) { + nfvoNetwork.setName(subnet.getSubnetId()); + } nfvoNetwork.setIpv4cidr(subnet.getCidrBlock()); nfvoNetwork.setAvZone(subnet.getAvailabilityZone()); nfvoNetwork.setExtId(subnet.getSubnetId()); From 8a3f0c47dae077269d41703d989cb29504e391a1 Mon Sep 17 00:00:00 2001 From: Oleksander Gozman Date: Tue, 6 Feb 2018 16:49:08 +0100 Subject: [PATCH 09/10] imp: couple of comments --- .../org/openbaton/drivers/amazon/AmazonDriver.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/openbaton/drivers/amazon/AmazonDriver.java b/src/main/java/org/openbaton/drivers/amazon/AmazonDriver.java index 428fdd5..7b12569 100644 --- a/src/main/java/org/openbaton/drivers/amazon/AmazonDriver.java +++ b/src/main/java/org/openbaton/drivers/amazon/AmazonDriver.java @@ -64,7 +64,6 @@ public AmazonDriver() { public static void main(String[] args) throws NoSuchMethodException, IOException, InstantiationException, TimeoutException, IllegalAccessException, InvocationTargetException, InterruptedException { - if (args.length == 4) { log.info("Starting the plugin with CUSTOM parameters: "); log.info("name: " + args[0]); @@ -333,6 +332,12 @@ private List
getUnallocatedAddresses(AmazonEC2 client) { return unAllockAddrs; } + /** + * Get the interfaces attached to a certain VM + * @param client amazonec2 client + * @param instanceId id of the vm + * @return list of interfaces + */ private List listInterfaceByAttachment(AmazonEC2 client, String instanceId) { Filter filter = new Filter(); filter.setName("attachment.instance-id"); @@ -359,11 +364,11 @@ private List getInternetGatewaysByVPC(AmazonEC2 client, String } /** - * Creates the internet gateway in a particaular vpc + * Creates the internet gateway in a particular vpc * * @param client amazon client to make calls to api * @param vpcId the id of the VPC where gateway should be attached - * @return + * @return createdgateway data */ private InternetGateway createAndAttachInternetGateway(AmazonEC2 client, String vpcId) { CreateInternetGatewayRequest request = new CreateInternetGatewayRequest(); From e59482e2a2ad670574c2f679f0ea279262201f60 Mon Sep 17 00:00:00 2001 From: Oleksander Gozman Date: Wed, 7 Feb 2018 15:08:06 +0100 Subject: [PATCH 10/10] fix: update dependencies and add todo for rebuildserver --- build.gradle | 4 ++-- src/main/java/org/openbaton/drivers/amazon/AmazonDriver.java | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 3ae0fbe..2cd6148 100644 --- a/build.gradle +++ b/build.gradle @@ -87,8 +87,8 @@ dependencies { compile group: 'com.amazonaws', name: 'aws-java-sdk', version: '1.11.218' - compile 'org.slf4j:slf4j-api:1.7.12' - compile 'org.slf4j:slf4j-simple:1.7.12' + compile 'org.slf4j:slf4j-api:1.7.25' + compile 'org.slf4j:slf4j-simple:1.7.25' testCompile("junit:junit:4.12") diff --git a/src/main/java/org/openbaton/drivers/amazon/AmazonDriver.java b/src/main/java/org/openbaton/drivers/amazon/AmazonDriver.java index 7b12569..6cb6988 100644 --- a/src/main/java/org/openbaton/drivers/amazon/AmazonDriver.java +++ b/src/main/java/org/openbaton/drivers/amazon/AmazonDriver.java @@ -622,6 +622,11 @@ public java.util.List listServer(BaseVimInstance vimInstanceBase) } } + @Override + public Server rebuildServer(BaseVimInstance vimInstance, String serverId, String imageId) throws VimDriverException { + return null; + } + @java.lang.Override public List listNetworks(BaseVimInstance vimInstanceBase) throws VimDriverException { log.info("Listing networks");