示例#1
0
def delete_azure_deployment(cloud_service_name, deployment_slot):
    cs = db_adapter.find_first_object_by(AzureCloudService,
                                         name=cloud_service_name)
    db_adapter.delete_all_objects_by(AzureDeployment,
                                     slot=deployment_slot,
                                     cloud_service_id=cs.id)
    db_adapter.commit()
示例#2
0
def commit_azure_cloud_service(name, label, location, status, experiment_id):
    db_adapter.add_object_kwargs(AzureCloudService,
                                 name=name,
                                 label=label,
                                 location=location,
                                 status=status,
                                 experiment_id=experiment_id)
    db_adapter.commit()
示例#3
0
def commit_azure_endpoint(name, protocol, public_port, private_port,
                          virtual_machine):
    db_adapter.add_object_kwargs(AzureEndpoint,
                                 name=name,
                                 protocol=protocol,
                                 public_port=public_port,
                                 private_port=private_port,
                                 virtual_machine=virtual_machine)
    db_adapter.commit()
示例#4
0
def commit_azure_storage_account(name, description, label, location, status,
                                 experiment_id):
    db_adapter.add_object_kwargs(AzureStorageAccount,
                                 name=name,
                                 description=description,
                                 label=label,
                                 location=location,
                                 status=status,
                                 experiment_id=experiment_id)
    db_adapter.commit()
示例#5
0
def commit_azure_deployment(name, slot, status, cloud_service_name,
                            experiment_id):
    cs = db_adapter.find_first_object_by(AzureCloudService,
                                         name=cloud_service_name)
    db_adapter.add_object_kwargs(AzureDeployment,
                                 name=name,
                                 slot=slot,
                                 status=status,
                                 cloud_service=cs,
                                 experiment_id=experiment_id)
    db_adapter.commit()
示例#6
0
def delete_azure_virtual_machine(cloud_service_name, deployment_name,
                                 virtual_machine_name):
    cs = db_adapter.find_first_object_by(AzureCloudService,
                                         name=cloud_service_name)
    dm = db_adapter.find_first_object_by(AzureDeployment,
                                         name=deployment_name,
                                         cloud_service=cs)
    db_adapter.delete_all_objects_by(AzureVirtualMachine,
                                     name=virtual_machine_name,
                                     deployment_id=dm.id)
    db_adapter.commit()
示例#7
0
def commit_virtual_environment(provider, name, image, status, remote_provider,
                               remote_paras, experiment_id):
    ve = db_adapter.add_object_kwargs(VirtualEnvironment,
                                      provider=provider,
                                      name=name,
                                      image=image,
                                      status=status,
                                      remote_provider=remote_provider,
                                      remote_paras=remote_paras,
                                      experiment_id=experiment_id)
    db_adapter.commit()
    return ve
示例#8
0
def update_azure_virtual_machine_status(cloud_service_name, deployment_name,
                                        virtual_machine_name, status):
    cs = db_adapter.find_first_object_by(AzureCloudService,
                                         name=cloud_service_name)
    dm = db_adapter.find_first_object_by(AzureDeployment,
                                         name=deployment_name,
                                         cloud_service=cs)
    vm = db_adapter.find_first_object_by(AzureVirtualMachine,
                                         name=virtual_machine_name,
                                         deployment=dm)
    vm.status = status
    db_adapter.commit()
    return vm
示例#9
0
def commit_azure_log(experiment_id, operation, status, note=None, code=None):
    db_adapter.add_object_kwargs(AzureLog,
                                 experiment_id=experiment_id,
                                 operation=operation,
                                 status=status,
                                 note=note,
                                 code=code)
    db_adapter.commit()
    if status == ALStatus.FAIL:
        update_experiment_status(experiment_id, EStatus.Failed)
    elif status == ALStatus.END:
        need_status = EStatus.Running
        if operation == ALOperation.STOP_VIRTUAL_MACHINE:
            need_status = EStatus.Stopped
        check_experiment_done(experiment_id, need_status)
