Esempio n. 1
0
    def test_create_10_tags(self):
        types = ['public', 'private']
        for i in range(10):
            new_tag = resource.Resource(type_name='tag_management.tag',
                                        rest_end_point=self.space)
            new_tag.name = 'ApiTestTag' + str(i)
            new_tag.type = types[i % 2]
            new_tag = self.space.tag_management.tags.post(new_tag)

        assert i == 9, "Failed to create 10 tags"
Esempio n. 2
0
    def test_assign_tag_on_2_devices(self):
        tags_list = self.space.tag_management.tags.get(
            filter_={'name': 'ApiTestTag2'})
        assert tags_list[0].name == 'ApiTestTag2', "No tag ApiTestTag2"

        devices_list = self.space.device_management.devices.get()
        assert len(devices_list) > 1, "Not enough devices on Space"

        my_targets = [
            resource.Resource('tag_management.target', self.space),
            resource.Resource('tag_management.target', self.space)
        ]
        my_targets[0].href = devices_list[0].href
        my_targets[1].href = devices_list[1].href

        tags_list[0].targets.post(my_targets)

        targets_list = tags_list[0].targets.get()
        assert len(targets_list) == len(my_targets)
Esempio n. 3
0
 def _create_resource(self, xml_data):
     """
     Helper method to create a resource under this collection. This is used
     to populate entries in the list returned by the get() method of this
     collection.
     """
     if self._meta_object.resource_type:
         from jnpr.space import resource
         return resource.Resource(type_name=self._meta_object.resource_type,
                                  rest_end_point=self._rest_end_point,
                                  xml_data=xml_data,
                                  parent=self)
     else:
         xml_str = etree.tostring(xml_data, encoding='unicode')
         return xmlutil.xml2obj(xml_str)
Esempio n. 4
0
    def test_assign_tag_on_1_device(self):
        tags_list = self.space.tag_management.tags.get(
            filter_={'name': 'ApiTestTag1'})
        assert tags_list[0].name == 'ApiTestTag1', "No tag ApiTestTag1"

        devices_list = self.space.device_management.devices.get()
        assert len(devices_list) > 0, "Not enough devices on Space"

        my_target = resource.Resource('tag_management.target', self.space)
        my_target.href = devices_list[0].href

        tags_list[0].targets.post(my_target)

        targets_list = tags_list[0].targets.get()
        assert len(targets_list) == 1
Esempio n. 5
0
def make_resource(type_name, rest_end_point,
                  xml_data=None, attributes=None, parent=None):
    """Creates a new instance of jnpr.space.resource.Resource based on the
    given parameters. This method creates it in-memory locally and *not* on
    the Space server. The post() method must be invoked on the Resource object
    to get it created on the Space server.

    :param str type_name: Fully qualified type name for the Resource to be
        created. It is of the format ``<service_name>.<resource_type>``.
        Some examples are:

            * ``device_management.device``
            * ``user_management.user``

    :param rest_end_point: A *Space* object encapsulating the Junos
        Space cluster which is to contain this resource.
    :type rest_end_point: jnpr.space.rest.Space

    :param lxml.etree.Element xml_data:  The state of the resource as an
        XML object. This defaults to ``None``.

    :param dict attributes:  The state of the resource as a dict where the
        keys are attribute names and values are attribute values.
        This defaults to ``None``.

    :param parent: The parent object of this resource. This defaults to
        ``None``.
    :type parent: jnpr.space.collection.Collection

    :returns: A new instance of jnpr.space.resource.Resource

    """
    return resource.Resource(type_name,
                             rest_end_point,
                             xml_data,
                             attributes,
                             parent)
Esempio n. 6
0
 def test_create_resource_error_3(self):
     with pytest.raises(Exception):
         resource.Resource(type_name='tag_management.tagg',
                           rest_end_point=self.space)