Exemple #1
0
    def test_getid(self):
        self.assertEqual(base.getid(4), 4)

        class TmpObject(object):
            id = 4

        self.assertEqual(base.getid(TmpObject), 4)
    def deactivate(self, zone, node, options):
        """Deactivates the given node."""

        url = '/zones/{}/nodes/{}/deactivate'.format(base.getid(zone),
                                                     base.getid(node))

        return self._post(url, body=options, response_key='device')
    def execute_service(self, zone, role, component, service, node):
        """Execute a specific service by zone, role, component

        :param zone: The ID of the :class: `Zone` to get.
        :rtype: :class:`Zone`

        :param role: The ID of the :class: `Role` to get.
        :rtype: :class:`Zone`

        :param component: The ID (Name of the component) of the :class:
        `Component` to get.
        :rtype: :class:`Component`

        :param service: The ID of the :class: `Service` to get.
        :rtype: :class:`Service`

        :param node: The ID of the :class: `Node` where to execute the action.
        :rtype: :class:`Node`
        """

        body = {
            'node_id': base.getid(node)
        }

        res = self._create("/zones/%s/roles/%s/components/%s/services/%s"
                           % (base.getid(zone),
                              base.getid(role),
                              component.name,
                              service.name), body=body, response_key="task")
        res.zone = zone
        res.node = node
        return res
Exemple #4
0
    def execute_service(self, zone, role, component, service, node):
        """Execute a specific service by zone, role, component

        :param zone: The ID of the :class: `Zone` to get.
        :rtype: :class:`Zone`

        :param role: The ID of the :class: `Role` to get.
        :rtype: :class:`Zone`

        :param component: The ID (Name of the component) of the :class:
        `Component` to get.
        :rtype: :class:`Component`

        :param service: The ID of the :class: `Service` to get.
        :rtype: :class:`Service`

        :param node: The ID of the :class: `Node` where to execute the action.
        :rtype: :class:`Node`
        """

        body = {'node_id': base.getid(node)}

        res = self._create(
            "/zones/%s/roles/%s/components/%s/services/%s" %
            (base.getid(zone), base.getid(role), component.name, service.name),
            body=body,
            response_key="task")
        res.zone = zone
        res.node = node
        return res
    def deactivate(self, zone, node, options):
        """Deactivates the given node."""

        url = '/zones/{}/nodes/{}/deactivate'.format(base.getid(zone),
                                                     base.getid(node))

        return self._post(url, body=options, response_key='device')
    def list_zone_role(self, zone, role):
        """Get all components by zone and role.

        :param zone: The ID of the :class: `Zone` to get.
        :rtype: :class:`Zone`

        :param role: The ID of the :class: `Role` to get.
        :rtype: :class:`Zone`
        """
        return self._list("/zones/%s/roles/%s/components" % (base.getid(zone),
                                                             base.getid(role)),
                          "components")
Exemple #7
0
    def list_node(self, zone, node):
        """Get all tasks by zone and node.

        :param zone: The ID of the :class: `Zone` to get.
        :rtype: :class:`Zone`

        :param profile: The ID of the :class: `Node` to get.
        :rtype: :class:`Node`
        """
        return self._list(
            "/zones/%s/nodes/%s/tasks" % (base.getid(zone), base.getid(node)),
            "tasks")
    def list_zone_role(self, zone, role):
        """Get all components by zone and role.

        :param zone: The ID of the :class: `Zone` to get.
        :rtype: :class:`Zone`

        :param role: The ID of the :class: `Role` to get.
        :rtype: :class:`Zone`
        """
        return self._list(
            "/zones/%s/roles/%s/components" %
            (base.getid(zone), base.getid(role)), "components")
    def list_node(self, zone, node):
        """Get all tasks by zone and node.

        :param zone: The ID of the :class: `Zone` to get.
        :rtype: :class:`Zone`

        :param profile: The ID of the :class: `Node` to get.
        :rtype: :class:`Node`
        """
        return self._list("/zones/%s/nodes/%s/tasks" % (base.getid(zone),
                                                        base.getid(node)),
                          "tasks")