示例#10
0
 def delete_certificate(self, certificate_id, hackathon_name):
     certificate_id = int(certificate_id)
     hackathon_id = db_adapter.find_first_object_by(Hackathon,
                                                    name=hackathon_name).id
     hackathon_azure_keys = db_adapter.find_all_objects_by(
         HackathonAzureKey, hackathon_id=hackathon_id)
     if hackathon_azure_keys is None:
         log.error('hackathon [%d] has no certificates' % hackathon_id)
         return False
     azure_key_ids = map(lambda x: x.azure_key_id, hackathon_azure_keys)
     if certificate_id not in azure_key_ids:
         log.error('hackathon [%d] has no certificate [%d]' %
                   (hackathon_id, certificate_id))
         return False
     certificate = db_adapter.get_object(AzureKey, certificate_id)
     db_adapter.delete_object(certificate)
     db_adapter.commit()
     return True
示例#11
0
def commit_azure_virtual_machine(name, label, status, dns, public_ip,
                                 private_ip, cloud_service_name,
                                 deployment_name, experiment_id,
                                 virtual_environment):
    cs = db_adapter.find_first_object_by(AzureCloudService,
                                         name=cloud_service_name)
    dm = db_adapter.find_first_object_by(AzureDeployment,
                                         name=deployment_name,
                                         cloud_service=cs)
    vm = db_adapter.add_object_kwargs(AzureVirtualMachine,
                                      name=name,
                                      label=label,
                                      status=status,
                                      dns=dns,
                                      public_ip=public_ip,
                                      private_ip=private_ip,
                                      deployment=dm,
                                      experiment_id=experiment_id,
                                      virtual_environment=virtual_environment)
    db_adapter.commit()
    return vm
示例#12
0
 def test_create_virtual_machine(self):
     experiment = db_adapter.add_object_kwargs(Experiment)
     db_adapter.commit()
     template_unit_json = \
         json.load(file('../src/azureformation/resources/test-template-1.js'))['virtual_environments'][0]
     storage = StorageAccount(self.service)
     sa = template_unit_json['storage_account']
     result = storage.create_storage_account(experiment, sa['service_name'],
                                             sa['description'], sa['label'],
                                             sa['location'])
     self.assertTrue(result)
     cloud = CloudService(self.service)
     cs = template_unit_json['cloud_service']
     result = cloud.create_cloud_service(experiment, cs['service_name'],
                                         cs['label'], cs['location'])
     self.assertTrue(result)
     vm = VirtualMachine(self.service)
     template_unit = TemplateUnit(template_unit_json)
     result = vm.create_virtual_machine(experiment, template_unit)
     self.assertTrue(result)
     result = vm.create_virtual_machine(experiment, template_unit)
     self.assertTrue(result)
示例#13
0
    HackathonAzureKey,
    Template,
)
from src.azureformation.credentials import (
    CERT_CERTIFICATE,
    PEM_CERTIFICATE,
    SUBSCRIPTION_ID,
    MANAGEMENT_HOST,
    USER_NAME,
    HACKATHON_NAME,
    TEMPLATE_URL,
)

# load user
u = db_adapter.add_object_kwargs(User, name=USER_NAME)
db_adapter.commit()

# load hackathon
h = db_adapter.add_object_kwargs(Hackathon, name=HACKATHON_NAME)
db_adapter.commit()

# load azure key
a = db_adapter.add_object_kwargs(AzureKey,
                                 cert_url=CERT_CERTIFICATE,
                                 pem_url=PEM_CERTIFICATE,
                                 subscription_id=SUBSCRIPTION_ID,
                                 management_host=MANAGEMENT_HOST)
db_adapter.commit()

# associate hackathon with azure key
db_adapter.add_object_kwargs(HackathonAzureKey, hackathon=h, azure_key=a)
示例#14
0
def update_experiment_status(experiment_id, status):
    e = db_adapter.get_object(Experiment, experiment_id)
    e.status = status
    db_adapter.commit()
