Ejemplo n.º 1
0
 def post(self):
     """Posts a new VNF"""
     data = request.get_json()
     vdu_data = data['vdu']
     cached = "false"
     if 'cached' in vdu_data:
         cached = vdu_data['cached']
     if cached:
         cached = "true"
     vdu = TenorVDU(vdu_data['vm_image'],
                    vdu_data['vm_image_format'],
                    vdu_data['flavor'],
                    cached,
                    vdu_data['shell'],
                    vdu_data['storage_amount'],
                    vdu_data['vcpus'])
     vnf = TenorVNF(vdu)
     try:
         resp = vnf.register(data['name'])
     except Exception as exc:
         abort(500, message="Error registering VNF: {0}".format(str(exc)))
     try:
         data = json.loads(resp.text)
     except Exception as exc:
         abort(500,
               message="Error decoding VNF reg.: {0}".format(str(exc)))
     return {'state': 'PROVISIONED', 'vnf_id': data['vnfd']['id']}
Ejemplo n.º 2
0
 def delete(self, vnf_id):
     """Deletes a VNF"""
     vnf = TenorVNF(int(vnf_id))
     try:
         vnf.delete()
     except Exception as exc:
         abort(500, message="Error deleting VNF: {0}".format(str(exc)))
     return {'message': 'successfully deleted'}
Ejemplo n.º 3
0
    def post(self, ns_id=None):
        """Posts a new NS"""
        if ns_id:
            try:
                data = request.get_json()
                vdu = TenorVDU()
                vnf = TenorVNF(vdu)
                tns = TenorNS(vnf)
                tns.set_dummy_id(ns_id)
                if not 'pop_id' in data:
                    abort(400, message='Lack of PoP id')
                available_pops = TenorPoP().get_pop_ids()
                if not data['pop_id'] in available_pops:
                    abort(404, message='PoP {0} not found'.format(data['pop_id']))
                resp = tns.instantiate(data['pop_id'])
                nsdata = json.loads(resp.text)
                client = MongoClient()
                mdb = client.custom_conf
                confs = mdb.confs
                if not 'user' in data:
                    data['user'] = None
                    data['password'] = None
                confs.insert_one({'ns_instance_id': nsdata['id'],
                                  'user': data['user'],
                                  'password': data['password'],
                                  'consumer_params': data['context']['consumer_params']})
                client.close()
                return {'service_instance_id': nsdata['id'],
                        'state': 'PROVISIONED'}
            except:
                nsi = TenorNSI(ns_id)
                nsi.delete()
                abort(500, message='Error instantiating {0}'.format(ns_id))

        data = request.get_json()
        vnf_ids = TenorVNF.get_vnf_ids()
        if not data['vnf_id'] in vnf_ids:
            abort(404, message='vnf_id {0} not found'.format(data['vnf_id']))
        vnf = TenorVNF(data['vnf_id'])
        tns = TenorNS(data['vnf_id'])
        resp = tns.register(data['name'])
        try:
            data = json.loads(resp.text)
        except Exception as exc:
            abort(500,
                  message="Error decoding NS reg.: {0}".format(str(exc)))
        return {'state': 'PROVISIONED', 'ns_id': data['nsd']['id']}
Ejemplo n.º 4
0
 def post(self):
     """Post a new NSI"""
     data = request.get_json()
     log_db_client = MongoClient()
     log_db = log_db_client.orchestrator_logs
     logs = log_db.logs
     logs.insert_one({'method': 'POST',
                      'request': data,
                      'date': datetime.datetime.utcnow()})
     log_db_client.close()
     context = data['context']
     name = context['name_image']
     cached = "true"
     if 'cached' in context:
         cached = context['cached']
     if cached:
         cached = "true"
     vdu = TenorVDU(context['vm_image'], context['vm_image_format'],
                    context['flavor'],cached)
     if not 'bootstrap_script' in context:
         shell = None
         with open('keys/anella.json') as data_file:
             shell = json.load(data_file)
         context['bootstrap_script'] = shell['shell']
     try:
         vnf = TenorVNF(vdu)
         tns = TenorNS(vnf)
         tns.register(name, context['bootstrap_script'])
         resp = None
         pop_id = POP_ID
         if 'pop_id' in context:
             pop_id = context['pop_id']
         if not 'public_network_id' in context:
             resp = tns.instantiate(pop_id)
         else:
             print context['public_network_id']
             resp = tns.instantiate(pop_id, context['public_network_id'])
         nsdata = json.loads(resp.text)
     except Exception as exc:
         abort(500,
               message="Error posting NS instance: {0}".format(str(exc)))
     client = MongoClient()
     mdb = client.custom_conf
     confs = mdb.confs
     if not 'user' in data:
         data['user'] = None
         data['password'] = None
     if 'consumer_params' in data['context']:
         confs.insert_one({'ns_instance_id': nsdata['id'],
                           'user': data['user'],
                           'password': data['password'],
                           'consumer_params': data['context']['consumer_params']})
     client.close()
     return {'service_instance_id': nsdata['id'], 'state': 'PROVISIONED'}
