from libcloud.compute import providers from libcloud_rest.api.handlers import ServiceHandler, invoke_method,\ invoke_extension_method, list_providers, provider_info from libcloud_rest.utils import json invoke_method = partial(invoke_method, providers) compute_handler = ServiceHandler('/compute/') compute_handler.add_handlers([ ('/providers', partial(list_providers, providers)), ('/providers/<string:provider_name>', partial(provider_info, providers)), ('/<string:provider>/<string:method_name>', partial(invoke_extension_method, providers), ['POST']), ('/<string:provider>/nodes', partial(invoke_method, 'list_nodes')), ('/<string:provider>/images', partial(invoke_method, 'list_images')), ('/<string:provider>/sizes', partial(invoke_method, 'list_sizes')), ('/<string:provider>/locations', partial(invoke_method, 'list_locations')) ]) @compute_handler.handler('/<string:provider>/nodes', methods=['POST']) def create_node(request): """ Invoke create_node method and patch response. @return: Response object with newly created node ID in Location. """ response = invoke_method('create_node', request) node_id = json.loads(response.data)['id']
from libcloud.compute import providers from libcloud_rest.api.handlers import ServiceHandler, invoke_method,\ invoke_extension_method, list_providers, provider_info from libcloud_rest.utils import json invoke_method = partial(invoke_method, providers) compute_handler = ServiceHandler('/compute/') compute_handler.add_handlers([ ('/providers', partial(list_providers, providers)), ('/providers/<string:provider_name>', partial(provider_info, providers)), ('/<string:provider>/<string:method_name>', partial(invoke_extension_method, providers), ['POST']), ('/<string:provider>/nodes', partial(invoke_method, 'list_nodes')), ('/<string:provider>/images', partial(invoke_method, 'list_images')), ('/<string:provider>/sizes', partial(invoke_method, 'list_sizes')), ('/<string:provider>/locations', partial(invoke_method, 'list_locations')) ]) @compute_handler.handler('/<string:provider>/nodes', methods=['POST']) def create_node(request): """ Invoke create_node method and patch response. @return: Response object with newly created node ID in Location. """ response = invoke_method('create_node', request)
from libcloud.loadbalancer import providers from libcloud_rest.api.handlers import ServiceHandler, invoke_method,\ invoke_extension_method, list_providers, provider_info from libcloud_rest.utils import json invoke_method = partial(invoke_method, providers) lb_handler = ServiceHandler('/loadbalancer/') lb_handler.add_handlers([ ('/providers', partial(list_providers, providers)), ('/providers/<string:provider_name>', partial(provider_info, providers)), ('/<string:provider>/<string:method_name>', partial(invoke_extension_method, providers), ['POST']), ('/<string:provider>/algorithms', partial(invoke_method, 'list_supported_algorithms')), ('/<string:provider>/balancers', partial(invoke_method, 'list_balancers')), ('/<string:provider>/protocols', partial(invoke_method, 'list_protocols')), ('/<string:provider>/locations', partial(invoke_method, 'list_locations')) ]) @lb_handler.handler('/<string:provider>/balancers', methods=['POST']) def create_balancer(request): """ Invoke create_balancer method and patch response. @return: Response object with newly created balancer ID in Location. """ response = invoke_method('create_balancer', request)
from libcloud.storage import providers from werkzeug.wsgi import wrap_file from libcloud_rest.api.handlers import ServiceHandler, invoke_method,\ list_providers, get_driver_instance from libcloud_rest.utils import json, Response from libcloud_rest.api import entries invoke_method = partial(invoke_method, providers) storage_handler = ServiceHandler('/storage/') storage_handler.add_handlers([ ('/providers', partial(list_providers, providers)), ('/<string:provider>/containers', partial(invoke_method, 'list_containers')), ]) @storage_handler.handler('/<string:provider>/containers', methods=['POST']) def create_container(request): """ Invoke create_container method and patch response. @return: Response object with newly created container name in Location. """ response = invoke_method('create_container', request) container_id = json.loads(response.data)['name'] response.autocorrect_location_header = False response.headers.add_header('Location', container_id)
from werkzeug.wsgi import wrap_file from libcloud_rest.api.handlers import ServiceHandler, invoke_method, list_providers, get_driver_instance from libcloud_rest.utils import json, Response from libcloud_rest.api import entries invoke_method = partial(invoke_method, providers) storage_handler = ServiceHandler("/storage/") storage_handler.add_handlers( [ ("/providers", partial(list_providers, providers)), ("/<string:provider>/containers", partial(invoke_method, "list_containers")), ] ) @storage_handler.handler("/<string:provider>/containers", methods=["POST"]) def create_container(request): """ Invoke create_container method and patch response. @return: Response object with newly created container name in Location. """ response = invoke_method("create_container", request) container_id = json.loads(response.data)["name"] response.autocorrect_location_header = False response.headers.add_header("Location", container_id)
from libcloud_rest.api.handlers import ServiceHandler, invoke_method,\ invoke_extension_method, list_providers, provider_info from libcloud_rest.utils import json invoke_method = partial(invoke_method, providers) lb_handler = ServiceHandler('/loadbalancer/') lb_handler.add_handlers([ ('/providers', partial(list_providers, providers)), ('/providers/<string:provider_name>', partial(provider_info, providers)), ('/<string:provider>/<string:method_name>', partial(invoke_extension_method, providers), ['POST']), ('/<string:provider>/algorithms', partial(invoke_method, 'list_supported_algorithms')), ('/<string:provider>/balancers', partial(invoke_method, 'list_balancers')), ('/<string:provider>/protocols', partial(invoke_method, 'list_protocols')), ('/<string:provider>/locations', partial(invoke_method, 'list_locations')) ]) @lb_handler.handler('/<string:provider>/balancers', methods=['POST']) def create_balancer(request): """ Invoke create_balancer method and patch response. @return: Response object with newly created balancer ID in Location. """