Exemplo n.º 1
0
    def validate_sdn_account_credentials(self, loop, name):
        self._log.debug("Validating SDN Account credentials %s", name)
        self._status = RwsdnYang.SDNAccount_ConnectionStatus(
            status="validating",
            details="SDN account connection validation in progress")

        _sdnacct = self.get_sdn_account(name)
        if (_sdnacct is None):
            raise SdnGetPluginError
        _sdnplugin = self.get_sdn_plugin(name)
        if (_sdnplugin is None):
            raise SdnGetInterfaceError

        rwstatus, status = yield from loop.run_in_executor(
            None,
            _sdnplugin.validate_sdn_creds,
            _sdnacct,
        )

        if rwstatus == RwTypes.RwStatus.SUCCESS:
            self._status = RwsdnYang.SDNAccount_ConnectionStatus.from_dict(
                status.as_dict())
        else:
            self._status = RwsdnYang.SDNAccount_ConnectionStatus(
                status="failure",
                details="Error when calling CAL validate sdn creds")

        self._log.info("Got sdn account validation response: %s", self._status)
        _sdnacct.connection_status = self._status
Exemplo n.º 2
0
 def set_sdn_account(self,account):
     if (account.name in self._account):
         self._log.error("SDN Account is already set")
     else:
         sdn_account           = RwsdnYang.SDNAccount()
         sdn_account.from_dict(account.as_dict())
         sdn_account.name = account.name
         self._account[account.name] = sdn_account
         self._log.debug("Account set is %s , %s",type(self._account), self._account)
Exemplo n.º 3
0
def get_sdn_account():
    """
    Creates an object for class RwsdnYang.SdnAccount()
    """
    account                 = RwsdnYang.SDNAccount()
    account.account_type    = "mock"
    account.mock.username   = "******"
    account.mock.plugin_name = "rwsdn_mock"
    return account
Exemplo n.º 4
0
def get_sdn_account():
    """
    Creates an object for class RwsdnYang.SdnAccount()
    """
    account = RwsdnYang.SDNAccount()
    account.account_type = "sdnsim"
    account.sdnsim.username = "******"
    account.sdnsim.plugin_name = "rwsdn_sim"
    return account
Exemplo n.º 5
0
    def __init__(self, log, log_hdl, loop):
        self._account = {}
        self._log = log
        self._log_hdl = log_hdl
        self._loop = loop
        self._sdn = {}

        self._regh = None

        self._status = RwsdnYang.SDNAccount_ConnectionStatus(
            status='unknown', details="Connection status lookup not started")

        self._validate_task = None
Exemplo n.º 6
0
    def do_init(self, rwlog_ctx):
        if not any(isinstance(h, rwlogger.RwLogger) for h in logger.handlers):
            logger.addHandler(
                rwlogger.RwLogger(
                    subcategory="rwsdn.mock",
                    log_hdl=rwlog_ctx,
                ))

        account = RwsdnYang.SDNAccount()
        account.name = 'mock'
        account.account_type = 'mock'
        account.mock.username = '******'

        self.datastore = DataStore()
        self.topology = self.datastore.create_default_topology()
Exemplo n.º 7
0
    def do_validate_sdn_creds(self, account):
        """
        Validates the sdn account credentials for the specified account.
        Performs an access to the resources using Keystone API. If creds
        are not valid, returns an error code & reason string

        @param account - a SDN account

        Returns:
            Validation Code and Details String
        """
        status = RwsdnYang.SdnConnectionStatus()
        print("SDN Successfully connected")
        status.status = "success"
        status.details = "Connection was successful"
        #logger.debug('Done with validate SDN creds: %s', type(status))
        return status
