openstack security group and rules python api use

Posted juandx

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了openstack security group and rules python api use相关的知识,希望对你有一定的参考价值。

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的主要内容,如果未能解决你的问题,请参考以下文章

Openstack Horizon 可插拔Panels 和 Groups

Openstack Horizon 可插拔Panels 和 Groups

TF aws_security_group:属性“ingress”的值不合适:需要属性“prefix_list_ids”、“security_groups”和“self”

openstack-kilo--issue(十五) WARNING keystonemiddleware.auth_token Authorization failed for token Could

KeyCloak 服务器引起:java.lang.ClassNotFoundException:java.security.acl.Group

属性“com.apple.security.application-groups in”在设备中不起作用