Nova 中的一些基本概念与操作(2)

目录:
1. 基本操作-请求和响应数据格式
2. Nova 命令行工具简要说明
3. 开发指南
4. 开发指南 :Adding a Method to the OpenStack API
5. 开发指南 : Placement API
6. 开发指南 : Policy

一、基本操作-请求和响应数据格式

非常琐碎,所以就不翻译了。开发人员应该在用到时去确认请求和响应格式,且对支持的请求响应有一个大概了解。
http://developer.openstack.org/api-guide/compute/index.html

二、Nova 命令行工具简要说明

  1. nova-api-os-compute : a server daemon that serves the Nova OpenStack Compute API
  2. nova-api-metadata : server daemon that serves the Nova Metadata API
  3. nova-api : server daemon that serves the nova EC2 and OpenStack APIs in separate greenthreads
  4. nova-cells : 启动nova-cells服务。nova-cells服务处理cell之间的通信,为新的选择cells.
  5. nova-cert : server daemon that serves the Nova Cert service for X509 certificates. Only needed for EC2 API.
  6. nova-compute :处理实例(guest vms)相关的所有操作。nova -compute负责 构建磁盘镜像,通过底层driver启动实例,响应“状态检查”请求,绑定持久化存储,终止实例等。
  7. nova-conductor : server daemon that serves the Nova Conductor service, which provides coordination and database query support for Nova.
  8. nova-console : console Proxy to set up multi-tenant VM console access (i.e. with xvp)
  9. nova-consoleauth :Provides Authentication for nova consoles
  10. nova-dhcpbridge : Handles Lease Database updates from DHCP servers 。 Used whenever nova is managing DHCP (vlan and flatDHCP). nova-dhcpbridge should not be run as a daemon.
  11. nova-idmapshift :Tool used by Nova libvirt-lxc virt driver 。在底层实例为Linux容器时,该工具用来处理文件系统的权限管理。
  12. nova-manage :control and manage cloud computer instances by managing shell selection, vpn connections, and floating IP address configuration.
  13. nova-network :Nova Network is responsible for allocating IPs and setting up the network
  14. nova-novncproxy :Websocket novnc Proxy for OpenStack Nova noVNC consoles.
  15. nova-rootwrap :Filters which commands nova is allowed to run as another user.
  16. nova-scheduler :Nova Scheduler picks a compute node to run a VM instance.
  17. nova-serialproxy : Websocket proxy that is compatible with OpenStack Nova
  18. nova-spicehtml5proxy :Websocket Proxy for OpenStack Nova SPICE HTML5 consoles.
  19. nova-status :CLI interface for nova status commands,The nova-status command provides routines for checking the status of a Nova deployment.
  20. nova-xvpvncproxy :XVP VNC Console Proxy Server

三、开发指南

http://docs.openstack.org/developer/nova/

以下是开发指南中部分章节的翻译

四、Adding a Method to the OpenStack API

OpenStack 外部的API接口大多数都是RESTFUL形式,因此,当你需要扩充方法时,应该也要遵守该原则,使用RESTFUL 接口形式。

1.Routing

路由的概念就是将请求URL 映射到 “控制器+action”上去。OpenStack采用的是Routes 包,这是Rails routes的一个Python实现。详细信息见:http://routes.groovie.org/ 。OpenStack中路由相关的代码在nova/api/openstack/init.py中的ApiRouter类中 。路由语法见:http://routes.groovie.org/manual.html

2. Controllers and actions

控制器在“nova/api/openstack ”目录下面,继承了nova.wsgi.Controller类。一个控制器的列子见:nova/api/openstack/compute/servers.py

方法的参数通过 mapper.connect() or .resource()方法从URL中提取出来,其中第一个参数为self,第二个参数为WebOb request。

3. Serialization

Action返回一个字典,wsgi.Controller将该字典序列化成JSON数据。

4.Faults

如果响应的状态码不是200,你应该返回 用faults.Fault(webob.exc.HTTPNotFound()) 代替 返回一个异常。

五、Placement API

Placement API的作用:查询管理resource provider,包括查询resource provider目录,分配记录,所属的aggregates。

1. Placement API简介

Nova在 Newton 14.0.0版中引入Placement API。这是一个比较独立的Rest API 栈,建立该数据模型是为了追踪记录resources provider目录和resource使用情况。例如,resource provider可以是一个计算节点、共享存储池或是IP地址池。placement 服务追踪每种resource provider的服务目录,使用情况(意思就是,可以从placement API获取resource provider目录,并获取resource provider的资源使用情况)。例如一个新建的instance是 某个compute node resource provider的消费者,消费RAM,CPU资源,也是外部存储资源池的消费者,也是IP resource provider的消费者。

