Skip to content

Commit

Permalink
fea: started move to new catalogue
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksander Gozman committed Dec 14, 2017
1 parent 2f5b75e commit bc8b0ac
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 24 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
//------------------------------------------------//
}

Expand Down
70 changes: 58 additions & 12 deletions src/main/java/org/openbaton/drivers/amazon/AmazonDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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]);
Expand Down Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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<VNFDConnectionPoint> newNetworks =
Expand Down Expand Up @@ -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<Server> servers = listServer(vimInstance);
for (Server ser : servers) {
Expand All @@ -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<AWSImage> newImages = listImages(vimInstance);
if (amazon.getImages() == null) {
amazon.setImages(new HashSet<>());
}
amazon.getImages().clear();
amazon.addAllImages(newImages);

List<BaseNetwork> newNetworks = listNetworks(vimInstance);

if (amazon.getNetworks() == null) {
amazon.setNetworks(new HashSet<>());
}
amazon.getNetworks().clear();
amazon.addAllNetworks(newNetworks);

List<DeploymentFlavour> newFlavors = listFlavors(vimInstance);
if (amazon.getFlavours() == null) {
amazon.setFlavours(new HashSet<>());
}
amazon.getFlavours().clear();
amazon.getFlavours().addAll(newFlavors);

List<org.openbaton.catalogue.nfvo.viminstances.AvailabilityZone> 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;
Expand Down Expand Up @@ -425,8 +470,8 @@ public int compare(VNFDConnectionPoint t, VNFDConnectionPoint t1) {
* does not exits
*/
private Set<String> getSecurityIdFromName(
Set<String> groupNames, AmazonEC2 client, VimInstance vimInstance) throws VimDriverException, AmazonClientException {
String vpcId = getVpcsMap(vimInstance).get(vimInstance.getTenant());
Set<String> 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");
}
Expand Down Expand Up @@ -456,9 +501,9 @@ private Set<String> getSecurityIdFromName(
}

@java.lang.Override
public java.util.List<NFVImage> listImages(VimInstance vimInstance) throws VimDriverException {
public java.util.List<AWSImage> 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++) {
Expand All @@ -470,7 +515,7 @@ public java.util.List<NFVImage> listImages(VimInstance vimInstance) throws VimDr
DescribeImagesRequest describeImagesRequest = new DescribeImagesRequest();
describeImagesRequest.setFilters(Arrays.asList(filter));
DescribeImagesResult describeImagesResult = client.describeImages(describeImagesRequest);
List<NFVImage> images = new ArrayList<>();
List<AWSImage> images = new ArrayList<>();
for (Image image : describeImagesResult.getImages()) {
images.add(Utils.getImage(image));
}
Expand All @@ -492,13 +537,14 @@ public java.util.List<NFVImage> listImages(VimInstance vimInstance) throws VimDr
}

@java.lang.Override
public java.util.List<Server> listServer(VimInstance vimInstance) throws VimDriverException {
public java.util.List<Server> listServer(BaseVimInstance vimInstanceBase) throws VimDriverException {
AmazonVimInstance vimInstance = (AmazonVimInstance) vimInstanceBase;
try {
List<Server> 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");
Expand Down
19 changes: 9 additions & 10 deletions src/main/java/org/openbaton/drivers/amazon/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Network> nets) {
Server server = new Server();
Expand Down Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion src/main/resources/plugin.conf.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
launchTimeout = 128

0 comments on commit bc8b0ac

Please sign in to comment.