Example #1
0
    def new(self, uri, new_data_hash):
        """
        Used to create new live activity through API and set the "uri" so that we
        can operate on this instance of LiveActivity right away after .new() returns True

        :param new_data_hash: dictionary of a following structure::

            {"live_activity_name" : "",\
            "live_activity_description" : "",\
            "activity_id" : "",\
            "controller_id" : ""}

        :param uri: "http://some_server/prefix" (passed by master)

        :rtype: new LiveActivity object or False
        """
        self.log.info("Creating new Live Activity with arguments: %s" %
                      new_data_hash)
        route = Path().get_route_for('LiveActivity', 'new')
        url = "%s%s" % (uri, route)
        request_response = self._api_post_json(url, new_data_hash)
        if request_response.url:
            self.absolute_url = request_response.url.replace(
                "view.html", "view.json")
            self.fetch()
            self.log.info(
                "Created new LiveActivity with url=%s, data_hash is now %s" %
                (self.absolute_url, self.data_hash))
            return self
        else:
            self.log.info("Created new LiveActivity %s but returned False" %
                          self)
            return False
Example #2
0
    def set_live_activity_groups(self, live_activity_groups_list):
        """
        Used to set new live acitivity groups list for space

        :param: dictionary with following structure::

            {\
            'space.name' : 'name of the space',\
            'liveActivityGroupsIds' : [1,2,666]\
            }

        :rtype: new Space object
        """
        params = { 'space.name' : self.name(),
                   'liveActivityGroupIds' : live_activity_groups_list,
                   'space.description' : self.description()
                 }

        self.log.info("Updating Space with arguments: %s" % params)
        route = Path().get_route_for('Space', 'edit') % self.id()
        url = "%s%s" % (self.uri, route)
        request_response = self._api_post_json_no_cookies(url, params)
        if request_response.url:
            self.absolute_url = request_response.url.replace("view.html", "view.json")
            self.fetch()
            self.log.info("Updated Space with url=%s, data_hash is now %s" % (self.absolute_url, self.data_hash))
            return self
        else:
            self.log.info("Updated Space %s but returned False" % self)
            return False
    def _compose_url(self,
                     uri,
                     class_name=None,
                     method_name=None,
                     context=None,
                     action=None):
        """
        Should compose URL trying to do that in two steps:
            1. return if object that tries to retrieve the url
            has route that is already staticaly defined
            2. try to compose the custom route on the basis of URL data

        :rtype: string
        """
        if class_name and method_name:
            self.log.info(
                "Composing url for class_name '%s' and method name '%s'" %
                (class_name, method_name))
            static_route = Path().get_route_for(class_name, method_name)
            if static_route:
                self.log.info("Returned auto url %s" % (static_route))
                url = "%s%s" % (uri, static_route)
                return url

        elif context and action:
            url = "%s%s%s" % (uri, context, action)
            self.log.info("Composed url %s" % (url))
            return url
        else:
            self.log.info("Could not compose an url.")
            raise CommunicableException
Example #4
0
    def new(self, uri, constructor_args):
        """
        Used to create new space through API and set the "uri" so that we
        can operate on this instance of Space right away after .new() returns True

        :param constructor_args: dictionary with following structure::

            {\
            'space.name' : 'space_name',\
            'space.description' : 'space_description',\
            '_eventId_save' : 'Save',\
            'liveActivityGroupIds' : [1,2,666]\
            }

        :param uri: "http://some_server/prefix" (passed by master)

        :rtype: new LiveActivityGroup object or False
        """

        self.log.info("Creating new Space with arguments: %s" % constructor_args)
        route = Path().get_route_for('Space', 'new')
        url = "%s%s" % (uri, route)
        request_response = self._api_post_json(url, constructor_args)
        if request_response.url:
            self.absolute_url = request_response.url.replace("view.html", "view.json")
            self.fetch()
            self.log.info("Created new Space with url=%s, data_hash is now %s" % (self.absolute_url, self.data_hash))
            return self
        else:
            self.log.info("Created new Space %s but returned False" % self)
            return False