PS:之前是没有Placement API的,该API的出现是为了解决之前设计的一些问题:
(1)之前对资源的管理全由compute node来做的,即compute node为resource provider,在统计资源使用情况时,简单的将所有compute node的资源情况加起来。但这是错误的,系统中存在外部的资源,这些资源由外部系统提供,如Ceph,NFS提供的存储服务的。当resources provider变得多种多样时,需要一个统一的、简单的管理接口,让管理员知道系统中的资源使用情况,这就是Placement API。
(2)在(1)的基础上,当我们使用resources provider模型 来追踪系统大量资源的使用情况后,我们需要对数据库模型也做相应的改变:1,引入一张表来存储 各种通用资源的resource的 inventory/capacity信息;2,引入一张表存储inventory 的usage/allocation信息。

关于没有Placement API的设计中的问题可见如下链接:
https://specs.openstack.org/openstack/nova-specs/specs/newton/implemented/generic-resource-pools.html

https://specs.openstack.org/openstack/nova-specs/specs/newton/implemented/compute-node-inventory-newton.html

https://specs.openstack.org/openstack/nova-specs/specs/newton/implemented/resource-providers-allocations.html

https://specs.openstack.org/openstack/nova-specs/specs/newton/implemented/resource-providers.html

2. API 示例

List all allocations against the resource provider identified by uuid.

GET /resource_providers/5af2c770-6878-4dc6-b739-1164cf990fc5/allocations

{
  "resource_provider_generation": 99,
  "allocations": {
    "9a82ff67-26e2-4d0a-a7e1-746788a85646": {
        "resources": {
            "DISK_GB": 6,
            "VCPU": 3
        }
    },
    "aeaf9aa1-8d4a-46e6-8dec-cf2c704b5976": {
        "resource": {
            "DISK_GB": 2,
            "VCPU": 1
        }
    }
  }
}

3. Big Picture

Placement API 服务就是一个WSGI 服务,发送接收JSON 数据,使用RDBMS做持久化处理。服务模块扩大通过增加WSGI服务的数据 、扩大RDBMS服务。

https://docs.openstack.org/developer/nova/placement_dev.html
https://docs.openstack.org/developer/nova/placement.html

六、Policy

先说一下几个相关概念:
(1)User : 用户。
(2)tenant: 用户组的概念( A group of users, used to isolate access to Nova resources, an alternative term for a Nova project. Project :A logical grouping of users within Nova, used to define quotas and access to virtual machine images.)
(3)Roles :是权限的集合,可以将role赋予某个user,使这个user拥有相应的权限,方便用户权限管理。

简单来说,policy就是用来控制某一个User在某个Tenant中的权限的。这个User能执行什么操作,不能执行什么操作,就是通过policy机制来实现的。直观的看,policy就是一个json文件,位于/etc/[SERVICE_CODENAME]/policy.json中,每一个服务都有一个对应的policy.json文件,通过配置这个文件,实现了对User的权限管理。policy.json文件可以在role的级别配置,不过默认的配置的角色只有admin,如果需要配置其他的角色,需要自己创建,然后在policy.json中进行配置。

policy.json的一个例子:

{  
"context_is_admin":  "role:admin",  
"admin_or_owner":  "is_admin:True or project_id:%(project_id)s",  
"default": "rule:admin_or_owner",  
"compute:create": "role:admin",  
"compute:create:attach_network": "",  
"compute:create:attach_volume": "",  
"compute:create:forced_host": "is_admin:True",  
"compute:get_all": "",  
......  
}  

policy.json有两种写法,一种是每一行写成列表形式的,另一种就是上面的例子,是写成字符串形式的,这里只说后面一种情况。
每一行可以分为两部分:冒号前面的叫做action,即用户执行的操作,冒号后面的叫rule,即用来根据当前的上下文(context),来判断前面的action是否能够由当前的user执行。policy做的主要工作,就是来解析这个rule的,要把这个字符串的rule,解析成相应的对象,在外部调用policy进行权限认证的时候,根据action映射到相应的rule对象,然后由这个对象判断是否能够执行这个action。

http://blog.csdn.net/hackerain/article/details/8241691/
https://docs.openstack.org/developer/nova/sample_policy.html
https://docs.openstack.org/developer/nova/policy_enforcement.html

猜你喜欢

转载自blog.csdn.net/youyou1543724847/article/details/71514534