Example #1
0
File: ch.py Project: EICT/C-BAS
    def CreateSlice(self, urn_req = None):
        self.logger.info("Called CreateSlice URN REQ %r" % urn_req)
        slice_gid = None

        if urn_req and self.slices.has_key(urn_req):
            # If the Slice has expired, treat this as
            # a request to renew
            slice_cred = self.slices[urn_req]
            slice_exp = self._naiveUTC(slice_cred.expiration)
            if slice_exp <= datetime.datetime.utcnow():
                # Need to renew this slice
                self.logger.info("CreateSlice on %r found existing cred that expired at %r - will renew", urn_req, slice_exp)
                slice_gid = slice_cred.get_gid_object()
            else:
                self.logger.debug("Slice cred is still valid at %r until %r - return it", datetime.datetime.utcnow(), slice_exp)
                return slice_cred.save_to_string()

        # Create a random uuid for the slice
        slice_uuid = uuid.uuid4()

        # First ensure we have a slice_urn
        if urn_req:
            # Validate urn_req has the right form
            # to be issued by this CH
            if not urn_util.is_valid_urn(urn_req):
                # FIXME: make sure it isnt empty, etc...
                urn = urn_util.publicid_to_urn(urn_req)
            else:
                urn = urn_req

            # Validate the urn meets name restrictions
            if not urn_util.is_valid_urn_bytype(urn, 'slice', self.logger):
                raise Exception("Cannot create slice with urn %s: URN is invalid" % urn)
        else:
            # Generate a unique URN for the slice
            # based on this CH location and a UUID

            # Where was the slice created?
            (ipaddr, port) = self._server.socket._sock.getsockname()
            # FIXME: Get public_id start from a properties file
            # Create a unique name for the slice based on uuid
            slice_name = slice_uuid.__str__()[4:12]
            public_id = 'IDN %s slice %s//%s:%d' % (SLICE_AUTHORITY, slice_name,
                                                                   ipaddr,
                                                                   port)
            # this func adds the urn:publicid:
            # and converts spaces to +'s, and // to :
            urn = urn_util.publicid_to_urn(public_id)

        # Now create a GID for the slice (signed credential)
        if slice_gid is None:
            # FIXME: For APIv3 compliance, we need
            # - slice email address
            # - unique cert serial number
            try:
                slice_gid = cert_util.create_cert(urn, self.keyfile, self.certfile, uuidarg = slice_uuid)[0]
            except Exception, exc:
                self.logger.error("Cant create slice gid for slice urn %s: %s", urn, traceback.format_exc())
                raise Exception("Failed to create slice %s. Cant create slice gid" % urn, exc)
Example #2
0
    def CreateSlice(self, urn_req=None):
        self.logger.info("Called CreateSlice URN REQ %r" % urn_req)
        slice_gid = None

        if urn_req and self.slices.has_key(urn_req):
            # If the Slice has expired, treat this as
            # a request to renew
            slice_cred = self.slices[urn_req]
            if slice_cred.expiration <= datetime.datetime.utcnow():
                # Need to renew this slice
                self.logger.info(
                    "CreateSlice on %r found existing cred that expired at %r - will renew",
                    urn_req, slice_cred.expiration)
                slice_gid = slice_cred.get_gid_object()
            else:
                self.logger.debug(
                    "Slice cred is still valid at %r until %r - return it",
                    datetime.datetime.utcnow(), slice_cred.expiration)
                return slice_cred.save_to_string()

        # First ensure we have a slice_urn
        if urn_req:
            # FIXME: Validate urn_req has the right form
            # to be issued by this CH
            if not urn_util.is_valid_urn(urn_req):
                # FIXME: make sure it isnt empty, etc...
                urn = urn_util.publicid_to_urn(urn_req)
            else:
                urn = urn_req
        else:
            # Generate a unique URN for the slice
            # based on this CH location and a UUID

            # Where was the slice created?
            (ipaddr, port) = self._server.socket._sock.getsockname()
            # FIXME: Get public_id start from a properties file
            # Create a unique name for the slice based on uuid
            slice_name = uuid.uuid4().__str__()[4:12]
            public_id = 'IDN %s slice %s//%s:%d' % (SLICE_AUTHORITY,
                                                    slice_name, ipaddr, port)
            # this func adds the urn:publicid:
            # and converts spaces to +'s, and // to :
            urn = urn_util.publicid_to_urn(public_id)

        # Now create a GID for the slice (signed credential)
        if slice_gid is None:
            try:
                slice_gid = cert_util.create_cert(urn, self.keyfile,
                                                  self.certfile)[0]
            except Exception, exc:
                self.logger.error("Cant create slice gid for slice urn %s: %s",
                                  urn, traceback.format_exc())
                raise Exception(
                    "Failed to create slice %s. Cant create slice gid" % urn,
                    exc)
