Beispiel #1
0
def build_template_lst_mixins(template_list):
    """
        Takes a list of templates and returns all template and term mixins
    """
    scheme = str(template_list["scheme"])
    terms_scheme = scheme[:-1] + "/terms#"

    temp_mxns = []
    term_mxns = []

    for temp_key, template in template_list["templates"].iteritems():
        related = [occi_sla.AGREEMENT_TEMPLATE]

        for term_key, term in template["terms"].iteritems():
            term_scheme = terms_scheme + term_key
            if term_scheme not in related:
                related.append(term_scheme)
        term_mxns += build_term_mixins2(temp_key, template["terms"], scheme)
        mxn = Mixin(scheme,
                    temp_key,
                    related=related,
                    title=temp_key,
                    attributes={})

        temp_mxns.append(mxn)
    return temp_mxns, flatten(term_mxns)
Beispiel #2
0
def get_category(category_string, categories, is_mixin=False):
    '''
    Create a Category from a string rendering.

    If found it will return the object from the registry.

    If is_mixin is set to true it will not match with the registry and just
    return a Mixin.

    category_string -- A string rendering of a category.
    categories -- A list of registered categories.
    is_mixin -- Mixin will be created and no matching will be done.
    '''
    # find term
    term = category_string[:category_string.find(';')].strip()

    # find scheme
    scheme = find_in_string(category_string, 'scheme')

    if is_mixin:
        location = find_in_string(category_string, 'location')
        if not location[0] == '/' or not location[-1] == '/':
            raise AttributeError('Illegal location; must start and end with /')
        return Mixin(scheme, term, location=location)

    # return the category from registry...
    tmp = Category(scheme, term, '', {}, '')
    for item in categories:
        if tmp == item:
            del (tmp)
            return item
    raise AttributeError('The following category is not registered within' +
                         ' this service (See Query interfaces): ' +
                         str(scheme) + str(term))
Beispiel #3
0
    def setUp(self):
        self.registry.set_hostname('http://127.0.0.1')
        self.app = Application([(r"(.*)/", CollectionWrapper)])

        self.registry.set_renderer('text/plain',
                                   TextPlainRendering(self.registry))
        self.registry.set_renderer('text/occi',
                                   TextOcciRendering(self.registry))
        self.registry.set_renderer('text/uri-list',
                                   TextUriListRendering(self.registry))

        self.mixin = Mixin('foo', 'mystuff')

        self.compute = Resource('/compute/1', COMPUTE, [])
        self.compute.attributes = {'foo2': 'bar2'}
        self.network = Resource('/network/1', NETWORK, [IPNETWORK])
        self.network_interface = Link('/network/interface/1', NETWORKINTERFACE,
                                      [IPNETWORKINTERFACE], self.compute,
                                      self.network)

        self.registry.set_backend(COMPUTE, SimpleComputeBackend())
        self.registry.set_backend(NETWORK, KindBackend())
        self.registry.set_backend(self.mixin, MixinBackend())
        self.registry.set_backend(START, SimpleComputeBackend())

        self.registry.add_resource(self.compute.identifier, self.compute)
        self.registry.add_resource(self.network.identifier, self.network)
        self.registry.add_resource(self.network_interface.identifier,
                                   self.network_interface)
Beispiel #4
0
    def setUp(self):
        self.kind1 = Kind('http://www.example.com#', 'foo')
        self.kind2 = Kind('http://www.example.com#', 'bar')
        self.mixin = Mixin('http://www.example.com#', 'mixin')

        self.registry.set_backend(self.kind1, KindBackend())
        self.registry.set_backend(self.kind2, KindBackend())
Beispiel #5
0
def build_term_mixins2(template_name, template_terms, scheme):
    """
        Pulls out terms from the template and adds them as mixins for the
        new template format
    """
    scheme = scheme[:-1] + "/terms#"
    related = [occi_sla.AGREEMENT_TERM]
    terms = []

    for term_key, term in template_terms.iteritems():
        attrs = {}

        term_metrics = term['metrics']

        attrs[term_key + '.term.desc'] = "immutable"
        attrs[term_key + '.term.state'] = "immutable"
        attrs[term_key + '.term.type'] = "immutable"
        if 'remedy' in term:
            attrs[term_key + '.term.remedy'] = "immutable"

        for metric_key in term_metrics:
            attrs[str(metric_key)] = "immutable"

        term = Mixin(scheme,
                     term_key,
                     related=related,
                     title=term_key,
                     attributes=attrs)
        terms.append(term)

    return terms
Beispiel #6
0
    def test_append_mixins_for_failure(self):
        '''
        Test if exception is thrown.
        '''
        # is not a mixin
        self.assertRaises(AttributeError, workflow.append_mixins, [self.kind2],
                          self.registry)

        # location collision
        mixin = Mixin('http://www.new.com#', 'mixin', location="/foo/")
        self.assertRaises(AttributeError, workflow.append_mixins, [mixin],
                          self.registry)

        # name collision
        mixin = Mixin('http://www.example.com#', 'foo', location="/stuff/")
        self.assertRaises(AttributeError, workflow.append_mixins, [mixin],
                          self.registry)
