コード例 #1
0
    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.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_gen(
                snapshot_path, progress_callback=progress_callback)

        response = self.api.put(uri,
                                params=query_params,
                                data=data,
                                expected_status_code=201)
        return Snapshot(response)
コード例 #2
0
    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.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_gen(
                snapshot_path, progress_callback=progress_callback)

        response = self.api.put(uri, params=query_params, data=data,
                                expected_status_code=201)
        return Snapshot(response)
コード例 #3
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.parse.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 urllib.parse.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 - upload it in chunks
            data = bytes_stream_utils.request_data_file_stream_gen(
                archive_location, progress_callback=progress_callback)

        return self.api.put(uri, params=query_params, data=data,
                            expected_status_code=201)
コード例 #4
0
    def upload(self,
               plugin_path,
               private_resource=False,
               progress_callback=None):
        """Uploads a plugin archive to the manager

        :param plugin_path: Path to plugin archive.
        :param private_resource: Whether the blueprint should be private
        :param progress_callback: Progress bar callback method
        :return: Plugin object
        """
        assert plugin_path

        uri = '/plugins'
        query_params = {'private_resource': private_resource}

        if urlparse.urlparse(plugin_path).scheme and \
                not os.path.exists(plugin_path):
            query_params['plugin_archive_url'] = plugin_path
            data = None
        else:
            data = bytes_stream_utils.request_data_file_stream_gen(
                plugin_path, progress_callback=progress_callback)

        response = self.api.post(uri,
                                 params=query_params,
                                 data=data,
                                 expected_status_code=201)
        return Plugin(response)
コード例 #5
0
    def upload(self,
               plugin_path,
               availability=AvailabilityState.TENANT,
               progress_callback=None):
        """Uploads a plugin archive to the manager

        :param plugin_path: Path to plugin archive.
        :param availability: The availability of the plugin,
                             can be 'private', 'tenant' or 'global'
        :param progress_callback: Progress bar callback method
        :return: Plugin object
        """
        assert plugin_path
        uri = '/plugins'
        query_params = {'availability': availability}
        timeout = self.api.default_timeout_sec
        if urlparse.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_gen(
                plugin_path, progress_callback=progress_callback)

        response = self.api.post(uri,
                                 params=query_params,
                                 data=data,
                                 expected_status_code=201,
                                 timeout=timeout)
        return Plugin(response)
コード例 #6
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 - upload it in chunks
            data = bytes_stream_utils.request_data_file_stream_gen(
                archive_location, progress_callback=progress_callback)

        return self.api.put(uri, params=query_params, data=data,
                            expected_status_code=201)
コード例 #7
0
    def _upload(self,
                archive_location,
                blueprint_id,
                application_file_name=None):
        query_params = {}
        if application_file_name is not None:
            query_params['application_file_name'] = \
                urllib.quote(application_file_name)

        uri = '/blueprints/{0}'.format(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 - upload it in chunks
            data = bytes_stream_utils.request_data_file_stream_gen(
                archive_location)

        return self.api.put(uri,
                            params=query_params,
                            data=data,
                            expected_status_code=201)
コード例 #8
0
    def upload(self,
               plugin_path,
               visibility=VisibilityState.TENANT,
               progress_callback=None):
        """Uploads a plugin archive to the manager

        :param plugin_path: Path to plugin archive.
        :param visibility: The visibility of the plugin, can be 'private',
                           'tenant' or 'global'
        :param progress_callback: Progress bar callback method
        :return: Plugin object
        """
        assert plugin_path
        query_params = {'visibility': visibility}
        timeout = self.api.default_timeout_sec
        if urlparse.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_gen(
                plugin_path, progress_callback=progress_callback)

        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)
コード例 #9
0
    def upload(self,
               plugin_path,
               visibility=VisibilityState.TENANT,
               progress_callback=None):
        """Uploads a plugin archive to the manager

        :param plugin_path: Path to plugin archive.
        :param visibility: The visibility of the plugin, can be 'private',
                           'tenant' or 'global'
        :param progress_callback: Progress bar callback method
        :return: Plugin object
        """
        assert plugin_path
        query_params = {'visibility': visibility}
        timeout = self.api.default_timeout_sec
        if urlparse.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_gen(
                plugin_path, progress_callback=progress_callback)

        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)
コード例 #10
0
    def upload(self, plugin_path):
        """
        Uploads a plugin archive to the remote Cloudify manager plugins
        repository.
        :param plugin_path: Path to plugin archive.
        :return: Uploaded plugin.
        """
        assert plugin_path

        uri = '/plugins'
        query_params = {}

        if urlparse.urlparse(plugin_path).scheme and \
                not os.path.exists(plugin_path):
            query_params['plugin_archive_url'] = plugin_path
            data = None
        else:
            data = bytes_stream_utils.request_data_file_stream_gen(
                plugin_path)

        response = self.api.post(uri, params=query_params, data=data,
                                 expected_status_code=201)
        return Plugin(response)