Ejemplo n.º 5
0
 def get(self, vnf_id=None):
     """Gets VNF(s)"""
     ids = TenorVNF.get_vnf_ids()
     result = []
     if vnf_id:
         for vid in ids:
             if vid == int(vnf_id):
                 return {'vnf_id': vid}
         abort(404, message='{0} VNF not found'.format(vnf_id))
     for vnf_sid in ids:
         result.append({'vnf_id': vnf_sid})
     return result
Ejemplo n.º 6
0
    def post(self, ns_id=None):
        """Posts a new NS"""
        if ns_id:
            try:
                data = request.get_json()
                vdu = TenorVDU()
                vnf = TenorVNF(vdu)
                tns = TenorNS(vnf)
                tns.set_dummy_id(ns_id)
                if not 'pop_id' in data:
                    abort(400, message='Lack of PoP id')
                resp = tns.instantiate(data['pop_id'])
                nsdata = json.loads(resp.text)
                pkey = ''
                with open('./keys/anella') as fhandle:
                    pkey = fhandle.read()
                icd = build_instance_configuration(
                    nsdata['id'], data['context']['consumer_params'], pkey)
                icd.save()
                return {
                    'service_instance_id': nsdata['id'],
                    'state': 'PROVISIONED'
                }
            except:
                nsi = TenorNSI(ns_id)
                nsi.delete()
                abort(500, message='Error instantiating {0}'.format(ns_id))

        data = request.get_json()
        vnf_ids = TenorVNF.get_vnf_ids()
        if not data['vnf_id'] in vnf_ids:
            abort(404, message='vnf_id {0} not found'.format(data['vnf_id']))
        vnf = TenorVNF(data['vnf_id'])
        tns = TenorNS(data['vnf_id'])
        resp = tns.register(data['name'])
        try:
            data = json.loads(resp.text)
        except Exception as exc:
            abort(500, message="Error decoding NS reg.: {0}".format(str(exc)))
        return {'state': 'PROVISIONED', 'ns_id': data['nsd']['id']}
Ejemplo n.º 7
0
    def post(self):
        """Post a new NSI"""
        apilog = ApiLog(method='POST', data=request.data)
        apilog.save()
        data = request.get_json()
        context = data['context']
        name = context['name_image']
        cached = "true"
        if 'cached' in context:
            cached = context['cached']
        if cached:
            cached = "true"
        vdu = TenorVDU(context['vm_image'], context['vm_image_format'],
                       context['flavor'], cached)
        key = RSA.generate(2048)
        pubkey = key.publickey()
        public_key_string = pubkey.exportKey('OpenSSH')
        if not 'bootstrap_script' in context:
            shell = None
            with open('keys/anella.json') as data_file:
                shell = json.load(data_file)
            context['bootstrap_script'] = shell['shell']
            context[
                'bootstrap_script'] = '#!/bin/bash\\necho \'{0}\' >> /root/.ssh/authorized_keys'.format(
                    public_key_string)
        try:
            vnf = TenorVNF(vdu)
            tns = TenorNS(vnf)
            name = TENOR_LABEL + '_{0}'.format(name)
            tns.register(name, context['bootstrap_script'])
            resp = None
            pop_id = POP_ID
            if 'pop_id' in context:
                pop_id = context['pop_id']
            if not 'public_network_id' in context:
                resp = tns.instantiate(pop_id)
            else:
                resp = tns.instantiate(pop_id, context['public_network_id'])
            nsdata = json.loads(resp.text)
        except Exception as exc:
            abort(500,
                  message="Error posting NS instance: {0}".format(str(exc)))
        if resp.status_code == 403:
            edata = json.loads(resp.text)
            abort(403, code=edata['message'])

        icd = build_instance_configuration(nsdata['id'],
                                           data['context']['consumer_params'],
                                           key.exportKey('PEM'))
        icd.save()
        return {'service_instance_id': nsdata['id'], 'state': 'PROVISIONED'}
Ejemplo n.º 8
0
 def delete(self, ns_id):
     """Deletes a NS"""
     vdu = TenorVDU()
     vnf = TenorVNF(vdu)
     tns = TenorNS(vnf)
     tns.set_dummy_id(ns_id)
     try:
         resp = tns.delete()
     except Exception as exc:
         abort(500, message="Error deleting NS: {0}".format(str(exc)))
     if resp.status_code == 200:
         return {'message': 'successfully deleted'}
     else:
         abort(resp.status_code,
               message='Error deleting {0} ns'.format(ns_id))