# Path: ferry/config/system/aws.py
# class System(object):
#     def __init__(self):
#         self.instance_type = "t2.small"
# 
#     def get_total_memory(self):
#         """
#         Get total memory of current system. 
#         """
#         if self.instance_type in AWS_INSTANCE_INFO:
#             return AWS_INSTANCE_INFO[self.instance_type]["mem"] * 1024
#         else:
#             logging.warning("AWS system could not find " + self.instance_type)
#             return 1024
# 
#     def get_free_memory(self):
#         """
#         Get free memory of current system. 
#         """
#         if self.instance_type in AWS_INSTANCE_INFO:
#             return AWS_INSTANCE_INFO[self.instance_type]["mem"] * 1024
#         else:
#             return 1024
# 
#     def get_num_cores(self):
#         """
#         Get total number of cores. 
#         """
#         if self.instance_type in AWS_INSTANCE_INFO:
#             return AWS_INSTANCE_INFO[self.instance_type]["cores"]
#         else:
#             return 1


import boto
import boto.cloudformation
import boto.ec2
import boto.vpc
import copy
import ferry.install
import json
import logging
import math
import os
import sys
import time
import yaml
from boto.ec2.address import *
from boto.ec2.networkinterface import *
from boto.exception import BotoServerError, EC2ResponseError
from boto.ec2.blockdevicemapping import BlockDeviceType, EBSBlockDeviceType, BlockDeviceMapping
from ferry.config.system.aws import System
from pymongo import MongoClient


class AWSLauncher(object):
    """
    Launches new instances/networks on an AWS
    cluster and initializes the instances to run Ferry processes. 
    """
    def __init__(self, controller):
        self.name = "AWS launcher"
        self.docker_registry = None
        self.docker_user = None
        
        self.controller = controller
        self.subnets = []
        self.stacks = {}
        self.num_network_hosts = 1024
        self.num_subnet_hosts = 256
        self.vpc_cidr = None

        self.nat_images = { "us-east-1" : "ami-4c9e4b24",
                            "us-west-1" : "ami-2b2b296e",
                            "us-west-2" : "ami-8b6912bb",
                            "eu-west-1" : "ami-3760b040",
                            "sa-east-1" : "ami-8b72db96",
                            "ap-northeast-1" : "ami-55c29e54",
                            "ap-southeast-1" : "ami-b082dae2",
                            "ap-southeast-2" : "ami-996402a3" }        
        self._init_app_db()
        self._init_aws_stack()


# Path: ferry/config/system/aws.py
# class System(object):
#     def __init__(self):
#         self.instance_type = "t2.small"
# 
#     def get_total_memory(self):
#         """
#         Get total memory of current system. 
#         """
#         if self.instance_type in AWS_INSTANCE_INFO:
#             return AWS_INSTANCE_INFO[self.instance_type]["mem"] * 1024
#         else:
#             logging.warning("AWS system could not find " + self.instance_type)
#             return 1024
# 
#     def get_free_memory(self):
#         """
#         Get free memory of current system. 
#         """
#         if self.instance_type in AWS_INSTANCE_INFO:
#             return AWS_INSTANCE_INFO[self.instance_type]["mem"] * 1024
#         else:
#             return 1024
# 
#     def get_num_cores(self):
#         """
#         Get total number of cores. 
#         """
#         if self.instance_type in AWS_INSTANCE_INFO:
#             return AWS_INSTANCE_INFO[self.instance_type]["cores"]
#         else:
#             return 1


# Path: ferry/fabric/aws/awslauncher.py
import boto
import boto.cloudformation
import boto.ec2
import boto.vpc
import copy
import ferry.install
import json
import logging
import math
import os
import sys
import time
import yaml
from boto.ec2.address import *
from boto.ec2.networkinterface import *
from boto.exception import BotoServerError, EC2ResponseError
from boto.ec2.blockdevicemapping import BlockDeviceType, EBSBlockDeviceType, BlockDeviceMapping
from ferry.config.system.aws import System
from pymongo import MongoClient



class AWSLauncher(object):
    """
    Launches new instances/networks on an AWS
    cluster and initializes the instances to run Ferry processes. 
    """
    def __init__(self, controller):
        self.name = "AWS launcher"
        self.docker_registry = None
        self.docker_user = None
        
        self.controller = controller
        self.subnets = []
        self.stacks = {}
        self.num_network_hosts = 1024
        self.num_subnet_hosts = 256
        self.vpc_cidr = None

        self.nat_images = { "us-east-1" : "ami-4c9e4b24",
                            "us-west-1" : "ami-2b2b296e",
                            "us-west-2" : "ami-8b6912bb",
                            "eu-west-1" : "ami-3760b040",
                            "sa-east-1" : "ami-8b72db96",
                            "ap-northeast-1" : "ami-55c29e54",
                            "ap-southeast-1" : "ami-b082dae2",
                            "ap-southeast-2" : "ami-996402a3" }        
        self._init_app_db()
        self._init_aws_stack()


        self.system = System()