¡@

Home 

OpenStack Study: nvsd_db.py

OpenStack Index

**** CubicPower OpenStack Study ****

def get_port_from_device(port_id):

    session = db.get_session()

    sg_binding_port = sg_db.SecurityGroupPortBinding.port_id

    query = session.query(models_v2.Port,

                          sg_db.SecurityGroupPortBinding.security_group_id)

    query = query.outerjoin(sg_db.SecurityGroupPortBinding,

                            models_v2.Port.id == sg_binding_port)

    query = query.filter(models_v2.Port.id == port_id)

    port_and_sgs = query.all()

    if not port_and_sgs:

        return None

    port = port_and_sgs[0][0]

    plugin = manager.NeutronManager.get_plugin()

    port_dict = plugin._make_port_dict(port)

    port_dict[ext_sg.SECURITYGROUPS] = [

        sg_id for tport, sg_id in port_and_sgs if sg_id]

    port_dict['security_group_rules'] = []

    port_dict['security_group_source_groups'] = []

    port_dict['fixed_ips'] = [ip['ip_address']

                              for ip in port['fixed_ips']]

    return port_dict