Example #5
0
 def _get_absolute_url(self):
     """
     :rtype: string
     """
     route = Path().get_route_for(self.class_name,
                                  'view') % self.data_hash['id']
     url = "%s%s" % (self.uri, route)
     return url
 def send_shutdown(self):
     shutdown_route = Path().get_route_for(
         self.class_name, 'shutdown') % self.data_hash['id']
     if self._send_shutdown_request(shutdown_route):
         self.log.info("Successfully sent shutdown for url=%s" %
                       self.absolute_url)
         return True
     else:
         return False
 def send_startup(self):
     startup_route = Path().get_route_for(self.class_name,
                                          'startup') % self.data_hash['id']
     if self._send_startup_request(startup_route):
         self.log.info("Successfully sent 'startup' for url=%s" %
                       self.absolute_url)
         return True
     else:
         return False
 def send_activate(self):
     activate_route = Path().get_route_for(
         self.class_name, 'activate') % self.data_hash['id']
     if self._send_activatable_request(activate_route):
         self.log.info("Successfully sent 'activate' for url=%s" %
                       self.absolute_url)
         return True
     else:
         return False
 def send_disconnect(self):
     disconnect_route = Path().get_route_for(
         self.class_name, 'disconnect') % self.data_hash['id']
     if self._send_connectable_request(disconnect_route):
         self.log.info("Successfully sent 'disconnect' for url=%s" %
                       self.absolute_url)
         return True
     else:
         return False
 def send_deploy(self):
     deploy_route = Path().get_route_for(self.class_name,
                                         'deploy') % self.data_hash['id']
     if self._send_deploy_request(deploy_route):
         self.log.info("Successfully sent 'deploy' for url=%s" %
                       self.absolute_url)
         return True
     else:
         return False
 def send_clean_tmp(self):
     configure_route = Path().get_route_for(
         self.class_name, 'clean_tmp') % self.data_hash['id']
     if self._send_cleanable_request(configure_route):
         self.log.info("Successfully sent 'clean_tmp' for url=%s" %
                       self.absolute_url)
         return True
     else:
         return False
 def get_config(self):
     config_route = Path().get_route_for(self.class_name,
                                         'config') % self.data_hash['id']
     self.log.info("Getting config of %s" % (self.class_name))
     response = self._send_configable_get_request(config_route)
     if response:
         self.log.info("Successfully got config from url=%s" %
                       self.absolute_url)
         return self._scrap_config(response)
     else:
         return False
 def send_delete(self):
     """
     Sends the "delete" GET request to a route
     """
     delete_route = Path().get_route_for(self.class_name,
                                         'delete') % self.data_hash['id']
     if self._send_delete_request(delete_route):
         self.log.info("Successfully sent 'delete' to url=%s" %
                       self.absolute_url)
         return True
     else:
         return False
 def send_status_refresh(self):
     """
     Extracts self.data_hash and self.class_name from children class
     and finds out to which route send GET request to ands sends it
     """
     refresh_route = Path().get_route_for(self.class_name,
                                          'status') % self.data_hash['id']
     if self._send_status_refresh(refresh_route):
         self.log.info("Successfully refreshed status for url=%s" %
                       self.absolute_url)
         return True
     else:
         return False
 def set_metadata(self, metadata_dictionary):
     """
     Accepts dictionary of keys that will be unpacked to "key=value" strings and
     makes a request overwriting any previous metadata
     :rtype: bool
     :param metadata_args: Dictionary with keys and values
     """
     metadata = {"values": self._unpack_metadata(metadata_dictionary)}
     self.log.info("Updating metadata of %s with %s" %
                   (self.class_name, metadata))
     metadata_route = Path().get_route_for(
         self.class_name, 'metadata') % self.data_hash['id']
     if self._send_metadatable_request(metadata_route, metadata):
         self.log.info("Successfully sent metadata for url=%s" %
                       self.absolute_url)
         return True
     else:
         return False
 def set_config(self, config_dictionary):
     """
     Accepts dictionary of keys that will be unpacked to "key=value" strings and
     makes a request overwriting any previous config
     :rtype: bool
     :param config_dictionary: Dictionary with keys and values
     """
     config = {"values": self._unpack_config(config_dictionary)}
     self.log.info("Updating config of %s with %s" %
                   (self.class_name, config))
     config_route = Path().get_route_for(self.class_name,
                                         'config') % self.data_hash['id']
     if self._send_configable_set_request(config_route, config):
         self.log.info("Successfully sent config for url=%s" %
                       self.absolute_url)
         return True
     else:
         return False
    def upload(self, uri, zip_file_handler):
        """
        Should make a deployment of the activity with following steps:
            - receive handler to a local zipfile
            - upload it to the API
            - save
            - set instance variables for the object

        :return: False or URL to a new Activity
        :param uri: stirng
        :param zip_file_handler: 'file' class instance
        :rtype: new Activity object or False
        """
        self.log.info("Uploading new Activity from file %s" % zip_file_handler)
        route = Path().get_route_for('Activity', 'upload')
        url = "%s%s" % (uri, route)
        payload = {"_eventId_save" : "Save"}
        request_response = self._api_post_json(url, payload, zip_file_handler)
        return self.check_upload_response(request_response)
