Kashyap & Venu | user data or config drive fn. added and working
This commit is contained in:
parent
2785010240
commit
3b887709a6
15
ec2driver.py
15
ec2driver.py
|
@ -33,6 +33,7 @@ from nova.openstack.common import loopingcall
|
||||||
from nova.virt import driver
|
from nova.virt import driver
|
||||||
from nova.virt import virtapi
|
from nova.virt import virtapi
|
||||||
from nova.compute import flavors
|
from nova.compute import flavors
|
||||||
|
import base64
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -191,16 +192,24 @@ class EC2Driver(driver.ComputeDriver):
|
||||||
timer = loopingcall.FixedIntervalLoopingCall(_wait_for_state)
|
timer = loopingcall.FixedIntervalLoopingCall(_wait_for_state)
|
||||||
timer.start(interval=0.5).wait()
|
timer.start(interval=0.5).wait()
|
||||||
|
|
||||||
|
|
||||||
def spawn(self, context, instance, image_meta, injected_files,
|
def spawn(self, context, instance, image_meta, injected_files,
|
||||||
admin_password, network_info=None, block_device_info=None):
|
admin_password, network_info=None, block_device_info=None):
|
||||||
LOG.info("***** Calling SPAWN *******************")
|
LOG.info("***** Calling SPAWN *******************")
|
||||||
|
LOG.info("****** %s" % instance._user_data)
|
||||||
LOG.info("****** Allocating an elastic IP *********")
|
LOG.info("****** Allocating an elastic IP *********")
|
||||||
elastic_ip_address = self.ec2_conn.allocate_address(domain='vpc')
|
elastic_ip_address = self.ec2_conn.allocate_address(domain='vpc')
|
||||||
|
|
||||||
#Creating the EC2 instance
|
#Creating the EC2 instance
|
||||||
instance_type = flavor_map[instance.get_flavor().name]
|
flavor_type = flavor_map[instance.get_flavor().name]
|
||||||
reservation = self.ec2_conn.run_instances(aws_ami, instance_type=instance_type)
|
|
||||||
|
#passing user_data from the openstack instance which is Base64 encoded after decoding it.
|
||||||
|
user_data = instance._user_data
|
||||||
|
|
||||||
|
if user_data:
|
||||||
|
user_data = base64.b64decode(user_data)
|
||||||
|
|
||||||
|
reservation = self.ec2_conn.run_instances(aws_ami, instance_type=flavor_type, user_data=user_data)
|
||||||
ec2_instance = reservation.instances
|
ec2_instance = reservation.instances
|
||||||
instance['metadata'].update({'ec2_id':ec2_instance[0].id, 'public_ip_address':elastic_ip_address.public_ip})
|
instance['metadata'].update({'ec2_id':ec2_instance[0].id, 'public_ip_address':elastic_ip_address.public_ip})
|
||||||
|
|
||||||
|
|
|
@ -20,13 +20,18 @@ aws_region = "us-east-1"
|
||||||
aws_access_key_id = "AKIAIZJDDRNNJUWZ3LXA"
|
aws_access_key_id = "AKIAIZJDDRNNJUWZ3LXA"
|
||||||
aws_secret_access_key = "FMld6m8kok9jpxBkORST5xfbZSod7mVm9ChDgttS"
|
aws_secret_access_key = "FMld6m8kok9jpxBkORST5xfbZSod7mVm9ChDgttS"
|
||||||
|
|
||||||
aws_ami = "ami-864d84ee"
|
#Adding a Red Hat Linux image below
|
||||||
|
aws_ami = "ami-785bae10"
|
||||||
|
#aws_ami = "ami-864d84ee"
|
||||||
instance_type = "t2.micro"
|
instance_type = "t2.micro"
|
||||||
|
|
||||||
flavor_map = {'m1.tiny': 't2.micro', 'm1.small': 't2.small', 'm1.medium': 't2.medium', 'm1.large': 'c3.xlarge',
|
flavor_map = {'m1.tiny': 't2.micro', 'm1.small': 't2.small', 'm1.medium': 't2.medium', 'm1.large': 'c3.xlarge',
|
||||||
'm1.xlarge': 'c3.2xlarge'}
|
'm1.xlarge': 'c3.2xlarge'}
|
||||||
|
#Add image maps key: image in openstack, Value: EC2_AMI_ID
|
||||||
image_map = {}
|
image_map = {}
|
||||||
|
|
||||||
|
keypair_map = {}
|
||||||
|
|
||||||
# The limit on maximum resources you could have in the AWS EC2.
|
# The limit on maximum resources you could have in the AWS EC2.
|
||||||
|
|
||||||
cpu_units = 100
|
cpu_units = 100
|
||||||
|
|
Loading…
Reference in New Issue