def load(core_rest_api): document = core_rest_api.content_parser.document( Field('id', Unicode()), Field('ip', Unicode()), Field('mac', Unicode()), Field('sn', Unicode()), Field('plugin', Unicode()), Field('vendor', Unicode()), Field('model', Unicode()), Field('version', Unicode()), Field('description', Unicode()), Field('status', Unicode()), Field('template_id', Unicode()), Field('options', Dict()) ) blueprint = Blueprint('devices', __name__, url_prefix='/%s/devices' % config.API_VERSION) converter = Converter.resource(document, Device) provd_client = core_rest_api.provd_client() device_dao = builder.build_dao(provd_client) device_service = builder.build_service(device_dao) device_updater = builder.build_device_updater(device_dao) association_service = builder.build_line_device_associator(device_updater) resource = DeviceResource(device_service, association_service, converter) chain = DecoratorChain(core_rest_api, blueprint) chain.search().decorate(resource.search) chain.get('/<resource_id>').decorate(resource.get) chain.create().decorate(resource.create) chain.edit('/<resource_id>').decorate(resource.edit) chain.delete('/<resource_id>').decorate(resource.delete) (chain .get('/<device_id>/synchronize') .decorate(resource.synchronize)) (chain .get('/<device_id>/autoprov') .decorate(resource.autoprov)) (chain .limit_localhost() .get('/<device_id>/associate_line/<int:line_id>') .decorate(resource.associate_line)) (chain .limit_localhost() .get('/<device_id>/remove_line/<int:line_id>') .decorate(resource.remove_line)) core_rest_api.register(blueprint)
def load(core_rest_api): validator = fk_validator.build_validators() bsfilter_validator = fk_validator.BSFilterValidator(bsfilter_dao) funckey_converter = fk_converter.build_funckey_converter(exclude=['agent', 'bsfilter']) user_funckey_converter = fk_converter.build_funckey_converter() template_converter = fk_converter.build_template_converter(funckey_converter) user_template_converter = fk_converter.build_template_converter(user_funckey_converter) association_converter = fk_converter.build_association_converter(core_rest_api.content_parser) provd_client = core_rest_api.provd_client() device_dao = device_builder.build_dao(provd_client) device_updater = device_builder.build_device_updater(device_dao) service = fk_service.TemplateService(validator, template_dao, user_dao, notifier, device_updater) template_manipulator = TemplateManipulator(service, device_updater, user_dao) template_resource = CRUDResource(service, template_converter) funckey_resource = FuncKeyResource(template_manipulator, funckey_converter, association_converter) user_funckey_resource = UserFuncKeyResource(template_manipulator, user_funckey_converter, association_converter, bsfilter_validator, user_dao) user_template_resource = UserTemplateResource(template_manipulator, user_template_converter, association_converter) blueprint = Blueprint('func_key_templates', __name__, url_prefix='/%s/funckeys/templates' % config.API_VERSION) fk_blueprint = Blueprint('func_keys', __name__, url_prefix='/%s/funckeys' % config.API_VERSION) user_blueprint = core_rest_api.blueprint('users') chain = DecoratorChain(core_rest_api, blueprint) fk_chain = DecoratorChain(core_rest_api, fk_blueprint) # /funckeys fk_chain.get("/destinations").decorate(funckey_resource.get_destinations) # /funckeys/templates chain.search().decorate(template_resource.search) chain.get().decorate(template_resource.get) chain.create().decorate(template_resource.create) chain.delete().decorate(template_resource.delete) # /funckeys/templates/:id/:position chain.edit("/<int:template_id>/<int:position>").decorate(funckey_resource.update_funckey) chain.delete("/<int:template_id>/<int:position>").decorate(funckey_resource.remove_funckey) chain.get("/<int:template_id>/<int:position>").decorate(funckey_resource.get_funckey) chain.get("/<int:template_id>/users").decorate(funckey_resource.get_associations) user_chain = DecoratorChain(core_rest_api, user_blueprint) # /users/:id/funckeys user_chain.get("/<int:user_id>/funckeys/<int:position>").decorate(user_funckey_resource.get_funckey) user_chain.edit("/<int:user_id>/funckeys/<int:position>").decorate(user_funckey_resource.update_funckey) user_chain.delete("/<int:user_id>/funckeys/<int:position>").decorate(user_funckey_resource.remove_funckey) # /users/:id/funckeys/templates user_chain.get("/<int:user_id>/funckeys").decorate(user_template_resource.get_unified_template) user_chain.edit("/<int:user_id>/funckeys/templates/<int:template_id>").decorate(user_template_resource.associate_template) user_chain.delete("/<int:user_id>/funckeys/templates/<int:template_id>").decorate(user_template_resource.dissociate_template) user_chain.get("/<int:user_id>/funckeys/templates").decorate(user_template_resource.get_associations) core_rest_api.register(blueprint) core_rest_api.register(user_blueprint) core_rest_api.register(fk_blueprint)
def _update_device(line): device_dao = device_builder.build_dao(provd_client) device_updater = device_builder.build_device_updater(device_dao) device_updater.update_for_line(line)