Example #1
0
File: ftp.py Project: brtsz/zato
    def handle(self, *args, **kwargs):
        
        with closing(self.server.odb.session()) as session:
            payload = kwargs.get('payload')

            core_params = ['cluster_id', 'name', 'is_active', 'host', 'port', 'dircache']
            core_params = _get_params(payload, core_params, 'data.')
            
            optional_params = ['user', 'acct', 'timeout']
            optional_params = _get_params(payload, optional_params, 'data.', default_value=None)

            name = core_params['name']
            cluster_id = core_params['cluster_id']

            existing_one = session.query(OutgoingFTP.id).\
                filter(OutgoingFTP.cluster_id==cluster_id).\
                filter(OutgoingFTP.name==name).\
                first()

            if existing_one:
                raise Exception('An outgoing FTP connection [{0}] already exists on this cluster'.format(name))

            created_elem = Element('out_ftp')

            try:

                core_params['is_active'] = is_boolean(core_params['is_active'])
                core_params['dircache'] = is_boolean(core_params['dircache'])

                item = OutgoingFTP()
                item.name = core_params['name']
                item.is_active = core_params['is_active']
                item.cluster_id = core_params['cluster_id']
                item.dircache = core_params['dircache']
                item.host = core_params['host']
                item.port = core_params['port']
                item.user = optional_params['user']
                item.acct = optional_params['acct']
                item.timeout = optional_params['timeout']

                session.add(item)
                session.commit()

                created_elem.id = item.id
                self.update_facade(core_params, optional_params)

                return ZATO_OK, etree.tostring(created_elem)

            except Exception, e:
                msg = 'Could not create an outgoing FTP connection, e=[{e}]'.format(e=format_exc(e))
                self.logger.error(msg)
                session.rollback()

                raise
Example #2
0
File: ftp.py Project: dsuch/zato
    def handle(self):
        input = self.request.input
        
        with closing(self.odb.session()) as session:
            existing_one = session.query(OutgoingFTP.id).\
                filter(OutgoingFTP.cluster_id==input.cluster_id).\
                filter(OutgoingFTP.name==input.name).\
                first()

            if existing_one:
                raise Exception('An outgoing FTP connection [{0}] already exists on this cluster'.format(input.name))

            try:
                item = OutgoingFTP()
                item.name = input.name
                item.is_active = input.is_active
                item.cluster_id = input.cluster_id
                item.dircache = input.dircache
                item.host = input.host
                item.port = input.port
                item.user = input.user
                item.acct = input.acct
                item.timeout = input.timeout

                session.add(item)
                session.commit()

                self.notify_worker_threads(input)

                self.response.payload.id = item.id
                self.response.payload.name = item.name

            except Exception, e:
                msg = 'Could not create an outgoing FTP connection, e:[{e}]'.format(e=format_exc(e))
                self.logger.error(msg)
                session.rollback()

                raise
Example #3
0
File: ftp.py Project: xbx/zato
    def handle(self):
        input = self.request.input

        with closing(self.odb.session()) as session:
            existing_one = session.query(OutgoingFTP.id).\
                filter(OutgoingFTP.cluster_id==input.cluster_id).\
                filter(OutgoingFTP.name==input.name).\
                first()

            if existing_one:
                raise Exception(
                    'An outgoing FTP connection [{0}] already exists on this cluster'
                    .format(input.name))

            try:
                item = OutgoingFTP()
                item.name = input.name
                item.is_active = input.is_active
                item.cluster_id = input.cluster_id
                item.dircache = input.dircache
                item.host = input.host
                item.port = input.port
                item.user = input.user
                item.acct = input.acct
                item.timeout = input.timeout or None

                session.add(item)
                session.commit()

                self.notify_worker_threads(input)

                self.response.payload.id = item.id
                self.response.payload.name = item.name

            except Exception, e:
                msg = 'Could not create an outgoing FTP connection, e:[{e}]'.format(
                    e=format_exc(e))
                self.logger.error(msg)
                session.rollback()

                raise
Example #4
0
    def handle(self):

        input = self.request.input

        with closing(self.odb.session()) as session:
            existing_one = session.query(OutgoingFTP.id).\
                filter(OutgoingFTP.cluster_id==input.cluster_id).\
                filter(OutgoingFTP.name==input.name).\
                first()

            if existing_one:
                raise Exception(
                    'Outgoing FTP connection `{}` already exists'.format(
                        input.name))

            try:
                item = OutgoingFTP()
                item.name = input.name
                item.is_active = input.is_active
                item.cluster_id = input.cluster_id
                item.dircache = input.dircache
                item.host = input.host
                item.port = input.port
                item.user = input.user
                item.acct = input.acct
                item.timeout = input.timeout or None

                # Opaque attributes
                set_instance_opaque_attrs(item, input)

                session.add(item)
                session.commit()

                self.notify_worker_threads(input)

                self.response.payload.id = item.id
                self.response.payload.name = item.name

            except Exception:
                self.logger.error(
                    'Outgoing FTP connection could not be created, e:`{}`',
                    format_exc())
                session.rollback()

                raise