Exemple #10
0
    def delete(self, architecture, profile):
        """
        Delete a profile.

        :param architecture: The ID of the :class: `Architecture` to get.
        :rtype: :class:`Architecture`

        :param profile: The ID of the :class: `Profile` to delete.
        :rtype: :class:`Profile`
        """

        self._delete("/archs/%s/profiles/%s" %
                     (base.getid(architecture), base.getid(profile)))
    def delete(self, architecture, profile):
        """
        Delete a profile.

        :param architecture: The ID of the :class: `Architecture` to get.
        :rtype: :class:`Architecture`

        :param profile: The ID of the :class: `Profile` to delete.
        :rtype: :class:`Profile`
        """

        self._delete("/archs/%s/profiles/%s" % (base.getid(architecture),
                                                base.getid(profile)))
Exemple #12
0
    def state(self, zone, node, task):
        """Get a specific task by zone and node.

        :param zone: The ID of the :class: `Zone` to get.
        :rtype: :class:`Zone`

        :param profile: The ID of the :class: `Node` to get.
        :rtype: :class:`Node`

        :param profile: The ID of the :class: `Task` to get.
        :rtype: :class:`Task`
        """
        return self._get(
            "/zones/%s/nodes/%s/tasks/%s/state" %
            (base.getid(zone), base.getid(node), task.uuid), "task")
    def delete(self, architecture):
        """
        Delete an architecture.

        :param architecture: The :class:`Architecture` to delete.
        """
        self._delete("/archs/%s" % base.getid(architecture))
Exemple #14
0
    def delete(self, zone, task, node):
        """
        Delete a specific task.

        :param zone: The  ID of the :class: `Zone` to get.
        :rtype: :class:`Zone`

        :param task: The UUID of the :class: `Task` to delete.
        :rtype: :class:`Task`

        :param node: The ID of the :class: `Node` to get
        :rtype: :class:`Node`
        """

        self._delete("/zones/%s/nodes/%s/tasks/%s" %
                     (base.getid(zone), base.getid(node), task.uuid))
    def get(self, zone):
        """Get a specific zone .

        :param zone: The ID of the :class: `Zone` to get.
        :rtype: :class:`Zone`
        """
        return self._get("/zones/%s" % base.getid(zone), "zone")
    def list(self, zone):
        """Get a list of nodes by a specific zone.

        :param zone: The ID of the :class: `Zone` to get its nodes.
        :rtype: :class:`Zone`
        """
        return self._list("/zones/%s/nodes" % base.getid(zone), "nodes")
    def delete(self, datastore):
        """
       Delete an datastore.

       :param datastore: The :class:`Datastore` to delete.
       """
        self._delete("/datastores/%s" % base.getid(datastore))
    def delete(self, datastore):
        """
       Delete an datastore.

       :param datastore: The :class:`Datastore` to delete.
       """
        self._delete("/datastores/%s" % base.getid(datastore))
    def get(self, zone):
        """Get a specific zone .

        :param zone: The ID of the :class: `Zone` to get.
        :rtype: :class:`Zone`
        """
        return self._get("/zones/%s" % base.getid(zone), "zone")
Exemple #20
0
    def delete(self, architecture):
        """
        Delete an architecture.

        :param architecture: The :class:`Architecture` to delete.
        """
        self._delete("/archs/%s" % base.getid(architecture))
    def get_node(self, zone, node, task):
        """Get a specific task by zone and node.

        :param zone: The ID of the :class: `Zone` to get.
        :rtype: :class:`Zone`

        :param profile: The ID of the :class: `Node` to get.
        :rtype: :class:`Node`

        :param profile: The ID of the :class: `Task` to get.
        :rtype: :class:`Task`
        """
        return self._get("/zones/%s/nodes/%s/tasks/%s" % (base.getid(zone),
                                                          base.getid(node),
                                                          task),
                         "task")
Exemple #22
0
    def cancel(self, zone, node, task):
        """Cancel a task by zone and node.

        :param zone: The ID of the :class: `Zone` to get.
        :rtype: :class:`Zone`

        :param role: The ID of the :class: `Node` to get.
        :rtype: :class:`Node`

        :param role: The ID of the :class: `Task` to get.
        :rtype: :class:`Task`
        """

        return self.api.client.post(
            "/zones/%s/nodes/%s/tasks/%s/cancel" %
            (base.getid(zone), base.getid(node), task.uuid))
    def get(self, datastore):
        """Get a specific datastore from pool.

        :param datastore: The ID of the :class: `Datastore` to get.
        :rtype: :class:`Datastore`
        """

        return self._get('/datastores/%s' % base.getid(datastore), 'datastore')
    def get(self, component):
        """Get a specific component.

        :param component: The ID (Name of the component) of the :class:
        `Component` to get.
        :rtype: :class:`Component`
        """
        return self._get("/components/%s" % base.getid(component), "component")
