码迷,mamicode.com
首页 > 编程语言 > 详细

openstack security group and rules python api use

时间:2016-06-01 19:40:36      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:

nova和neutron都可以,但是感觉还是用neutron好。

 

import neutronclient.v2_0.client as neclient
neutron = neclient.Client(username=‘admin‘,password=‘password‘,tenant_name=‘admin‘,auth_url=‘http://ip:5000/v2.0‘)

s1 = neutron.create_security_group(body={‘security_group‘:{‘name‘:‘block‘}})
for r in s1[‘security_group‘][‘security_group_rules‘]:
    neutron.delete_security_group_rule(security_group_rule=r[‘id‘])

sgs = neutron.list_security_groups()[‘security_groups‘]
s2 = ‘‘
for sg in sgs:
    if sg[‘name‘]==‘block‘:
        s2 = sg
        break

if s2!=‘‘:
    neutron.create_security_group_rule(body={"security_group_rule": {
                        "direction": "ingress",
                        "ethertype": "IPv4",
                        "protocol": None,
                        "remote_ip_prefix":"192.168.0.0/16",
                        "security_group_id":s2[‘id‘] }
                      })

    neutron.create_security_group_rule(body={"security_group_rule": {
                        "direction": "egress",
                        "ethertype": "IPv4",
                        "protocol": None,
                         "remote_ip_prefix":"192.168.0.0/16",
                        "security_group_id":s2[‘id‘] }
                      })

  

文档感觉很low,去binding python的文档看neutron的简直想死 http://docs.openstack.org/developer/python-neutronclient/ 。。。只能去看源码

看参数还是得去看原生api http://developer.openstack.org/api-ref-networking-v2-ext.html

 

openstack security group and rules python api use

标签:

原文地址:http://www.cnblogs.com/juandx/p/5550629.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!