divendres, 3 de març del 2017



Programing with the OpenStackClient.

Due the fact that all the documentation regarding the neutront is mentioning the old neutron pakcage
and this packge is not installed in the default openstackcli so it is necessary to get access to the package neutronclient.v2_0



pip install python-openstackclient

pip install python-neutronclient.


To run the code you have to download the credentiansl and executhe the sh whith source in order to keep the envirotmetn varibles in your session.

source yourcredentials.sh


Below a simple program which creates the security rules, security rules are something very similar to a firewall. You need to create at least one security rules and open ports and protocols in order to connect with your VM.

Do not forget the icmp in order to allow the routing towards the virtual instances.

to run tihis code


'''
Created on Feb 26, 2017

@author: jordi
'''
from os import environ as env


from keystoneauth1 import session
from keystoneauth1 import loading
from novaclient import client
import logging


logging.basicConfig(level=logging.ERROR)


loader = loading.get_plugin_loader('password')
auth = loader.load_from_options(
                    auth_url=env['OS_AUTH_URL'],
                   username=env['OS_USERNAME'],
                   password=env['OS_PASSWORD'],
                   tenant_name=env['OS_TENANT_NAME'],
                  
                   )
sess = session.Session(auth=auth,verify=False)
nova = client.Client('2',session=sess)

nova.security_groups.create(name="web", description='jordi servers')
group = nova.security_groups.find(name="web")
nova.security_group_rules.create(group.id, ip_protocol="icmp",from_port=-1, to_port=-1)
nova.security_group_rules.create(group.id, ip_protocol="tcp",from_port=80, to_port=80)
nova.security_group_rules.create(group.id, ip_protocol="tcp",from_port=8080, to_port=8080)
nova.security_group_rules.create(group.id, ip_protocol="tcp",from_port=443, to_port=443) 


The result in OpenStack Horizont.



However this API has because there is not egreess option. To solve it is better use the new OpenStackSdk. Next entry

Cap comentari:

Publica un comentari a l'entrada