Example #18
0
    def new(self, uri, constructor_args):
        """
        Used to create new space controller through API and set the "uri" so that we
        can operate on this instance of SpaceController right away after .new() returns True

        :param constructor_args: dictionary with following structure::

            {"space_controller_name" : "mandatory string",\
            "space_controller_description" : "non mandatory string",\
            "space_controller_host_id" : "mandatory string"}

        :param uri: "http://some_server/prefix" (passed by master)

        :rtype: new SpaceController object or False

        """

        unpacked_arguments = {}
        unpacked_arguments['name'] = constructor_args['space_controller_name']
        unpacked_arguments['description'] = constructor_args[
            'space_controller_description']
        unpacked_arguments['hostId'] = constructor_args[
            'space_controller_host_id']
        unpacked_arguments['_eventId_save'] = 'Save'

        self.log.info("Creating new SpaceController with arguments: %s" %
                      unpacked_arguments)
        route = Path().get_route_for('SpaceController', 'new')
        url = "%s%s" % (uri, route)
        request_response = self._api_post_json(url, unpacked_arguments)

        if request_response.url:
            self.absolute_url = request_response.url.replace(
                "view.html", "view.json")
            self.fetch()
            self.log.info(
                "Created new SpaceController with url=%s, data_hash is now %s"
                % (self.absolute_url, self.data_hash))
            return self
        else:
            self.log.info("Created new SpaceController %s but returned False" %
                          self)
            return False
Example #19
0
    def set_live_activities(self, live_activities_list):
        """
        Used to set new live activities list

        :param: dictionary with following structure::

            {\
            'liveActivityGroup.name' : 'live_activity_group_name',\
            'liveActivityIds' : [1,2,666]\
            }

        :param uri: "http://some_server/prefix" (passed by master)

        :rtype: new LiveActivityGroup object or False
        """
        params = {
            'liveActivityGroup.name': self.name(),
            'liveActivityIds': live_activities_list,
            'liveActivityGroup.description': self.description()
        }
        self.log.info("Updating LiveActivityGroup with arguments: %s" % params)
        route = Path().get_route_for('LiveActivityGroup', 'edit') % self.id()
        url = "%s%s" % (self.uri, route)
        request_response = self._api_post_json_no_cookies(url, params)
        if request_response.url:
            self.absolute_url = request_response.url.replace(
                "view.html", "view.json")
            self.fetch()
            self.log.info(
                "Updated LiveActivityGroup with url=%s, data_hash is now %s" %
                (self.absolute_url, self.data_hash))
            return self
        else:
            self.log.info("Updated LiveActivityGroup %s but returned False" %
                          self)
            return False