Exemple #25
0
    def get(self, device):
        """Get a specific device from pool.

        :param device: The ID of the :class: `Device` to get.
        :rtype: :class:`Device`
        """

        return self._get('/pool/devices/%s' % base.getid(device), 'device')
    def space(self, datastore):
        """Get a specific datastore and its space

        :param datastore: The ID of the :class: `Datastore` to get.
        :rtype: :class:`Datastore`
        """
        return self._get('/datastores/%s/space' % base.getid(datastore),
                         'datastore')
    def get(self, architecture):
        """Get a specific architecture.

        :param architecture: The ID of the :class: `Architecture` to get.
        :rtype: :class:`Architecture`
        """
        return self._get("/archs/%s" % base.getid(architecture),
                         "architecture")
    def list(self, zone):
        """Get a list of nodes by a specific zone.

        :param zone: The ID of the :class: `Zone` to get its nodes.
        :rtype: :class:`Zone`
        """
        return self._list("/zones/%s/nodes" % base.getid(zone),
                          "nodes")
    def cancel(self, zone, node, task):
        """Cancel a task by zone and node.

        :param zone: The ID of the :class: `Zone` to get.
        :rtype: :class:`Zone`

        :param role: The ID of the :class: `Node` to get.
        :rtype: :class:`Node`

        :param role: The ID of the :class: `Task` to get.
        :rtype: :class:`Task`
        """

        return self.api.client.post("/zones/%s/nodes/%s/tasks/%s/cancel"
                                    % (base.getid(zone),
                                       base.getid(node),
                                       task.uuid))
    def get_zone_role(self, zone, role, component_id):
        """Get a component by zone and role.

        :param zone: The ID of the :class: `Zone` to get.
        :rtype: :class:`Zone`

        :param role: The ID of the :class: `Role` to get.
        :rtype: :class:`Zone`

         :param component: The ID (Name of the component) of the :class:
        `Component` to get.
        :rtype: :class:`Component`
        """

        return self._get(
            "/zones/%s/roles/%s/components/%s" %
            (base.getid(zone), base.getid(role), component_id), "component")
    def get(self, component):
        """Get a specific component.

        :param component: The ID (Name of the component) of the :class:
        `Component` to get.
        :rtype: :class:`Component`
        """
        return self._get("/components/%s" % base.getid(component), "component")
Exemple #32
0
    def get(self, architecture):
        """Get a specific architecture.

        :param architecture: The ID of the :class: `Architecture` to get.
        :rtype: :class:`Architecture`
        """
        return self._get("/archs/%s" % base.getid(architecture),
                         "architecture")
    def get(self, datastore):
        """Get a specific datastore from pool.

        :param datastore: The ID of the :class: `Datastore` to get.
        :rtype: :class:`Datastore`
        """

        return self._get('/datastores/%s' % base.getid(datastore), 'datastore')
    def space(self, datastore):
        """Get a specific datastore and its space

        :param datastore: The ID of the :class: `Datastore` to get.
        :rtype: :class:`Datastore`
        """
        return self._get('/datastores/%s/space' % base.getid(datastore),
                         'datastore')
    def delete(self, zone, task, node):
        """
        Delete a specific task.

        :param zone: The  ID of the :class: `Zone` to get.
        :rtype: :class:`Zone`

        :param task: The UUID of the :class: `Task` to delete.
        :rtype: :class:`Task`

        :param node: The ID of the :class: `Node` to get
        :rtype: :class:`Node`
        """

        self._delete("/zones/%s/nodes/%s/tasks/%s" % (base.getid(zone),
                                                      base.getid(node),
                                                      task.uuid))
