Esempio n. 1
0
    def get(self, identifier="", parameters={}):
        """
        Retrieves a particular entity of this collection.

        @param identifier: The identifier of the entity to retrieve.
        @type identifier: string
        @param parameters: Query parameters to send to ComodIT server.
        @type parameters: dict of strings

        @return: An entity representation.
        @rtype: L{Entity}

        @raise EntityNotFoundException: If the entity was not found on the
        server.
        """

        if not identifier and not self.accept_empty_id:
            raise PythonApiException("Cannot get entity: identifier is empty")

        try:
            result = self.client._http_client.read(self.url + identifier,
                                                   parameters=parameters)
            return self._new(result)
        except ApiException as e:
            self._handle_error(e, identifier)
Esempio n. 2
0
    def _unpublish(self, argv):
        app = self._ctrl._get_entity(argv)

        if app.published_as is None:
            raise PythonApiException(self._type_name + " is not published")

        self.store().get(app.published_as, {"org_name" : argv[0]}).delete()
Esempio n. 3
0
    def _update(self, entity, parameters={}):
        """
        Updates a remote entity with a local representation and updates the
        local representation of remote entity.

        @param entity: Entity's local representation.
        @type entity: L{Entity}
        @param parameters: Query parameters to send to ComodIT server.
        @type parameters: dict of strings

        @raise EntityNotFoundException: If the entity was not found on the
        server.
        """

        entity_id = entity.identifier
        if not entity_id and not self.accept_empty_id:
            raise PythonApiException(
                "Cannot update entity: identifier is empty")

        try:
            result = self.client._http_client.update(self.url + entity_id,
                                                     entity.get_json(),
                                                     parameters=parameters)
        except ApiException as e:
            self._handle_error(e, entity.identifier)
        entity.set_json(result)
Esempio n. 4
0
    def _push(self, argv):
        app = self._ctrl._get_entity(argv)

        if app.published_as is None:
            raise PythonApiException(self._type_name + " is not published")

        pub_app = self.store()._new({"uuid" : app.published_as})
        pub_app.update()
Esempio n. 5
0
    def _pull(self, argv):
        app = self._ctrl._get_entity(argv)

        if app.purchased_as is None:
            raise PythonApiException(self._type_name + " is not purchased")

        org = self._ctrl._client.organizations().get(app.organization)

        pur = self.get_purchased(org)._new({"uuid" : app.purchased_as})
        pur.update()
Esempio n. 6
0
    def reset_secret(self):
        """
        Resets the secret key of this organization.
        """

        try:
            self._http_client.create(self.url + "access")
        except ApiException, e:
            raise PythonApiException("Could not reset secret key: " +
                                     e.message)
Esempio n. 7
0
    def _publish(self, argv):
        app = self._ctrl._get_entity(argv)

        if not app.published_as is None:
            raise PythonApiException(self._type_name + " has already been published")

        template_json = json.load(open(os.path.join(Config()._get_templates_path(), self._template)))
        template_json[self._label] = app.uuid

        pub_app = self.store()._new(template_json)
        self.store()._create(pub_app)
Esempio n. 8
0
    def set_content(self, path):
        """
        Uploads the content of given local file.

        @param path: Path to local file.
        @type path: string
        """

        try:
            self._http_client.upload_to_exising_file_with_path(
                path, self.content_url)
        except Exception as e:
            raise PythonApiException("Could not set file content: " + str(e))
Esempio n. 9
0
 def __init__(self, ctrl, content_type):
     self._ctrl = ctrl
     self._content_type = content_type
     if content_type == "app":
         self._params = "<org_name> <app_name>"
         self._template = "published_application.json"
         self._type_name = "Application"
         self._label = "application"
     elif content_type == "dist":
         self._params = "<org_name> <dist_name>"
         self._template = "published_distribution.json"
         self._type_name = "Distribution"
         self._label = "distribution"
     else:
         raise PythonApiException("Unhandled type: " + str(content_type))
Esempio n. 10
0
    def _update_authorized(self, argv):
        app = self._ctrl._get_entity(argv)

        if app.published_as is None:
            raise PythonApiException(self._type_name + " is not published")

        try:
            pub = self.store().get(app.published_as, {"org_name": argv[0]})
        except PythonApiException:
            raise ControllerException(
                "Unable to retrieve entity from store, maybe you forgot to use --org option?"
            )
        updated = edit_text(json.dumps(pub.authorized, indent=4))
        pub.update_authorized(
            json.loads(updated, object_pairs_hook=OrderedDict))
