diff --git a/amazon-test.py b/amazon-test.py new file mode 100644 index 0000000..ef38099 --- /dev/null +++ b/amazon-test.py @@ -0,0 +1,221 @@ + +import time +from calplus.v1.compute.drivers.amazon import AmazonDriver +from calplus.v1.block_storage.drivers.amazon import AmazonVolumeDriver +from calplus.v1.network.drivers.amazon import AmazonNetDriver +import argparse + +amazon_config_driver = { + 'driver_name': 'AMAZON1', + 'aws_access_key_id': '9d0e9902b3984d22a179b28df675ad80', + 'aws_secret_access_key': '8404f669a8a74195a15ad46171a3b548', + 'region_name': 'RegionOne', + 'endpoint_url': 'http://controller:8788', + 'limit': { + } +} + +class AmazonTest(): + def __init__(self): + self.amazon_driver = AmazonDriver(amazon_config_driver) + self.amazon_volume_driver = AmazonVolumeDriver(amazon_config_driver) + self.amazon_net_driver = AmazonNetDriver(amazon_config_driver) + + def create_vm_small_flavor(self, block_device_mapping=None): + started_time = int(round(time.time() * 1000)) + image_id = 'ami-9e6af129' + # if block_device_mapping is not None: + # image_id = 'ami-9e6af129' + self.amazon_driver = AmazonDriver(amazon_config_driver) + result = self.amazon_driver.create( + 'm1.small', + 'subnet-94e5201d', + 'cal', # keypair + block_device_mapping, + image_id, + ) + print (result[0]) + if(result[0]): + ended_time = int(round(time.time() * 1000)) + print 'SMALL_FLAVOR CREATED_TIME (ms): ', ended_time - started_time + # self.delete_server(result[0].id) + return result[0] + + def create_vm_medium_flavor(self, block_device_mapping=None): + started_time = int(round(time.time() * 1000)) + image_id = 'ami-9e6af129' + # if block_device_mapping is not None: + # image_id = None + self.amazon_driver = AmazonDriver(amazon_config_driver) + result = self.amazon_driver.create( + block_device_mapping, + image_id, + 'm1.medium', + 'subnet-94e5201d', + 'cal' # keypair + ) + print (result[0]) + if(result[0]): + ended_time = int(round(time.time() * 1000)) + print 'MEDIUM_FLAVOR CREATED_TIME (ms): ', ended_time - started_time + # self.delete_server(result[0].id) + return result[0] + + def create_vm_large_flavor(self, block_device_mapping=None): + started_time = int(round(time.time() * 1000)) + image_id = 'ami-9e6af129' + # if block_device_mapping is not None: + # image_id = None + self.amazon_driver = AmazonDriver(amazon_config_driver) + result = self.amazon_driver.create( + block_device_mapping, + image_id, + 'm1.large', + 'subnet-94e5201d', + 'cal' # keypair + ) + print (result[0]) + if(result[0]): + ended_time = int(round(time.time() * 1000)) + print 'LARGE_FLAVOR CREATED_TIME (ms): ', ended_time - started_time + # self.delete_server(result[0].id) + return result[0] + + def delete_server(self, id): + time.sleep(10) + print 'DELETED', id + self.amazon_driver.delete(id) + time.sleep(10) + + def create_volume(self): + configs = { + 'size': 15, + 'name': 'Amazon-Cal-Vol-Test', + 'snapshot_id': 'snap-e6bfaec3' + } + return self.amazon_volume_driver.create(configs) + + def create_snapshot(self): + configs = { + 'description': 'snapshot for testing CAL with EC2', + 'name': 'cal-snapshot' + } + return self.amazon_volume_driver.create_snapshot(configs) + + def associate_public_ip(self, allocation_id, instance_id): + started_time = int(round(time.time() * 1000)) + configs = { + 'allocation_id': allocation_id, + 'instance_id': instance_id + } + result = self.amazon_driver.associate_public_ip(configs) + ended_time = int(round(time.time() * 1000)) + print 'Associate Public IP in (ms): ', ended_time - started_time + return result + + def is_valid_pub_ip(self, pub_ip): + search_opts = { + 'Filters': [ + { + 'Name': 'network-interface.addresses.association.public-ip', + 'Values': [ + pub_ip, + ] + }, + ] + } + instances = self.amazon_driver.list(**search_opts) + return False if len(instances) else True + +def processArguments(): + parser = argparse.ArgumentParser() + parser.add_argument('--flavor', dest='FLAVOR', type=str, default="") + parser.add_argument('--volume', dest='VOLUME', type=str, default="false") + parser.add_argument('--size', dest='SIZE', type=str, default="20") + parser.add_argument('--assign-ip', dest='ASSIGN', type=str, default="false") + args = parser.parse_args() + return args + + +def run(): + + args = processArguments() + amazon_test = AmazonTest() + if args.FLAVOR == 'small': + print 'small type vm' + amazon_test.create_vm_small_flavor() + elif args.FLAVOR == 'medium': + print 'medium type vm' + amazon_test.create_vm_medium_flavor() + elif args.FLAVOR == 'large': + print 'large type vm' + amazon_test.create_vm_large_flavor() + + if args.VOLUME == 'true': + started_time = int(round(time.time() * 1000)) + print 'create volume' + # volume = amazon_test.create_volume() + + print 'create instance' + block_device_mapping = [ + { + 'DeviceName': '/dev/vdb', + 'VirtualName': 'ephemeral0', + 'Ebs': { + 'DeleteOnTermination': False, + 'SnapshotId': 'snap-e6bfaec3', + 'VolumeSize': int(args.SIZE), + 'VolumeType': '', + 'Encrypted': False, + 'KmsKeyId': '' + }, + 'NoDevice': '' + }, + ] + vm = amazon_test.create_vm_small_flavor(block_device_mapping) + + ended_time = int(round(time.time() * 1000)) + print 'CREATE VOLUME WITH SIZE ' + args.SIZE + 'GB IN (ms): ', ended_time - started_time + + f = open('amazon_saved_vm.txt', 'w+') + f.write(str(vm.id)) # write to file + + if args.ASSIGN != 'false': + print 'Associate Floating IP' + f = open("amazon_saved_vm.txt", "rw+") + vm_id = f.readline() + print vm_id + search_opts = { + 'Filters': [ + { + 'Name': 'domain', + 'Values': [ + 'vpc', + ] + } + ] + } + ips = amazon_test.amazon_net_driver.list_public_ip(**search_opts) + has_pub_ip = False + for ip in ips: + is_valid = amazon_test.is_valid_pub_ip(ip['public_ip']) + if is_valid: + has_pub_ip = True + amazon_test.associate_public_ip(ip['id'], vm_id) + break + + if has_pub_ip == False: + print "Has no public IP" + + # else: + # print 'all type vm' + # amazon_test.create_vm_small_flavor() + # time.sleep(3) + # amazon_test.create_vm_medium_flavor() + # time.sleep(3) + # amazon_test.create_vm_large_flavor() + + + +if __name__ == "__main__": + run() \ No newline at end of file diff --git a/calplus/tests/unit/v1/compute/drivers/test_amazon_driver.py b/calplus/tests/unit/v1/compute/drivers/test_amazon_driver.py index 7d15452..7f7890e 100644 --- a/calplus/tests/unit/v1/compute/drivers/test_amazon_driver.py +++ b/calplus/tests/unit/v1/compute/drivers/test_amazon_driver.py @@ -447,3 +447,4 @@ def test_list_ip_unable_to_delete(self): self.fake_driver.client.describe_instances. \ assert_called_once_with(InstanceIds=['fake_id']) + diff --git a/calplus/v1/block_storage/drivers/amazon.py b/calplus/v1/block_storage/drivers/amazon.py new file mode 100644 index 0000000..2f172d2 --- /dev/null +++ b/calplus/v1/block_storage/drivers/amazon.py @@ -0,0 +1,81 @@ +""" OpenstackDriver for Compute + based on BaseDriver +""" + + + +import six +import boto3 + +from calplus.v1.block_storage.drivers.base import BaseDriver + + +PROVIDER = "OPENSTACK" + + +class AmazonVolumeDriver(BaseDriver): + """docstring for OpenstackDriver""" + + def __init__(self, cloud_config): + super(AmazonVolumeDriver, self).__init__() + self.aws_access_key_id = cloud_config['aws_access_key_id'] + self.aws_secret_access_key = cloud_config['aws_secret_access_key'] + self.endpoint_url = cloud_config['endpoint_url'] + self.region_name = cloud_config.get('region_name', None) + self.driver_name = \ + cloud_config.get('driver_name', 'default') + self.limit = cloud_config.get('limit', None) + self._setup() + + def _setup(self): + parameters = { + 'aws_access_key_id': self.aws_access_key_id, + 'aws_secret_access_key': self.aws_secret_access_key, + 'region_name': self.region_name, + 'endpoint_url': self.endpoint_url + } + self.resource = boto3.resource('ec2', **parameters) + self.client = boto3.client('ec2', **parameters) + + def create(self, configs): + avail_zone = "nova" + snapshot_id = configs.get('snapshot_id') + + # size = configs.get('size') + # volume_type = 'standard' + # kms_key_id = '' + # name = configs.get('name') + # tags = [{ + # 'ResourceType': 'volume', + # 'Tags': [ + # { + # 'Key': 'name', + # 'Value': name + # }, + # ] + # }] + + volume = self.resource.create_volume( + AvailabilityZones=avail_zone, + SnapshotId=snapshot_id, + ) + return volume + + def create_snapshot(self, configs): + des = configs['description'] + name = configs['name'] + tags = [{ + 'ResourceType': 'snapshot', + 'Tags': [ + { + 'Key': 'name', + 'Value': name + }, + ] + }] + snapshot = self.resource.create_snapshot( + Description=des, + TagSpecifications=tags + ) + return snapshot + diff --git a/calplus/v1/block_storage/drivers/base.py b/calplus/v1/block_storage/drivers/base.py index 7baa17c..514c1f6 100644 --- a/calplus/v1/block_storage/drivers/base.py +++ b/calplus/v1/block_storage/drivers/base.py @@ -7,3 +7,7 @@ class BaseDriver(object): def __init__(self, *args, **kwargs): pass + + @abc.abstractmethod + def create(self, configs): + pass \ No newline at end of file diff --git a/calplus/v1/block_storage/drivers/openstack.py b/calplus/v1/block_storage/drivers/openstack.py new file mode 100644 index 0000000..34f8bde --- /dev/null +++ b/calplus/v1/block_storage/drivers/openstack.py @@ -0,0 +1,90 @@ +""" OpenstackDriver for Compute + based on BaseDriver +""" + + +from datetime import datetime +import six + +from keystoneauth1.identity import v3 +from keystoneauth1 import session +from cinderclient.v3 import client + +from calplus.v1.block_storage.drivers.base import BaseDriver + + +PROVIDER = "OPENSTACK" + + +class CinderDriver(BaseDriver): + """docstring for OpenstackDriver""" + + def __init__(self, cloud_config): + super(CinderDriver, self).__init__() + self.auth_url = cloud_config['os_auth_url'] + self.project_name = cloud_config['os_project_name'] + self.username = cloud_config['os_username'] + self.password = cloud_config['os_password'] + self.user_domain_name = \ + cloud_config.get('os_project_domain_name', 'default') + self.project_domain_name = \ + cloud_config.get('os_user_domain_name', 'default') + self.driver_name = \ + cloud_config.get('driver_name', 'default') + self.tenant_id = cloud_config.get('tenant_id', None) + self.limit = cloud_config.get('limit', None) + self.client_version = \ + cloud_config.get('os_cinderclient_version', '4.1.0') + self._setup() + + def _setup(self): + auth = v3.Password(auth_url=self.auth_url, + user_domain_name=self.user_domain_name, + username=self.username, + password=self.password, + project_domain_name=self.project_domain_name, + project_name=self.project_name) + sess = session.Session(auth=auth) + + self.client = client.Client(self.client_version, session=sess) + + def create(self, configs): + size = configs.get('size') + consistencygroup_id = configs.get('consistencygroup_id') + group_id = configs.get('group_id') + snapshot_id = configs.get('snapshot_id') + source_volid = configs.get('source_volid') + name = configs.get('name') + description = configs.get('description') + volume_type = configs.get('volume_type') + user_id = None, + project_id = None + availability_zone = configs.get('availability_zone') + metadata = configs.get('metadata') + imageRef = configs.get('imageRef') + scheduler_hints = configs.get('scheduler_hints') + multiattach = configs.get('multiattach') + backup_id = configs.get('backup_id') + + volume = self.client.volumes.create(size, consistencygroup_id, + group_id, snapshot_id, + source_volid, name, description, + volume_type, user_id, + project_id, availability_zone, + metadata, imageRef, scheduler_hints, + multiattach, backup_id) + return volume + + def list(self): + return self.client.volumes.list() + + def get(self, volume_id): + return self.client.volumes.get(volume_id) + + def attach(self, volume, instance_uuid=None): + mountpoint = '/dev/vda' + mode = 'rw' + return self.client.volumes.attach(volume, instance_uuid, mountpoint, mode) + + def set_bootable(self, volume, flag): + return self.client.volumes.set_bootable(self, volume, flag) \ No newline at end of file diff --git a/calplus/v1/compute/drivers/amazon.py b/calplus/v1/compute/drivers/amazon.py index d74003b..39d7a75 100644 --- a/calplus/v1/compute/drivers/amazon.py +++ b/calplus/v1/compute/drivers/amazon.py @@ -39,8 +39,8 @@ def _setup(self): self.client = boto3.client('ec2', **parameters) self.quota = AmazonQuota(self.client, self.limit) - def create(self, image_id, flavor_id, - network_id, name=None, number=1, **kargs): + def create(self, flavor_id, + network_id, key_name, block_device_mapping=None, image_id=None, name=None, number=1, **kargs): if name is None: name = six.text_type(datetime.now()) profile = { @@ -48,23 +48,32 @@ def create(self, image_id, flavor_id, 'Name': name } server = self.resource.create_instances( + BlockDeviceMappings=block_device_mapping, ImageId=image_id, MinCount=number, MaxCount=number, + KeyName=key_name, InstanceType=flavor_id, SubnetId=network_id, IamInstanceProfile=profile ) return server + def create_key_pair(self, key_name=''): + return self.client.create_key_pair( + KeyName=key_name + ) + def show(self, instance_id): servers = self.client.describe_instances(InstanceIds=[instance_id]) return servers.get("Reservations")[0].get("Instances")[0] def list(self, **search_opts): # TODO: reformat search_opts for client boto - servers = self.client.describe_instances() - return servers.get("Reservations")[0].get("Instances") + servers = self.client.describe_instances(**search_opts) + if len(servers.get("Reservations")): + return servers.get("Reservations")[0].get("Instances") + return [] def delete(self, instance_id): server = self.resource.Instance(instance_id) @@ -120,9 +129,16 @@ def delete_private_ip(self): """Delete private IP""" pass - def associate_public_ip(self, instance_id, public_ip_id, private_ip=None): + def associate_public_ip(self, configs): """Associate a external IP""" - pass + allocation_id = configs['allocation_id'] + instance_id = configs['instance_id'] + response = self.client.associate_address( + AllocationId=allocation_id, + InstanceId=instance_id, + AllowReassociation=True + ) + return response def disassociate_public_ip(self, public_ip_id): """Disassociate a external IP""" diff --git a/calplus/v1/compute/drivers/base.py b/calplus/v1/compute/drivers/base.py index 0050cf7..8c1b400 100644 --- a/calplus/v1/compute/drivers/base.py +++ b/calplus/v1/compute/drivers/base.py @@ -86,10 +86,10 @@ def delete_private_ip(self, instance_id, new_sg): """Delete private IP""" pass - @abc.abstractmethod - def associate_public_ip(self, instance_id, public_ip_id, private_ip=None): - """Associate a external IP""" - pass + # @abc.abstractmethod + # def associate_public_ip(self, instance_id, public_ip_id, private_ip=None): + # """Associate a external IP""" + # pass @abc.abstractmethod def disassociate_public_ip(self, public_ip_id): diff --git a/calplus/v1/compute/drivers/openstack.py b/calplus/v1/compute/drivers/openstack.py index b3e22bf..69cc67e 100644 --- a/calplus/v1/compute/drivers/openstack.py +++ b/calplus/v1/compute/drivers/openstack.py @@ -49,15 +49,18 @@ def _setup(self): self.quota = OpenstackQuota( self.client, self.tenant_id, self.limit) - def create(self, image_id, flavor_id, - network_id, name=None, number=1, **kargs): + def create(self, flavor_id, + network_id, key_name,image_id=None, name=None, block_device_mapping=None, number=1, **kargs): if name is None: name = six.text_type(datetime.now()) server = self.client.servers.create( name=name, image=image_id, flavor=flavor_id, - nics=[{'net-id': network_id}] + nics=[{'net-id': network_id}], + key_name=key_name, + max_count=number, + block_device_mapping_v2=block_device_mapping ) return server @@ -68,7 +71,7 @@ def show(self, instance_id): return server def list(self, **search_opts): - servers = self.client.servers.list() + servers = self.client.servers.list(search_opts=search_opts) return servers def delete(self, instance_id): diff --git a/calplus/v1/network/drivers/amazon.py b/calplus/v1/network/drivers/amazon.py index 13298f9..b0edc5a 100644 --- a/calplus/v1/network/drivers/amazon.py +++ b/calplus/v1/network/drivers/amazon.py @@ -11,12 +11,12 @@ PROVIDER = "AMAZON" -class AmazonDriver(BaseDriver): +class AmazonNetDriver(BaseDriver): """docstring for AmazonDriver""" def __init__(self, cloud_config): - super(AmazonDriver, self).__init__() + super(AmazonNetDriver, self).__init__() self.aws_access_key_id = cloud_config['aws_access_key_id'] self.aws_secret_access_key = cloud_config['aws_secret_access_key'] self.endpoint_url = cloud_config['endpoint_url'] diff --git a/calplus/v1/network/drivers/openstack.py b/calplus/v1/network/drivers/openstack.py index 0f40d04..ce947f1 100644 --- a/calplus/v1/network/drivers/openstack.py +++ b/calplus/v1/network/drivers/openstack.py @@ -13,12 +13,12 @@ PROVIDER = "OPENSTACK" -class OpenstackDriver(BaseDriver): +class NeutronDriver(BaseDriver): """docstring for OpenstackDriver""" def __init__(self, cloud_config): - super(OpenstackDriver, self).__init__() + super(NeutronDriver, self).__init__() self.auth_url = cloud_config['os_auth_url'] self.project_name = cloud_config['os_project_name'] self.username = cloud_config['os_username'] diff --git a/openstack-test.py b/openstack-test.py new file mode 100644 index 0000000..4a5e7b9 --- /dev/null +++ b/openstack-test.py @@ -0,0 +1,216 @@ +""" +Cloud Abstract Layer (CAL) Library Examples +This script shows the basic use of the CAL as a library. +""" + +import time +import pickle +import argparse +from calplus.v1.compute.drivers.openstack import OpenstackDriver +from calplus.v1.block_storage.drivers.openstack import CinderDriver +from calplus.v1.network.drivers.openstack import NeutronDriver + +openstack_config_driver = { + 'os_auth_url': 'http://controller:5000/v3', + 'os_username': 'nghiadt', + 'os_password': 'bkcloud', + 'os_project_name': 'nghiadt', + '': 'http://controller:9696', + 'os_driver_name': 'default', + 'os_project_domain_name': 'default', + 'os_user_domain_name': 'default', + 'tenant_id': '364928bae40f4d55ac6d9b35e2146dc9', + 'limit': { + } +} + +class OpenstackTest(): + def __init__(self, args): + self.openstack_driver = OpenstackDriver(openstack_config_driver) + self.cinder_driver = CinderDriver(openstack_config_driver) + self.neutron_driver = NeutronDriver(openstack_config_driver) + # if args.FLAVOR: + # + # if args.VOLUME == 'true': + + def create_vm_small_flavor(self, block_id=None): + started_time = int(round(time.time() * 1000)) + image_id = '12162d01-2eab-45db-a1c4-831725aa05ee' + if block_id is not None: + image_id = None + + result = self.openstack_driver.create( + 'fd842c76-42bd-41d4-8917-02390eabac9d', # flavor id + '60b89cd1-0a5b-4293-bcbe-49be0cc85435', + '9thfloor-hlf', + image_id, + 'ops-small-flavor', + block_id + ) + print (result) + if result: + ended_time = int(round(time.time() * 1000)) + print 'SMALL_FLAVOR CREATED_TIME (ms): ', ended_time - started_time + # self.delete_server(result) + + return result + + def create_vm_medium_flavor(self, block_id=None): + started_time = int(round(time.time() * 1000)) + image_id = '12162d01-2eab-45db-a1c4-831725aa05ee' + if block_id is not None: + image_id = None + result = self.openstack_driver.create( + 'd6cff5fd-3083-4b55-972d-46f9aecf973c', # flavor id + '60b89cd1-0a5b-4293-bcbe-49be0cc85435', + '9thfloor-hlf', + image_id, + 'ops-medium-flavor', + block_id + ) + print (result) + if result: + ended_time = int(round(time.time() * 1000)) + print 'MEDIUM_FLAVOR CREATED_TIME (ms): ', ended_time - started_time + # self.delete_server(result) + + return result + + def create_vm_large_flavor(self, block_id=None): + started_time = int(round(time.time() * 1000)) + image_id = '12162d01-2eab-45db-a1c4-831725aa05ee' + if block_id is not None: + image_id = None + result = self.openstack_driver.create( + '81fdfda4-be44-46f7-9c8f-b15fa1c7ac82', # flavor id + '60b89cd1-0a5b-4293-bcbe-49be0cc85435', + '9thfloor-hlf', + image_id, + 'ops-large-flavor', + block_id + ) + print (result) + if result: + ended_time = int(round(time.time() * 1000)) + print 'LARGE_FLAVOR CREATED_TIME (ms): ', ended_time - started_time + # self.delete_server(result) + + return result + + def show_server(self, id): + server = self.openstack_driver.show(id) + print server + + def delete_server(self, id): + time.sleep(10) + print 'DELETED', id + self.openstack_driver.delete(id) + time.sleep(10) + + def list_nic(self, id): + interfaces = self.openstack_driver.list_nic(id) + print interfaces + + def create_volume(self, size): + configs = {} + configs['size'] = size + configs['snapshot_id'] = None + configs['name'] = 'ubuntu-volume-cal' + configs['description'] = 'cal-test-vol' + configs['availability_zone'] = 'nova' + configs['imageRef'] = '12162d01-2eab-45db-a1c4-831725aa05ee' + + result = self.cinder_driver.create(configs) + return result + + def associate_public_ip(self, instance_id, public_ip_id, private_ip=None): + started_time = int(round(time.time() * 1000)) + result = self.openstack_driver.associate_public_ip(instance_id, public_ip_id, private_ip) + ended_time = int(round(time.time() * 1000)) + print 'Associate Public IP in (ms): ', ended_time - started_time + return result + +def processArguments(): + parser = argparse.ArgumentParser() + parser.add_argument('--flavor', dest='FLAVOR', type=str, default="") + parser.add_argument('--volume', dest='VOLUME', type=str, default="false") + parser.add_argument('--size', dest='SIZE', type=str, default="20") + parser.add_argument('--assign-ip', dest='ASSIGN', type=str, default="false") + args = parser.parse_args() + return args + +def run(): + # python openstack-test.py --flavor small + + args = processArguments() + openstack_test = OpenstackTest(args) + + if args.FLAVOR == 'small': + print 'small type vm' + openstack_test.create_vm_small_flavor() + elif args.FLAVOR == 'medium': + print 'medium type vm' + openstack_test.create_vm_medium_flavor() + elif args.FLAVOR == 'large': + print 'large type vm' + openstack_test.create_vm_large_flavor() + + if args.VOLUME == 'true': + started_time = int(round(time.time() * 1000)) + print 'create volume' + volume = openstack_test.create_volume(args.SIZE) + + print 'create VM' + volume_dict = [{ + 'boot_index': 0, + 'uuid': volume.id, + 'device_name': 'vda', + 'source_type': "volume", + 'destination_type': "volume", + 'volume_size': args.SIZE, + 'delete_on_termination': False + }] + passCreated = False + while passCreated == False: + try: + vm = openstack_test.create_vm_small_flavor(volume_dict) + print vm, type(vm) + passCreated = True + except: + print 'Volume has been not bootable.' + time.sleep(3) + ended_time = int(round(time.time() * 1000)) + print 'CREATE VOLUME WITH SIZE ' + args.SIZE + 'GB IN (ms): ', ended_time - started_time + + f = open('saved_vm.txt', 'w+') + f.write(str(vm.id)) # write to file + + if args.ASSIGN != 'false': + print 'Associate Floating IP' + f = open("saved_vm.txt", "rw+") + vm_id = f.readline() + print vm_id + public_id = args.ASSIGN + if args.ASSIGN == 'true': + search_opts = { + 'status': 'DOWN', + 'tenant_id': openstack_config_driver['tenant_id'], + 'description': 'for CAL' + } + ips = openstack_test.neutron_driver.list_public_ip(**search_opts) + public_id = ips[0]['id'] + print openstack_test.associate_public_ip(vm_id, public_id) + + + + # else: + # print 'all type vm' + # openstack_test.create_vm_small_flavor() + # time.sleep(3) + # openstack_test.create_vm_medium_flavor() + # time.sleep(3) + # openstack_test.create_vm_large_flavor() + + +if __name__ == "__main__": + run() diff --git a/setup-db.sh b/setup-db.sh new file mode 100644 index 0000000..4ea1586 --- /dev/null +++ b/setup-db.sh @@ -0,0 +1,32 @@ +echo Installing package +SUDO_PREFIX="sudo" + +DOCKER_VERSION=$(docker -v) +if [ -z "$DOCKER_VERSION" ]; +then + sudo apt-get update + sudo apt-get install apt-transport-https ca-certificates curl software-properties-common + curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - + sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable" + + sudo apt-get update + sudo apt-get install -y docker-ce=17.03.2~ce-0~ubuntu-xenial + sudo usermod -aG docker $(whoami) +fi + +MYSQL_CONTAINER=$(docker ps -a | grep mysql | awk '{print $1}' ) + +if [ ! -z "$MYSQL_CONTAINER" ]; +then + $SUDO_PREFIX docker rm -f $MYSQL_CONTAINER +fi + +sleep 3 + +started_time=$(date +%s%3N) +$SUDO_PREFIX docker run -idt --name some-mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root mysql:5.7 +ended_time=$(date +%s%3N) + +runtime=$((ended_time - started_time)) + +echo "Running time (ms) =" $runtime \ No newline at end of file