示例#15
0
def set_template_virtual_environment_count(experiment_id, count):
    e = db_adapter.get_object(Experiment, experiment_id)
    t = db_adapter.get_object(Template, e.template_id)
    t.virtual_environment_count = count
    db_adapter.commit()
示例#16
0
def update_virtual_environment_remote_paras(virtual_machine, remote_paras):
    ve = virtual_machine.virtual_environment
    ve.remote_paras = remote_paras
    db_adapter.commit()
示例#17
0
def update_virtual_environment_status(virtual_machine, status):
    ve = virtual_machine.virtual_environment
    ve.status = status
    db_adapter.commit()
示例#18
0
def delete_azure_storage_account(name):
    db_adapter.delete_all_objects_by(AzureStorageAccount, name=name)
    db_adapter.commit()
示例#19
0
def delete_azure_cloud_service(name):
    db_adapter.delete_all_objects_by(AzureCloudService, name=name)
    db_adapter.commit()
示例#20
0
    def create_certificate(self, subscription_id, management_host,
                           hackathon_name):
        """
        1. check certificate dir
        2. generate pem file
        3. generate cert file
        4. add azure key to db
        5. add hackathon azure key to db
        :param subscription_id:
        :param management_host:
        :param hackathon_id:
        :return:
        """

        # make sure certificate dir exists
        if not os.path.isdir(self.CERT_BASE):
            log.debug('certificate dir not exists')
            os.mkdir(self.CERT_BASE)

        base_url = '%s/%s' % (self.CERT_BASE, subscription_id)

        pem_url = base_url + '.pem'
        # avoid duplicate pem generation
        if not os.path.isfile(pem_url):
            pem_command = 'openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout %s -out %s -batch' % \
                          (pem_url, pem_url)
            commands.getstatusoutput(pem_command)
        else:
            log.debug('%s exists' % pem_url)

        cert_url = base_url + '.cer'
        # avoid duplicate cert generation
        if not os.path.isfile(cert_url):
            cert_command = 'openssl x509 -inform pem -in %s -outform der -out %s' % (
                pem_url, cert_url)
            commands.getstatusoutput(cert_command)
        else:
            log.debug('%s exists' % cert_url)

        azure_key = db_adapter.find_first_object_by(
            AzureKey,
            cert_url=cert_url,
            pem_url=pem_url,
            subscription_id=subscription_id,
            management_host=management_host)
        # avoid duplicate azure key
        if azure_key is None:
            azure_key = db_adapter.add_object_kwargs(
                AzureKey,
                cert_url=cert_url,
                pem_url=pem_url,
                subscription_id=subscription_id,
                management_host=management_host)
            db_adapter.commit()
        else:
            log.debug('azure key exists')

        hackathon_id = db_adapter.find_first_object_by(Hackathon,
                                                       name=hackathon_name).id
        hackathon_azure_key = db_adapter.find_first_object_by(
            HackathonAzureKey,
            hackathon_id=hackathon_id,
            azure_key_id=azure_key.id)
        # avoid duplicate hackathon azure key
        if hackathon_azure_key is None:
            db_adapter.add_object_kwargs(HackathonAzureKey,
                                         hackathon_id=hackathon_id,
                                         azure_key_id=azure_key.id)
            db_adapter.commit()
        else:
            log.debug('hackathon azure key exists')

        return cert_url
示例#21
0
def update_azure_virtual_machine_private_ip(virtual_machine, private_ip):
    virtual_machine.private_ip = private_ip
    db_adapter.commit()
示例#22
0
def relationship(*arg, **kw):
    ret = relation(*arg, **kw)
    db_adapter.commit()
    return ret
示例#23
0
def update_azure_virtual_machine_public_ip(virtual_machine, public_ip):
    virtual_machine.public_ip = public_ip
    db_adapter.commit()