Exemple #36
0
    def template(self, architecture):
        """Get a specific template (Profile) by architecture.

        :param architecture: The ID of the :class: `Architecture` to get its
        template.
        :rtype: :class:`Architecture`
        """
        return self._get("/archs/%s/get_template" % base.getid(architecture),
                         "profile")
    def content(self, datastore):
        """Get a specific datastore and its content

        :param datastore: The ID of the :class: `Datastore` to get.
        :rtype: :class:`Datastore`
        """

        return self._get('/datastores/%s/content' % base.getid(datastore),
                         'datastore')
    def update(self, datastore, **kwargs):
        """
        Update the parameters of the datastore
        """

        if not kwargs:
            return

        return self._update("/datastores/%s" % base.getid(datastore), kwargs)
    def content(self, datastore):
        """Get a specific datastore and its content

        :param datastore: The ID of the :class: `Datastore` to get.
        :rtype: :class:`Datastore`
        """

        return self._get('/datastores/%s/content' % base.getid(datastore),
                         'datastore')
    def detach(self, datastore, **kwargs):
        """
        Attach a datastore.

        :param datastore: The ID of the :class: `Datastore` to detach.
        :rtype: :class:`Datastore`
        """
        return self._update("/datastores/%s/detach" % base.getid(datastore),
                            kwargs)
Exemple #41
0
    def update(self, architecture, profile, profile_file):
        """
        Update the name, components

        :param architecture: The ID of the :class: `Architecture` to get.
        :rtype: :class:`Architecture`

        :param profile: The ID of the :class: `Profile` to update.
        :rtype: :class:`Profile`

        :param profile: Profile JSON format define with updates
        """
        if not profile_file:
            return

        return self._update(
            "/archs/%s/profiles/%s" %
            (base.getid(architecture), base.getid(profile)), profile_file)
Exemple #42
0
    def list_zone_role_component(self, zone, role, component):
        """Get all services by zone, role and component.

        :param zone: The ID of the :class: `Zone` to get.
        :rtype: :class:`Zone`

        :param role: The ID of the :class: `Role` to get.
        :rtype: :class:`Zone`

        :param component: The ID (Name of the component) of the :class:
        `Component` to get.
        :rtype: :class:`Component`
        """
        return self._list("/zones/%s/roles/%s/components/%s/services"
                          % (base.getid(zone),
                             base.getid(role),
                             component.name),
                          "services")
    def detach(self, datastore, **kwargs):
        """
        Attach a datastore.

        :param datastore: The ID of the :class: `Datastore` to detach.
        :rtype: :class:`Datastore`
        """
        return self._update("/datastores/%s/detach" % base.getid(datastore),
                            kwargs)
    def delete(self, zone):
        """
        Delete a zone.

        :param profile: The ID of the :class: `Zone` to delete.
        :rtype: :class:`Zone`
        """

        self._delete("/zones/%s" % base.getid(zone))
    def update(self, datastore, **kwargs):
        """
        Update the parameters of the datastore
        """

        if not kwargs:
            return

        return self._update("/datastores/%s" % base.getid(datastore), kwargs)
    def template(self, architecture):
        """Get a specific template (Profile) by architecture.

        :param architecture: The ID of the :class: `Architecture` to get its
        template.
        :rtype: :class:`Architecture`
        """
        return self._get("/archs/%s/get_template" % base.getid(architecture),
                         "profile")
    def delete(self, zone):
        """
        Delete a zone.

        :param profile: The ID of the :class: `Zone` to delete.
        :rtype: :class:`Zone`
        """

        self._delete("/zones/%s" % base.getid(zone))
    def update(self, architecture, profile, profile_file):
        """
        Update the name, components

        :param architecture: The ID of the :class: `Architecture` to get.
        :rtype: :class:`Architecture`

        :param profile: The ID of the :class: `Profile` to update.
        :rtype: :class:`Profile`

        :param profile: Profile JSON format define with updates
        """
        if not profile_file:
            return

        return self._update("/archs/%s/profiles/%s"
                            % (base.getid(architecture),
                               base.getid(profile)),
                            profile_file)