Beispiel #7
0
    def setUp(self):
        self.kind1 = Kind('http://example.com#', '1')
        self.kind2 = Kind('http://example.com#', '2')
        self.action = Action('http://example.com#', 'action')
        self.mixin = Mixin('http://example.com#', 'mixin')

        self.registry.set_backend(self.kind1, KindBackend())
        self.registry.set_backend(self.kind2, DummyBackend())
        self.registry.set_backend(self.action, ActionBackend())
        self.registry.set_backend(self.mixin, MixinBackend())

        self.entity = Resource('foo', self.kind1, [self.kind2])
 def setUp(self):
     action = Action('http://example.com/foo#', 'action')
     self.kind = Kind('http://example.com/foo#', 'bar',
                      'http://schemeas.ogf.org/occi/core#',
                       [action], 'Some bla bla',
                       {'foo': 'required', 'foo2': 'immutable', 'bar': ''},
                       '/foo/')
     mixin = Mixin('http://example.com/foo#', 'mixin')
     action = Action('http://example.com/foo#', 'action')
     self.target = Resource('/foo/target', self.kind, [], [])
     self.source = Resource('/foo/src', self.kind, [mixin], [])
     self.link = Link('/link/foo', self.kind, [], self.source, self.target)
     self.source.links = [self.link]
     self.source.actions = [action]
Beispiel #9
0
    def test_remove_mixins_for_failure(self):
        '''
        Test if only correct mixin get removed...
        '''
        mixin = Mixin('http://www.new.com#', 'mixin')
        self.registry.set_backend(mixin, MixinBackend())

        # not userdefined backend
        self.assertRaises(HTTPError, workflow.remove_mixins, [mixin],
                          self.registry)

        # not registeres
        self.assertRaises(HTTPError, workflow.remove_mixins, [self.mixin],
                          self.registry)

        # kind
        self.assertRaises(AttributeError, workflow.remove_mixins, [self.kind1],
                          self.registry)
Beispiel #10
0
def build_term_mixins(template_terms, scheme):
    """
        Pulls out terms from the template and adds them as mixins
    """
    scheme = scheme[:-1] + "/terms#"
    related = [occi_sla.AGREEMENT_TERM]
    terms = []

    for term_key, term in template_terms.iteritems():
        attrs = {}
        for metric_key in term:
            attrs[str(metric_key)] = "immutable"

        term = Mixin(scheme,
                     term_key,
                     related=related,
                     title=term_key,
                     attributes=attrs)
        terms.append(term)
Beispiel #11
0
    def setUp(self):
        self.kind = Kind('http://example.com/foo#', 'bar')
        self.link_kind = Kind('http://example.com/foo#', 'link')
        self.mixin = Mixin('http://example.com/foo#', 'mixin')

        target = Resource('/foo/target', self.kind, [], [])

        source = Resource('/foo/src', self.kind, [self.mixin], [])
        source.attributes = {'foo': 'bar'}

        link = Link('/link/foo', self.link_kind, [], source, target)
        link.attributes = {'foo': 'bar'}
        source.links = [link]

        self.resources = [source, target, link]
        for item in self.resources:
            self.registry.add_resource(item.identifier, item)

        self.registry.set_backend(self.kind, KindBackend())
        self.registry.set_backend(self.mixin, MixinBackend())
Beispiel #12
0
    def test_type_system_for_sanity(self):
        '''
        Test category, Action, Kind and Mixin.
        '''
        cat1 = Category('http://example.com#', 'foo', '', {}, '')
        cat2 = Category('http://example.com#', 'foo', '', {}, '')
        kind = Kind('http://example.com#', 'bar')
        action = Action('http://example.com#', 'action')
        mixin = Mixin('http://example.com#', 'mixin')

        # test eq
        self.assertEquals(cat1, cat2)
        self.assertFalse(cat1 == str)
        self.assertFalse(cat1 == kind)

        # test str
        self.assertEqual(str(cat1), 'http://example.com#foo')

        # test repr
        self.assertEqual(repr(kind), 'kind')
        self.assertEqual(repr(action), 'action')
        self.assertEqual(repr(mixin), 'mixin')
