Example #1
0
    def _upload(self,
                archive_location,
                blueprint_id,
                application_file_name=None,
                visibility=VisibilityState.TENANT,
                progress_callback=None):
        query_params = {'visibility': visibility}
        if application_file_name is not None:
            query_params['application_file_name'] = \
                urllib.quote(application_file_name)

        uri = '/{self._uri_prefix}/{id}'.format(self=self, id=blueprint_id)

        # For a Windows path (e.g. "C:\aaa\bbb.zip") scheme is the
        # drive letter and therefore the 2nd condition is present
        if urlparse.urlparse(archive_location).scheme and \
                not os.path.exists(archive_location):
            # archive location is URL
            query_params['blueprint_archive_url'] = archive_location
            data = None
        else:
            # archive location is a system path
            data = bytes_stream_utils.request_data_file_stream(
                archive_location,
                progress_callback=progress_callback,
                client=self.api)

        return self.api.put(uri,
                            params=query_params,
                            data=data,
                            expected_status_code=201)
Example #2
0
    def _prepare_put_request(self,
                             archive_location,
                             application_file_name,
                             visibility,
                             progress_callback):
        query_params = {'visibility': visibility}
        if application_file_name is not None:
            query_params['application_file_name'] = \
                urlquote(application_file_name)

        # For a Windows path (e.g. "C:\aaa\bbb.zip") scheme is the
        # drive letter and therefore the 2nd condition is present
        if urlparse(archive_location).scheme and \
                not os.path.exists(archive_location):
            # archive location is URL
            query_params['blueprint_archive_url'] = archive_location
            data = None
        else:
            # archive location is a system path
            data = bytes_stream_utils.request_data_file_stream(
                archive_location,
                progress_callback=progress_callback,
                client=self.api)

        return query_params, data
    def upload(self,
               snapshot_path,
               snapshot_id,
               progress_callback=None):
        """
        Uploads snapshot archive to Cloudify's manager.

        :param snapshot_path: Path to snapshot archive.
        :param snapshot_id: Id of the uploaded snapshot.
        :param progress_callback: Progress bar callback method
        :return: Uploaded snapshot.

        Snapshot archive should be the same file that had been created
        and downloaded from Cloudify's manager as a result of create
        snapshot / download snapshot commands.
        """
        assert snapshot_path
        assert snapshot_id

        uri = '/snapshots/{0}/archive'.format(snapshot_id)
        query_params = {}

        if urlparse(snapshot_path).scheme and \
                not os.path.exists(snapshot_path):
            query_params['snapshot_archive_url'] = snapshot_path
            data = None
        else:
            data = bytes_stream_utils.request_data_file_stream(
                snapshot_path,
                progress_callback=progress_callback,
                client=self.api)

        response = self.api.put(uri, params=query_params, data=data,
                                expected_status_code=201)
        return Snapshot(response)
Example #4
0
    def upload(self,
               plugin_path,
               plugin_title=None,
               visibility=VisibilityState.TENANT,
               progress_callback=None,
               _plugin_id=None,
               _uploaded_at=None,
               _created_by=None):
        """Uploads a plugin archive to the manager

        :param plugin_path: Path to plugin archive.
        :param plugin_title: Plugin title to be used e.g. in UI for
                             presentation purposes in Topology widget.
        :param visibility: The visibility of the plugin, can be 'private',
                           'tenant' or 'global'
        :param progress_callback: Progress bar callback method
        :param _plugin_id: Internal use only
        :param _uploaded_at: Internal use only
        :param _created_by: Internal use only
        :return: Plugin object
        """
        query_params = {'visibility': visibility}
        if _plugin_id:
            query_params['id'] = _plugin_id
        if _uploaded_at:
            query_params['uploaded_at'] = _uploaded_at
        if _created_by:
            query_params['created_by'] = _created_by
        if plugin_title:
            query_params['title'] = plugin_title
        timeout = self.api.default_timeout_sec
        if urlparse(plugin_path).scheme and not os.path.exists(plugin_path):
            query_params['plugin_archive_url'] = plugin_path
            data = None
            # if we have a timeout set, let's only use a connect timeout,
            # and skip the read timeout - this request can take a long
            # time before the server actually returns a response
            if timeout is not None and isinstance(timeout, (int, float)):
                timeout = (timeout, None)
        else:
            data = bytes_stream_utils.request_data_file_stream(
                plugin_path,
                progress_callback=progress_callback,
                client=self.api)

        response = self.api.post('/{self._uri_prefix}'.format(self=self),
                                 params=query_params,
                                 data=data,
                                 timeout=timeout,
                                 expected_status_code=201)
        if 'metadata' in response and 'items' in response:
            # This is a list of plugins - for caravan
            return self._wrap_list(response)
        else:
            return self._wrapper_cls(response)