Exemple #49
0
    def property_delete(self, architecture, profile, property_key):

        profile_dict = profile._info
        props_dict = profile_dict['properties']

        if property_key in props_dict:
            del props_dict[property_key]
        else:
            msg = "No profile property with a key: '%s' exists." % \
                  (property_key)
            raise exceptions.CommandError(msg)

        profile_dict['properties'] = props_dict
        del profile_dict['_links']
        profile_body = {"profile": profile_dict}

        return self._update(
            "/archs/%s/profiles/%s" %
            (base.getid(architecture), base.getid(profile)), profile_body)
    def get_zone_role(self, zone, role, component_id):
        """Get a component by zone and role.

        :param zone: The ID of the :class: `Zone` to get.
        :rtype: :class:`Zone`

        :param role: The ID of the :class: `Role` to get.
        :rtype: :class:`Zone`

         :param component: The ID (Name of the component) of the :class:
        `Component` to get.
        :rtype: :class:`Component`
        """

        return self._get("/zones/%s/roles/%s/components/%s"
                         % (base.getid(zone),
                            base.getid(role),
                            component_id),
                         "component")
    def property_delete(self, architecture, profile, property_key):

        profile_dict = profile._info
        props_dict = profile_dict['properties']

        if property_key in props_dict:
            del props_dict[property_key]
        else:
            msg = "No profile property with a key: '%s' exists." % \
                  (property_key)
            raise exceptions.CommandError(msg)

        profile_dict['properties'] = props_dict
        del profile_dict['_links']
        profile_body = {"profile": profile_dict}

        return self._update("/archs/%s/profiles/%s" %
                           (base.getid(architecture),
                            base.getid(profile)), profile_body)
    def get(self, zone, node):
        """Get a specific node by zone.

        :param zone: The ID of the :class: `Zone` to get.
        :rtype: :class:`Zone`

        :param profile: The ID of the :class: `Node` to get.
        :rtype: :class:`Node`
        """
        return self._get("/zones/%s/nodes/%s" % (base.getid(zone), node),
                         'node')
    def get(self, zone, node):
        """Get a specific node by zone.

        :param zone: The ID of the :class: `Zone` to get.
        :rtype: :class:`Zone`

        :param profile: The ID of the :class: `Node` to get.
        :rtype: :class:`Node`
        """
        return self._get("/zones/%s/nodes/%s" % (base.getid(zone), node),
                         'node')
Exemple #54
0
    def get(self, zone, task):
        """Get a specific task by zone.

        :param zone: The ID of the :class: `Zone` to get.
        :rtype: :class:`Zone`

        :param task: The ID of the :class: `Task` to get.
        :rtype: :class:`Task`
        """
        return self._get("/zones/%s/tasks/%s" % (base.getid(zone), task),
                         "task")
    def get(self, zone, role):
        """Get a specific role by zone.

        :param zone: The ID of the :class: `Zone` to get.
        :rtype: :class:`Zone`

        :param role: The ID of the :class: `Role` to get.
        :rtype: :class:`Role`
        """
        return self._get("/zones/%s/roles/%s" % (base.getid(zone), role),
                         "role")
    def get(self, zone, role):
        """Get a specific role by zone.

        :param zone: The ID of the :class: `Zone` to get.
        :rtype: :class:`Zone`

        :param role: The ID of the :class: `Role` to get.
        :rtype: :class:`Role`
        """
        return self._get("/zones/%s/roles/%s" % (base.getid(zone), role),
                         "role")
    def get(self, architecture, profile):
        """Get a specific profile by architecture.

        :param architecture: The ID of the :class: `Architecture` to get.
        :rtype: :class:`Architecture`

        :param profile: The ID of the :class: `Profile` to get.
        :rtype: :class:`Profile`
        """
        return self._get("/archs/%s/profiles/%s" % (base.getid(architecture),
                                                    profile),
                         "profile")
    def get(self, zone, task):
        """Get a specific task by zone.

        :param zone: The ID of the :class: `Zone` to get.
        :rtype: :class:`Zone`

        :param task: The ID of the :class: `Task` to get.
        :rtype: :class:`Task`
        """
        return self._get("/zones/%s/tasks/%s" % (base.getid(zone),
                                                 task),
                         "task")
    def update_zone_role(self, zone, role, component_id, component_file):
        """Update a component by zone and role.

        :param zone: The ID of the :class: `Zone` to get.
        :rtype: :class:`Zone`

        :param role: The ID of the :class: `Role` to get.
        :rtype: :class:`Zone`

         :param component: The ID (Name of the component) of the :class:
        `Component` to get.
        :rtype: :class:`Component`
        """

        if not component_file:
            return

        return self._update("/zones/%s/roles/%s/components/%s"
                            % (base.getid(zone),
                               base.getid(role),
                               component_id),
                            component_file)