Ejemplo n.º 1
0
def update_topo(topo, test_vn, new_policy):
    ''' Purpose of this def is to update & return topology object as needed.
    Example:  Need to modify VN's policy list..  This change requires update
    of every [affected] policy's VN list as well.
    Reference info of how data is maintained:
    vn_policy=  {'vnet0': ['policy0', 'policy1'], 'vnet1': ['policy2', 'policy3']}
    policy_vn= {'policy0': ['vnet0']}
    '''
    n_topo = copy.deepcopy(topo)
    # i] remove test_vn from currently associated policies
    topo_helper_obj = topology_helper(n_topo)
    n_topo.policy_vn = topo_helper_obj.get_policy_vn()
    for p in topo.vn_policy[test_vn]:
        n_topo.policy_vn[p].remove(test_vn)
    # ii] update vn_policy[test_vn] and policy_vn[new_policy] with new info
    n_topo.vn_policy[test_vn] = [new_policy]
    n_topo.policy_vn[new_policy].append(test_vn)
    return n_topo
                        'ip_prefix_len': 0
                    }
                }],
                'rule_uuid':
                uuid_2
            },
        ]
        return self

    # end sdn_topo_with_multi_project


if __name__ == '__main__':
    print "Currently topology limited to one domain/project.."
    print "Based on need, can be extended to cover config for multiple domain/projects"
    print "Running unit test for this module ..."
    my_topo = sdn_basic_policy_topo_with_multi_project(domain='default-domain')
    x = my_topo.__dict__
    print "\nprinting keys of topology dict:"
    for key, value in x.iteritems():
        print key
    print
    # Use topology_helper to extend/derive data from user-defined topology to help verifications.
    # ex. get list of all vm's from topology; get list of vn's associated to a
    # policy
    import topo_helper
    topo_h = topo_helper.topology_helper(my_topo)
    policy_vn = topo_h.get_policy_vn()
    print "printing derived topo data - vn's associated to a policy: \n", policy_vn
#
        self.rules[
            'policy-admin'] = [{'direction': '<>', 'protocol': 'icmp', 'dest_network': 'default-domain:project2:vnet2',
                                'source_network': 'default-domain:admin:vnet-admin', 'dst_ports': 'any', 'simple_action': 'pass', 'src_ports': 'any'}]
        #
        # Define public VN
        self.public_vn = 'public-vn'
        return self
   # end sdn_basic_policy_topo_with_fip

if __name__ == '__main__':
    print "Currently topology limited to one domain/project.."
    print "Based on need, can be extended to cover config for multiple domain/projects"
    print "Running unit test for this module ..."
    my_topo = sdn_basic_policy_topo_with_3_project(domain='default-domain')
    x = my_topo.__dict__
    print "\nprinting keys of topology dict:"
    for key, value in x.iteritems():
        print key
    print
    # print "keys & values:"
    # for key, value in x.iteritems(): print key, "-->", value
    # Use topology_helper to extend/derive data from user-defined topology to help verifications.
    # ex. get list of all vm's from topology; get list of vn's associated to a
    # policy
    import topo_helper
    topo_h = topo_helper.topology_helper(my_topo)
    #vmc_list= topo_h.get_vmc_list()
    policy_vn = topo_h.get_policy_vn()
    print "printing derived topo data - vn's associated to a policy: \n", policy_vn
#