Beispiel #13
0
    def setUp(self):
        self.rendering = TextOcciRendering(self.registry)
        # type system...
        self.kind = Kind('http://example.com#', 'foo', related=[Resource.kind])
        self.invalid_kind = Kind('http://example.com#', 'invalid')
        self.link = Kind('http://example.com#', 'link', related=[Link.kind])
        self.mixin = Mixin('http://example.com#', 'mixin')
        self.action = Action('http://example.com#', 'action')

        self.registry.set_backend(self.kind, KindBackend())
        self.registry.set_backend(self.invalid_kind, KindBackend())
        self.registry.set_backend(self.link, KindBackend())
        self.registry.set_backend(self.mixin, MixinBackend())
        self.registry.set_backend(self.action, ActionBackend())

        # 2 linked entities
        self.entity = Resource('/foo/1', self.kind, [self.mixin])
        trg = Resource('/foo/2', self.kind, [], [])
        self.link1 = Link('/link/1', self.link, [], self.entity, trg)
        self.entity.links = [self.link1]

        self.registry.add_resource('/foo/2', trg)
        self.registry.add_resource('/link/1', self.link1)
        self.registry.add_resource('/foo/1', self.entity)
Beispiel #14
0
}

NETWORK = Kind('http://schemas.ogf.org/occi/infrastructure#', 'network',
               [Resource.kind], [UP, DOWN], 'Network Resource',
               NETWORK_ATTRIBUTES, '/network/')

#IP networking mixin

IPNETWORK_ATTRIBUTES = {
    'occi.network.address': '',
    'occi.network.gateway': '',
    'occi.network.allocation': ''
}

IPNETWORK = Mixin('http://schemas.ogf.org/occi/infrastructure/network#',
                  'ipnetwork',
                  attributes=IPNETWORK_ATTRIBUTES)

#==============================================================================
# Storage
#==============================================================================

ONLINE = Action('http://schemas.ogf.org/occi/infrastructure/storage/action#',
                'online', 'Bring storage online')

OFFLINE = Action('http://schemas.ogf.org/occi/infrastructure/storage/action#',
                 'offline', 'Bring storage offline')

BACKUP = Action('http://schemas.ogf.org/occi/infrastructure/storage/action#',
                'backup', 'Backup storage resource')
Beispiel #15
0
    },
    actions=[ACCEPT_ACTION, REJECT_ACTION, SUSPEND_ACTION, UNSUSPEND_ACTION],
    related=[Resource.kind],
    location="/agreement/")

#  Agreement Link Definition
# ************************************

AGREEMENT_LINK = Kind(scheme="http://schemas.ogf.org/occi/sla#",
                      term="agreement_link",
                      title="SLA Agreement Link",
                      related=[Link.kind],
                      location="/agreement_link/")

#  Agreement Term Definition
# ************************************

AGREEMENT_TERM = Mixin(scheme="http://schemas.ogf.org/occi/sla#",
                       term="agreement_term",
                       title="Agreement Term",
                       attributes={},
                       location="/agreement_term/")

#  Agreement Template  Definition
# ************************************

AGREEMENT_TEMPLATE = Mixin(scheme="http://schemas.ogf.org/occi/sla#",
                           term="agreement_tpl",
                           title="Agreement Template",
                           location="/agreement_tpl/")
Beispiel #16
0
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from occi.core_model import Mixin
from api import occi_sla

m1 = Mixin("http://www.ran_epc_sp.org/templates#",
                          "epc",
                          related=[occi_sla.AGREEMENT_TEMPLATE],
                          title="EPC SLA Template",
                          attributes={"epc.occi.SLO_A": "immutable",
                                      "epc.occi.SLO_B": "required",
                                      "epc.occi.SLO_K": "required"})

m2 = Mixin("http://www.ran_epc_sp.org/templates#",
                          "ran",
                          related=[occi_sla.AGREEMENT_TEMPLATE],
                          title="RAN SLA Template",
                          attributes={"ran.occi.SLO_1": "required",
                                      "ran.occi.SLO_2": "immutable",
                                      "ran.occi.SLO_3": '',
                                      "ran.occi.SLO_4": ''})
Beispiel #17
0
# See the License for the specific language governing permissions and
# limitations under the License.
#
from occi.core_model import Kind
from occi.core_model import Link
from occi.core_model import Mixin
from occi.core_model import Action
from occi.core_model import Resource
from api import occi_sla
from occi.core_model import Mixin
# **************************** test_backends *********************************

# m1 & m2 are used in test_attributes_belong_to_agreement_or_mixin
# These mixins just need to have attributes

m1 = Mixin("", "", attributes={"uptime":"mutable","cpu_load":"mutable"})
m2 = Mixin("", "", attributes={"filtering":"immutable",
                             "location":"mutable",
                             "thru_put":"mutable"})
m3 = Mixin("", "", attributes={"os": "mutable","vm_cores": "required",
                    "memory": "required" })


# Complete Mixins

epc_mixin = Mixin("http://www.ran_epc_sp.org/templates#",
                          "epc",
                          related=[occi_sla.AGREEMENT_TEMPLATE],
                          title="EPC SLA Template",
                          attributes={"epc.occi.SLO_A": "immutable",
                                      "epc.occi.SLO_B": "required",