def add_extension(self, name, namespace, routing_key, exchange, patterns): """Add an API extension. :param name: (str): The name of the new API extension service. :param namespace: (str): The namespace of the new API extension service. :param routing_key: (str): AMQP routing key to use with the extension. :param exchange: (str): AMQP exchange to use with the extension. :param patterns: (str): URI API filters to register with the extension. :return: (lxml.objectify.ObjectifiedElement): object containing the sparse representation of the API extension. """ params = E_VMEXT.Service({'name': name}) params.append(E_VMEXT.Namespace(namespace)) params.append(E_VMEXT.Enabled('true')) params.append(E_VMEXT.RoutingKey(routing_key)) params.append(E_VMEXT.Exchange(exchange)) filters = E_VMEXT.ApiFilters() for pattern in patterns: filters.append( E_VMEXT.ApiFilter(E_VMEXT.UrlPattern(pattern.strip()))) params.append(filters) ext = self.client.get_extension() ext_services = self.client.get_linked_resource( ext, RelationType.DOWN, EntityType.EXTENSION_SERVICES.value) return self.client.post_linked_resource(ext_services, RelationType.ADD, EntityType.ADMIN_SERVICE.value, params)
def add_extension(self, name, namespace, routing_key, exchange, patterns, description=None): """Add an API extension service. :param str name: name of the new API extension service. :param str namespace: namespace of the new API extension service. :param str routing_key: AMQP routing key to use with the extension. :param str exchange: AMQP exchange to use with the extension. :param list patterns: list of url API filters to register with the extension. :return: object containing EntityType.ADMIN_SERVICE XML data i.e. the sparse representation of the API extension. :rtype: lxml.objectify.ObjectifiedElement """ params = E_VMEXT.Service({'name': name}) if description is not None: params.append(E.Description(description)) params.append(E_VMEXT.Namespace(namespace)) params.append(E_VMEXT.Enabled('true')) params.append(E_VMEXT.RoutingKey(routing_key)) params.append(E_VMEXT.Exchange(exchange)) filters = E_VMEXT.ApiFilters() for pattern in patterns: filters.append( E_VMEXT.ApiFilter(E_VMEXT.UrlPattern(pattern.strip()))) params.append(filters) ext = self.client.get_extension() ext_services = self.client.get_linked_resource( ext, RelationType.DOWN, EntityType.EXTENSION_SERVICES.value) return self.client.post_linked_resource(ext_services, RelationType.ADD, EntityType.ADMIN_SERVICE.value, params)
def enable_extension(self, name, enabled=True, namespace=None): """Enable or disable an API extension service. :param str name: the name of the extension service whose we want to enable/disable. :param str namespace: the namespace of the extension service. If not specified (i.e. = None), we will use the value passed in the `name` parameter. :param bool enabled: flag to enable or disable the extension. :return: href of the service being enabled/disabled. :rtype: str :raises MissingRecordException: if a service with the given name and namespace couldn't be found. :raise MultipleRecordsException: if more than one service with the given name and namespace are found. """ record = self._get_extension_record(name=name, namespace=namespace, format=QueryResultFormat.RECORDS) params = E_VMEXT.Service({'name': name}) params.append(E_VMEXT.Namespace(record.get('namespace'))) params.append(E_VMEXT.Enabled('true' if enabled else 'false')) params.append(E_VMEXT.RoutingKey(record.get('routingKey'))) params.append(E_VMEXT.Exchange(record.get('exchange'))) self.client.put_resource(record.get('href'), params, None) return record.get('href')
def update_extension(self, name, namespace=None, routing_key=None, exchange=None, description=None): """Update properties for an existing API extension. :param str name: name of the API extension. :param str namespace: namespace of the API extension. :param str routing_key: AMQP routing key to use for the extension. :param str exchange: AMQP exchange to use for the extension. :return: href of the API extension. :rtype: str :raises MissingRecordException: if an extension with the given name and namespace couldn't be found. :raise MultipleRecordsException: if more than one service with the given name and namespace are found. """ record = self._get_extension_record(name=name, namespace=namespace, format=QueryResultFormat.RECORDS) params = E_VMEXT.Service({'name': name}) description = description or record.get('description') if description is not None: params.append(E.Description(description)) params.append(E_VMEXT.Namespace(record.get('namespace'))) params.append(E_VMEXT.Enabled(record.get('enabled'))) params.append(E_VMEXT.RoutingKey( routing_key if routing_key else record.get('routingKey'))) params.append(E_VMEXT.Exchange( exchange if exchange else record.get('exchange'))) self.client.put_resource(record.get('href'), params, None) return record.get('href')
def enable_extension(self, name, enabled=True, namespace=None): """Enable or disable an API extension service. :param str name: the name of the extension service whose we want to enable/disable. :param str namespace: the namespace of the extension service. If not specified (i.e. = None), we will use the value passed in the `name` parameter. :param bool enabled: flag to enable or disable the extension. :return: object containing EntityType.ADMIN_SERVICE XML data representing the updated API extension. :rtype: lxml.objectify.ObjectifiedElement """ record = self.client.get_typed_query( ResourceType.ADMIN_SERVICE, qfilter='name==%s;namespace==%s' % (name, namespace if namespace else name), query_result_format=QueryResultFormat.RECORDS).find_unique() params = E_VMEXT.Service({'name': name}) params.append(E_VMEXT.Namespace(record.get('namespace'))) params.append(E_VMEXT.Enabled('true' if enabled else 'false')) params.append(E_VMEXT.RoutingKey(record.get('routingKey'))) params.append(E_VMEXT.Exchange(record.get('exchange'))) self.client.put_resource(record.get('href'), params, None) return record.get('href')
def enable_extension(self, name, enabled=True): record = self.client.get_typed_query( self.TYPE_NAME, equality_filter=('name', name), query_result_format=QueryResultFormat.RECORDS).find_unique() params = E_VMEXT.Service({'name': name}) params.append(E_VMEXT.Namespace(record.get('namespace'))) params.append(E_VMEXT.Enabled('true' if enabled else 'false')) params.append(E_VMEXT.RoutingKey(record.get('routingKey'))) params.append(E_VMEXT.Exchange(record.get('exchange'))) self.client.put_resource(record.get('href'), params, None) return record.get('href')
def add_extension(self, name, namespace, routing_key, exchange, patterns): params = E_VMEXT.Service({'name': name}) params.append(E_VMEXT.Namespace(namespace)) params.append(E_VMEXT.Enabled('true')) params.append(E_VMEXT.RoutingKey(routing_key)) params.append(E_VMEXT.Exchange(exchange)) filters = E_VMEXT.ApiFilters() for pattern in patterns: filters.append( E_VMEXT.ApiFilter(E_VMEXT.UrlPattern(pattern.strip()))) params.append(filters) ext = self.client.get_extension() ext_services = self.client.get_linked_resource( ext, RelationType.DOWN, EntityType.EXTENSION_SERVICES.value) return self.client.post_linked_resource(ext_services, RelationType.ADD, EntityType.ADMIN_SERVICE.value, params)
def enable_extension(self, name, enabled=True): """Enable or disable the API extension service. :param name: (str): The name of the extension service. :param enabled: (bool): Flag to enable or disable the extension. :return: (lxml.objectify.ObjectifiedElement): object containing the representation of the API extension. """ record = self.client.get_typed_query( self.TYPE_NAME, equality_filter=('name', name), query_result_format=QueryResultFormat.RECORDS).find_unique() params = E_VMEXT.Service({'name': name}) params.append(E_VMEXT.Namespace(record.get('namespace'))) params.append(E_VMEXT.Enabled('true' if enabled else 'false')) params.append(E_VMEXT.RoutingKey(record.get('routingKey'))) params.append(E_VMEXT.Exchange(record.get('exchange'))) self.client.put_resource(record.get('href'), params, None) return record.get('href')