Exemplo n.º 8
0
    def create_vnffgr(self, vnffgr,classifier_list,sff_list):
        """
        """
        self._log.debug("Received VNFFG chain Create msg %s",vnffgr)
        if vnffgr.id in self._vnffgr_list:
            self._log.error("VNFFGR with id %s already present in VNFFGMgr", vnffgr.id)
            vnffgr.operational_status = 'failed'
            msg = "VNFFGR with id {} already present in VNFFGMgr".format(vnffgr.id)
            raise VnffgrAlreadyExist(msg)

        self._vnffgr_list[vnffgr.id] = vnffgr
        vnffgr.operational_status = 'init'
        if len(self._account) == 0:
            self._log.error("SDN Account not configured")
            vnffgr.operational_status = 'failed'
            return
        if vnffgr.sdn_account:
            sdn_acct_name = vnffgr.sdn_account
        else:
            self._log.error("SDN Account is not associated to create VNFFGR")
            # TODO Fail the VNFFGR creation if SDN account is not associated
            #vnffgr.operational_status = 'failed'
            #msg = "SDN Account is not associated to create VNFFGR"
            #raise VnffgrCreationFailed(msg)
            sdn_account = [sdn_account.name for _,sdn_account in self._account.items()]
            sdn_acct_name = sdn_account[0]
            vnffgr.sdn_account = sdn_acct_name
        sdn_plugin = self.get_sdn_plugin(sdn_acct_name)

        for rsp in vnffgr.rsp:
            vnffg = RwsdnYang.VNFFGChain()
            vnffg.name = rsp.name
            vnffg.classifier_name = rsp.classifier_name

            vnfr_list = list()
            for index,cp_ref in enumerate(rsp.vnfr_connection_point_ref):
                cpath = vnffg.vnf_chain_path.add()
                cpath.order=cp_ref.hop_number
                cpath.service_function_type = cp_ref.service_function_type
                cpath.nsh_aware=True
                cpath.transport_type = 'vxlan-gpe'

                vnfr=cpath.vnfr_ids.add()
                vnfr.vnfr_id = cp_ref.vnfr_id_ref
                vnfr.vnfr_name = cp_ref.vnfr_name_ref
                vnfr.mgmt_address = cp_ref.connection_point_params.mgmt_address
                vnfr.mgmt_port = 5000
                vnfr_list.append(vnfr)
            
                vdu = vnfr.vdu_list.add()
                vdu.name = cp_ref.connection_point_params.name
                vdu.port_id = cp_ref.connection_point_params.port_id
                vdu.vm_id = cp_ref.connection_point_params.vm_id
                vdu.address = cp_ref.connection_point_params.address
                vdu.port =  cp_ref.connection_point_params.port

            for sff in sff_list.values():
                _sff = vnffg.sff.add()
                _sff.from_dict(sff.as_dict())
                if sff.function_type == 'SFF':
                    for vnfr in vnfr_list:
                        vnfr.sff_name = sff.name
                self._log.debug("Recevied SFF %s, Created SFF is %s",sff, _sff)

            self._log.debug("VNFFG chain msg is %s",vnffg)
            rc,rs = sdn_plugin.create_vnffg_chain(self._account[sdn_acct_name],vnffg)
            if rc != RwTypes.RwStatus.SUCCESS:
                vnffgr.operational_status = 'failed'
                msg = "Instantiation of VNFFGR with id {} failed".format(vnffgr.id)
                raise VnffgrCreationFailed(msg)

            self._log.info("VNFFG chain created successfully for rsp with id %s",rsp.id)


        meta = {}
        if(len(classifier_list) == 2):
            meta[vnffgr.classifier[0].id] = '0x' + ''.join(str("%0.2X"%int(i)) for i in vnffgr.classifier[1].ip_address.split('.'))
            meta[vnffgr.classifier[1].id] = '0x' + ''.join(str("%0.2X"%int(i)) for i in vnffgr.classifier[0].ip_address.split('.'))
            
        self._log.debug("VNFFG Meta VNFFG chain is {}".format(meta))
        
        for classifier in classifier_list:
            vnffgr_cl = [_classifier  for _classifier in vnffgr.classifier if classifier.id == _classifier.id]
            if len(vnffgr_cl) > 0:
                cl_rsp_name = vnffgr_cl[0].rsp_name
            else:
                self._log.error("No RSP wiht name %s found; Skipping classifier %s creation",classifier.rsp_id_ref,classifier.name)
                continue
            vnffgcl = RwsdnYang.VNFFGClassifier()
            vnffgcl.name = classifier.name
            vnffgcl.rsp_name = cl_rsp_name
            vnffgcl.port_id = vnffgr_cl[0].port_id
            vnffgcl.vm_id = vnffgr_cl[0].vm_id
            # Get the symmetric classifier endpoint ip and set it in nsh ctx1
            
            vnffgcl.vnffg_metadata.ctx1 =  meta.get(vnffgr_cl[0].id,'0') 
            vnffgcl.vnffg_metadata.ctx2 = '0'
            vnffgcl.vnffg_metadata.ctx3 = '0'
            vnffgcl.vnffg_metadata.ctx4 = '0'
            if vnffgr_cl[0].has_field('sff_name'):
                vnffgcl.sff_name = vnffgr_cl[0].sff_name
            for index,match_rule in enumerate(classifier.match_attributes):
                acl = vnffgcl.match_attributes.add()
                #acl.name = vnffgcl.name + str(index)
                acl.name = match_rule.id
                acl.ip_proto  = match_rule.ip_proto
                acl.source_ip_address = match_rule.source_ip_address + '/32'
                acl.source_port = match_rule.source_port
                acl.destination_ip_address = match_rule.destination_ip_address + '/32'
                acl.destination_port = match_rule.destination_port

            self._log.debug(" Creating VNFFG Classifier Classifier %s for RSP: %s",vnffgcl.name,vnffgcl.rsp_name)
            rc,rs = sdn_plugin.create_vnffg_classifier(self._account[sdn_acct_name],vnffgcl)
            if rc != RwTypes.RwStatus.SUCCESS:
                self._log.error("VNFFG Classifier cretaion failed for Classifier %s for RSP ID: %s",classifier.name,classifier.rsp_id_ref)
                #vnffgr.operational_status = 'failed'
                #msg = "Instantiation of VNFFGR with id {} failed".format(vnffgr.id)
                #raise VnffgrCreationFailed(msg)

        vnffgr.operational_status = 'running'
        self.update_vnffgrs(vnffgr.sdn_account)
        return vnffgr