Example #5
0
    def _prepare_put_request(self,
                             archive_location,
                             application_file_name,
                             visibility,
                             progress_callback,
                             async_upload,
                             labels=None,
                             created_at=None,
                             owner=None,
                             state=None,
                             skip_execution=False):
        query_params = {
            'visibility': visibility,
            'async_upload': async_upload,
            'skip_execution': skip_execution
        }
        if application_file_name is not None:
            query_params['application_file_name'] = \
                urlquote(application_file_name)
        if labels is not None:
            labels_params = []
            for label in labels:
                if (not isinstance(label, dict)) or len(label) != 1:
                    raise CloudifyClientError(
                        'Labels must be a list of 1-entry dictionaries: '
                        '[{<key1>: <value1>}, {<key2>: [<value2>, <value3>]}, '
                        '...]')

                [(key, value)] = label.items()
                value = value.replace('=', '\\=').replace(',', '\\,')
                labels_params.append('{0}={1}'.format(key, value))
            query_params['labels'] = ','.join(labels_params)
        if created_at:
            query_params['created_at'] = created_at
        if owner:
            query_params['owner'] = owner
        if state:
            query_params['state'] = state

        # For a Windows path (e.g. "C:\aaa\bbb.zip") scheme is the
        # drive letter and therefore the 2nd condition is present
        if urlparse(archive_location).scheme and \
                not os.path.exists(archive_location):
            # archive location is URL
            query_params['blueprint_archive_url'] = archive_location
            data = None
        else:
            # archive location is a system path
            data = bytes_stream_utils.request_data_file_stream(
                archive_location,
                progress_callback=progress_callback,
                client=self.api)

        return query_params, data
Example #6
0
    def upload_icon(self, blueprint_id, icon_path):
        """
        Upload an icon for an existing a blueprint.

        :param blueprint_id: Blueprint's id to update.
        :param icon_path: Path of a local file containing a icon for
            the blueprint.
        """
        icon_data = bytes_stream_utils.request_data_file_stream(
            icon_path, client=self.api)
        self.api.patch('/{self._uri_prefix}/{id}/icon'.format(self=self,
                                                              id=blueprint_id),
                       data=icon_data)
Example #7
0
    def upload(self, license_path):
        """Uploads a Cloudify license the Manager
        :param license_path: Path to the Cloudfiy license file.
        :return: License
        """
        assert license_path

        data = bytes_stream_utils.request_data_file_stream(license_path,
                                                           client=self.api)

        response = self.api.put('/license', data=data)

        return response
Example #8
0
    def upload_archive(self, blueprint_id, archive_path):
        """
        Upload an archive for an existing a blueprint.

        Used for uploading the blueprint's archive, downloaded from a URL using
        a system workflow, to the manager's file server
        This method is for internal use only.

        :param blueprint_id: Blueprint's id to update.
        :param archive_path: Path of a local blueprint archive data to upload
            to the manager's file server. Valid only when the blueprint's
            current upload state is `Uploading`, and is not being updated.
        """
        archive_data = bytes_stream_utils.request_data_file_stream(
            archive_path, client=self.api)
        self.api.put('/{self._uri_prefix}/{id}/archive'.format(
            self=self, id=blueprint_id),
                     data=archive_data)