Esempio n. 11
0
    def clone(self, clone_name):
        """
        Requests the cloning of remote entity. Clone will have given name.
        This name should not already be in use.

        @param clone_name: The name of the clone.
        @type clone_name: string
        @return: The representation of platform's clone.
        @rtype: L{Platform}
        """

        try:
            result = self._http_client.update(self.url + "_clone", parameters = {"name": clone_name})
            return Platform(self.collection, result)
        except ApiException as e:
            raise PythonApiException("Unable to clone platform: " + e.message)
Esempio n. 12
0
    def _create(self, entity, parameters={}):
        """
        Creates a remote entity given a local representation and updates the
        local representation with newly created remote entity.

        @param entity: Entity's local representation.
        @type entity: L{Entity}
        @param parameters: Query parameters to send to ComodIT server.
        @type parameters: dict of strings
        """

        try:
            result = self.client._http_client.create(self.url,
                                                     entity.get_json(),
                                                     parameters=parameters)
        except ApiException as e:
            raise PythonApiException("Could not create entity: " + e.message)
        entity.set_json(result)
Esempio n. 13
0
    def clone(self, clone_name):
        """
        Requests the cloning of remote entity. Clone will have given name.
        This name should not already be in use. Note that the hosts in cloned
        orchestration will have a clone with same name in cloned orchestration.
        
        @param clone_name: The name of the clone.
        @type clone_name: string
        @return: The representation of orchestration's clone.
        @rtype: L{Orchestration}
        """

        try:
            result = self._http_client.update(self.url + "_clone",
                                              parameters={"name": clone_name})
            return Orchestration(self.collection, result)
        except ApiException as e:
            raise PythonApiException("Unable to clone orchestration: " +
                                     e.message)
Esempio n. 14
0
    def refresh(self, entity, parameters = {}):
        """
        Updates the local representation of a remote entity.

        @param entity: Entity's local representation.
        @type entity: L{Entity}
        @param parameters: Query parameters to send to ComodIT server.
        @type parameters: dict of strings

        @raise EntityNotFoundException: If the entity was not found on the
        server.
        """

        try:
            result = self.client._http_client.read(self.url + entity.identifier,
                                                   parameters = parameters)
        except ApiException as e:
            raise PythonApiException("Could not refresh entity: " + e.message)
        entity.set_json(result)
Esempio n. 15
0
    def clone(self, clone_name):
        """
        Requests the cloning of remote entity. Clone will have given name.
        This name should not already be in use. Note that the hosts in cloned
        environment will have a clone with same name in cloned environment.
        Cloned hosts will all be in DEFINED state (see L{Host}).

        @param clone_name: The name of the clone.
        @type clone_name: string
        @return: The representation of environment's clone.
        @rtype: L{Environment}
        """

        try:
            result = self._http_client.update(self.url + "_clone",
                                              parameters={"name": clone_name})
            return Environment(self.collection, result)
        except ApiException, e:
            raise PythonApiException("Unable to clone environment: " +
                                     e.message)
Esempio n. 16
0
    def delete(self, identifier, parameters={}):
        """
        Deletes a particular entity in this collection.

        @param identifier: The identifier of the entity to delete.
        @type identifier: string
        @param parameters: Query parameters to send to ComodIT server.
        @type parameters: dict of strings
        """

        if not identifier and not self.accept_empty_id:
            raise PythonApiException(
                "Cannot delete entity: identifier is empty")

        try:
            self.client._http_client.delete(self.url + identifier,
                                            parameters=parameters)
        except ApiException as e:
            if e.code != 404:
                self._handle_error(e, identifier)
Esempio n. 17
0
    def list(self, parameters={}):
        """
        Fetches the entities in this collection.

        @param parameters: Query parameters to send to ComodIT server.
        @type parameters: dict of strings

        @rtype: list of L{Entity}
        """
        _http_client = self.client._http_client
        try:
            result = _http_client.read(self.url, parameters=parameters)

            entities_list = []
            count = int(result["count"])
            if (count > 0):
                json_list = result["items"]
                for json_res in json_list:
                    entities_list.append(self._new(json_res))

            return entities_list
        except ApiException as e:
            raise PythonApiException("Could not get elements: " + e.message)
Esempio n. 18
0
 def image_parameters(self):
     try:
         result = self._http_client.read(self.url + "driver/image_parameters")
         return [ Parameter(None, item) for item in result['items']]
     except ApiException as e:
         raise PythonApiException("Unable to retrieve image parameters: " + e.message)
Esempio n. 19
0
 def list_images(self):
     try:
         result = self._http_client.read(self.url + "images")
         return [ Image(item) for item in result['items']]
     except ApiException as e:
         raise PythonApiException("Unable to retrieve platform images: " + e.message)
Esempio n. 20
0
 def _handle_error(self, e, identifier):
     if e.code == 404:
         raise EntityNotFoundException(identifier)
     else:
         raise PythonApiException("error " + str(e.code) + ": " + e.message)