Nova and neutron are OK, but still feel good with 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 breakif s2!= ': Neutron.crea Te_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 '} })
The document feels very low, go to binding Python document to see Neutron's simply want to die http://docs.openstack.org/developer/python-neutronclient/... Only to see the source code
To see the parameters or to see the native API http://developer.openstack.org/api-ref-networking-v2-ext.html
OpenStack security group and rules Python API use