如果你打算在js中使用openstack接口(如jstack),就会碰到js的跨域请求问题,解决方法是要在openstack api的response中加上Access-Control-Allow-Origin: *
这样的头信息。
##反向代理 如果给api配置了反向代理,可以参考:
##配置wsgi 几乎所有的openstack api都使用了wsgi服务,我们可以在wsgi这层设置CORS信息。
首先安装一个python模块
pip install wsgicors
###让Keystone支持CORS 编辑/etc/keystone/keystone-paste.ini
,新增如下内容:
[filter:cors]use = egg:wsgicors#middlewarepolicy = openopen_origin = *open_headers = *open_methods = *open_maxage = 86400
然后,在每个pipeline的开头加上cors
,例如:
[pipeline:public_api]pipeline = cors stats_monitoring sizelimit url_normalize build_auth_context token_auth admin_token_auth xml_body_v2 json_body ec2_extension user_crud_extension public_service[pipeline:admin_api]pipeline = cors sizelimit url_normalize build_auth_context token_auth admin_token_auth xml_body_v2 json_body ec2_extension s3_extension crud_extension admin_service[pipeline:api_v3]pipeline = cors stats_reporting sizelimit url_normalize build_auth_context token_auth admin_token_auth xml_body_v3 json_body ec2_extension_v3 s3_extension simple_cert_extension revoke_extension service_v3[pipeline:public_version_api]pipeline = cors sizelimit url_normalize xml_body public_version_service[pipeline:admin_version_api]pipeline = cors sizelimit url_normalize xml_body admin_version_service
最后重启服务
service keystone restart
###让nova-api支持CORS 编辑/etc/nova/api-paste.ini
,新增如下内容:
[filter:cors]use = egg:wsgicors#middlewarepolicy = openopen_origin = *open_headers = *open_methods = *open_maxage = 86400
然后,在每个pipeline的开头加上cors
,例如:
[composite:openstack_compute_api_v2]use = call:nova.api.auth:pipeline_factorynoauth = cors compute_req_id faultwrap sizelimit noauth ratelimit osapi_compute_app_v2keystone = cors compute_req_id faultwrap sizelimit authtoken keystonecontext ratelimit osapi_compute_app_v2keystone_nolimit = cors compute_req_id faultwrap sizelimit authtoken keystonecontext osapi_compute_app_v2[composite:openstack_compute_api_v21]use = call:nova.api.auth:pipeline_factory_v21noauth = cors request_id faultwrap sizelimit noauth osapi_compute_app_v21keystone = cors request_id faultwrap sizelimit authtoken keystonecontext osapi_compute_app_v21[composite:openstack_compute_api_v3]use = call:nova.api.auth:pipeline_factory_v21noauth = cors request_id faultwrap sizelimit noauth_v3 osapi_compute_app_v3keystone = cors request_id faultwrap sizelimit authtoken keystonecontext osapi_compute_app_v3
最后重启nova-api
service nova-api restart
##参考