Beispiel #1
0
def addContainers(server, db):
    '''Adds all the containers from the database ( db ) to the cvp instance.
   Ccontainers are addeds in hierarchal manner. After adding  containers, configlets
   and image bundles are also applied to these containers using the backup data.
   This method catches allowable exceptions for smooth execution of the Cvp restore.
   But it raises all other exception denoting error situations. CvpError class object
   contains information about the occured exception.
   Raises:
      CvpError -- If unknown error occur while container addition
   '''
    currRootContainerInfo = server.getRootContainerInfo()
    containerList = []
    if 'Tree' in db:
        for containerInfo in db['Tree']:
            container = cvp.Container(containerInfo['name'],
                                      containerInfo['parentName'],
                                      containerInfo['configlets'],
                                      containerInfo['imageBundle'])
            containerList.append(container)
            if not containerInfo['parentName']:
                if currRootContainerInfo.name != containerInfo['name']:
                    server.renameContainer(currRootContainerInfo,
                                           containerInfo['name'])
                rootContainerName = containerInfo['name']
        containerCount = len(containerList)
        parentQueue = Queue.Queue()
        parentName = rootContainerName
        while containerCount > 1:
            for container in containerList:
                if container.parentName == parentName:
                    try:
                        server.addContainer(container)
                    except cvpServices.CvpError as err:
                        if err.errorCode == errorCodes.DATA_ALREADY_EXISTS:
                            print 'Container already exists:', container.name
                        else:
                            raise
                    parentQueue.put(container.name)
                    containerCount = containerCount - 1
            parentName = parentQueue.get()
        print 'Mapping configlets and image bundles to containers'
        for container in containerList:
            if container.imageBundle:
                imageBundle = server.getImageBundle(container.imageBundle)
                server.mapImageBundleToContainer(container, imageBundle)
            configletList = []
            for configletName in container.configlets:
                configlet = server.getConfiglet(configletName)
                configletList.append(configlet)
            server.mapConfigletToContainer(container, configletList)
		print "!"
		print "!"
		leaf_bgp_configlet_name = leaf['name'] + " bgp configuration"
		print "Contents of configlet %s:" % ( leaf_bgp_configlet_name )
		print "%s" % ( leaf_bgp_config )
		print "!"
		print "!"
		print "!"



#
# If debug is not activated, create Container structure for new DC
#

if debug == "no":
	if rebuild == 0:
		my_dc_container = cvp.Container( name, parentName )
		server.addContainer( my_dc_container )
		server.mapConfigletToContainer( my_dc_container , configlet_list )
		if deploymenttype == "cvx":
			server.mapConfigletToContainer( my_dc_container , cvx_configlet_list )

		my_leaf_container = cvp.Container( my_leaf_container_name , name )
		server.addContainer( my_leaf_container )
		leaf_configlet_list.append( vxlan_configlet )
		server.mapConfigletToContainer( my_leaf_container , leaf_configlet_list )

		my_spine_container = cvp.Container( my_spine_container_name , name )
		server.addContainer( my_spine_container )
Beispiel #3
0
def testContainer(server):
    ''' Tests all the functionalities pertaining to containers in Cvp application'''

    #generate sample configlets
    reference = [('configlet%d' % c, 'configlet%d' % c) for c in range(25)]
    for name, config in reference:
        configlet = cvp.Configlet(name, config)
        server.addConfiglet(configlet)
    #generate random container hierarchy
    containerList = {}
    parentConfig = []
    parentConfig.append(reference[0][0])
    parentConfig.append(reference[2][0])
    parentConfig.append(reference[4][0])
    childConfig = []
    childConfig.append(reference[3][0])
    childConfig.append(reference[5][0])
    childConfig.append(reference[6][0])
    print 'inserting containers'
    currRootContainerInfo = server.getRootContainerInfo()
    for i in range(0, 5):
        container = cvp.Container('parentContainer-%d' % i,
                                  currRootContainerInfo.name, parentConfig)
        server.addContainer(container)
        server.mapConfigletToContainer(container, parentConfig)
        containerList[container.name] = container
        for j in range(0, 3):
            childContainer = cvp.Container(
                'parentContainer%dchildContainer-%d' % (i, j),
                'parentContainer-%d' % i, childConfig)
            server.addContainer(childContainer)
            server.mapConfigletToContainer(childContainer, childConfig)
            containerList[childContainer.name] = childContainer

    print 're-inserting same containers'
    for i in range(0, 5):
        container = cvp.Container('parentContainer-%d' % i,
                                  currRootContainerInfo.name)
        try:
            server.addContainer(container)
        except cvpServices.CvpError as err:
            if err.errorCode == errorCodes.DATA_ALREADY_EXISTS:
                pass
            else:
                raise

        for j in range(0, 3):
            childContainer = cvp.Container(
                'parentContainer%dchildContainer-%d' % (i, j),
                'parentContainer-%d' % i)
            try:
                server.addContainer(childContainer)
            except cvpServices.CvpError as err:
                if err.errorCode == errorCodes.DATA_ALREADY_EXISTS:
                    pass
                else:
                    raise

    # read them all back and verify
    print 'verifying all the containers'
    containers = server.getContainers()
    for container in containers:
        if container.name == currRootContainerInfo.name:
            continue
        if container.name in containerList:
            assert container.parentName == containerList[
                container.name].parentName
            assert container.configlets == containerList[
                container.name].configlets
        else:
            raise KeyError

    # remove all the containers
    print 'removing all the containers'
    for container in containers:
        if container.name != currRootContainerInfo.name:
            server.deleteContainer(container)

    configs = server.getConfiglets()
    for config in configs:
        server.deleteConfiglet(config)