Example #3
0
File: am_gib.py Project: EICT/C-BAS
 def __init__(self, root_cert, urn_authority, url):
     self._url = url
     self._api_version = 2
     self._slices = dict()
     self._agg = Aggregate()
     self._agg.add_resources([FakeVM(self._agg) for _ in range(3)])
     self._cred_verifier = geni.CredentialVerifier(root_cert)
     self._urn_authority = urn_authority
     self._my_urn = publicid_to_urn("%s %s %s" % (self._urn_authority, 'authority', 'am'))
     self.max_lease = datetime.timedelta(days=REFAM_MAXLEASE_DAYS)
     self.logger = logging.getLogger('gcf.am2')
Example #4
0
 def __init__(self, root_cert, urn_authority, url):
     self._url = url
     self._api_version = 2
     self._slices = dict()
     self._agg = Aggregate()
     self._agg.add_resources([FakeVM(self._agg) for _ in range(3)])
     self._cred_verifier = geni.CredentialVerifier(root_cert)
     self._urn_authority = urn_authority
     self._my_urn = publicid_to_urn("%s %s %s" % (self._urn_authority, 'authority', 'am'))
     self.max_lease = datetime.timedelta(days=REFAM_MAXLEASE_DAYS)
     self.logger = logging.getLogger('gcf.am2')
Example #5
0
    def test_external_rspec(self):
        self.test_create_aggregates()
        adv_rspec = rspec_mod.get_resources(None, None)

        d1 = rspec_mod.parse_external_rspec(adv_rspec)

        # replace all the urn prefixes with external ones
        test_prefix = publicid_to_urn(
            "IDN %s//%s" % ("test//test", settings.OPENFLOW_GCF_BASE_SUFFIX))
        adv_rspec2 = adv_rspec.replace(rspec_mod.OPENFLOW_GAPI_RSC_URN_PREFIX,
                                       test_prefix)

        d2 = rspec_mod.parse_external_rspec(adv_rspec2)

        self.assertEqual(d1, d2)
Example #6
0
    def test_external_rspec(self):
        self.test_create_aggregates()
        adv_rspec = rspec_mod.get_resources(None, None)
        
        d1 = rspec_mod.parse_external_rspec(adv_rspec)
        
        # replace all the urn prefixes with external ones
        test_prefix = publicid_to_urn(
            "IDN %s//%s" % ("test//test", settings.OPENFLOW_GCF_BASE_SUFFIX)
        )
        adv_rspec2 = adv_rspec.replace(
            rspec_mod.OPENFLOW_GAPI_RSC_URN_PREFIX, test_prefix)

        d2 = rspec_mod.parse_external_rspec(adv_rspec2)
        
        self.assertEqual(d1, d2)
Example #7
0
PORT_TAG = "port"

VERSION = "version"

CURRENT_ADV_VERSION = "2"

URN = "urn"
SRC_URN = "src_urn"
DST_URN = "dst_urn"

LOCATION = "location"
NAME = "name"
FLOWVISOR_URL = "flowvisor_url"

OPENFLOW_GAPI_RSC_URN_PREFIX = publicid_to_urn(
    "IDN %s//%s" % (settings.GCF_BASE_NAME, settings.OPENFLOW_GCF_BASE_SUFFIX)
)

SWITCH_URN_REGEX = r"^%s\+switch:(?P<dpid>[\d:a-fA-F]+)$" % \
    OPENFLOW_GAPI_RSC_URN_PREFIX.replace("+", r"\+")
PORT_URN_REGEX = r"%s\+port:(?P<port>\d+)$" % SWITCH_URN_REGEX[:-1]

switch_re = re.compile(SWITCH_URN_REGEX)
port_re = re.compile(PORT_URN_REGEX)

EXTERNAL_SWITCH_URN_REGEX = r"^(?P<prefix>.*)\+switch:(?P<dpid>[:a-fA-F\d]+)$"
EXTERNAL_PORT_URN_REGEX = r"%s\+port:(?P<port>\d+)$" % EXTERNAL_SWITCH_URN_REGEX[:-1]

external_switch_re = re.compile(EXTERNAL_SWITCH_URN_REGEX)
external_port_re = re.compile(EXTERNAL_PORT_URN_REGEX)
Example #8
0
File: am_gib.py Project: EICT/C-BAS
 def resource_urn(self, resource):
     urn = publicid_to_urn("%s %s %s" % (self._urn_authority,
                                         str(resource.type),
                                         str(resource.id)))
     return urn
Example #9
0
'''
Created on Oct 6, 2010

@author: jnaous
'''
from django.db import models
from django.conf import settings
from openflow.plugin.gapi import gapi, rspec
from geni.util.urn_util import publicid_to_urn

OTHER_BASENAME = "test//test"
OTHER_PREFIX = publicid_to_urn(
    "IDN %s//%s" % (OTHER_BASENAME, settings.OPENFLOW_GCF_BASE_SUFFIX))


class DummyOFAggregate(models.Model):
    adv_rspec = models.XMLField()
    resv_rspec = models.XMLField(null=True, blank=True)

    def snapshot_switches(self):
        self.adv_rspec = gapi.ListResources({}, None)
        self.adv_rspec = self.adv_rspec.replace(
            rspec.OPENFLOW_GAPI_RSC_URN_PREFIX, OTHER_PREFIX)
        self.save()
Example #10
0
'''
Created on Oct 6, 2010

@author: jnaous
'''
from django.db import models
from django.conf import settings
from openflow.plugin.gapi import gapi, rspec
from geni.util.urn_util import publicid_to_urn

OTHER_BASENAME ="test//test"
OTHER_PREFIX = publicid_to_urn(
    "IDN %s//%s"
    % (OTHER_BASENAME, settings.OPENFLOW_GCF_BASE_SUFFIX)
)

class DummyOFAggregate(models.Model):
    adv_rspec = models.XMLField()
    resv_rspec = models.XMLField(null=True, blank=True)
    
    def snapshot_switches(self):
        self.adv_rspec = gapi.ListResources({}, None)
        self.adv_rspec = self.adv_rspec.replace(
            rspec.OPENFLOW_GAPI_RSC_URN_PREFIX, OTHER_PREFIX)
        self.save()
Example #11
0
 def resource_urn(self, resource):
     urn = publicid_to_urn("%s %s %s" % (self._urn_authority,
                                         str(resource.type),
                                         str(resource.id)))
     return urn
Example #12
0
PORT_NUM_TAG = "port_num"
PORT_TAG = "port"

VERSION = "version"

CURRENT_ADV_VERSION = "2"

URN = "urn"
SRC_URN = "src_urn"
DST_URN = "dst_urn"

LOCATION = "location"
NAME = "name"
FLOWVISOR_URL = "flowvisor_url"

OPENFLOW_GAPI_RSC_URN_PREFIX = publicid_to_urn(
    "IDN %s//%s" % (settings.GCF_BASE_NAME, settings.OPENFLOW_GCF_BASE_SUFFIX))

SWITCH_URN_REGEX = r"^%s\+switch:(?P<dpid>[\d:a-fA-F]+)$" % \
    OPENFLOW_GAPI_RSC_URN_PREFIX.replace("+", r"\+")
PORT_URN_REGEX = r"%s\+port:(?P<port>\d+)$" % SWITCH_URN_REGEX[:-1]

switch_re = re.compile(SWITCH_URN_REGEX)
port_re = re.compile(PORT_URN_REGEX)

EXTERNAL_SWITCH_URN_REGEX = r"^(?P<prefix>.*)\+switch:(?P<dpid>[:a-fA-F\d]+)$"
EXTERNAL_PORT_URN_REGEX = r"%s\+port:(?P<port>\d+)$" % EXTERNAL_SWITCH_URN_REGEX[:
                                                                                 -1]

external_switch_re = re.compile(EXTERNAL_SWITCH_URN_REGEX)
external_port_re = re.compile(EXTERNAL_PORT_URN_REGEX)