• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python api.Container类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中net.es.netshell.api.Container的典型用法代码示例。如果您正苦于以下问题:Python Container类的具体用法?Python Container怎么用?Python Container使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Container类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: get_ipcontainer

 def get_ipcontainer():
     """ This method returns the IP container used to store IP address in persistent storage"""
     container = Container.getContainer(IPManagement.IPCONTAINER) 
     if container is None:
         Container.createContainer(IPManagement.IPCONTAINER)
         container = Container.getContainer(IPManagement.IPCONTAINER)
     return container
开发者ID:esnet,项目名称:enos,代码行数:7,代码来源:tbip.py


示例2: vcendpoints

def vcendpoints(vc):
    """
    Given a Link object representing a virtual circuit, return the parsed endpoints.
    This is roughly analogus to griendpoints for OSCARS.
    :param vc: Link (Resource) object
    :return: array of array of (domain, node name, port name, vlan)
    """
    srcportanchor = vc.properties['SrcPort']
    dstportanchor = vc.properties['DstPort']

    srcport = Container.fromAnchor(srcportanchor)
    dstport = Container.fromAnchor(dstportanchor)

    srcnode = Container.fromAnchor(srcport.properties['Node'])
    dstnode = Container.fromAnchor(dstport.properties['Node'])

    srcendpoint = (str(srcnode.properties['Domain']),
                   str(srcport.properties['Node']['resourceName']),
                   str(srcport.resourceName.split("--")[1]),
                   str(srcport.properties['VLAN']))
    dstendpoint = (str(dstnode.properties['Domain']),
                   str(dstport.properties['Node']['resourceName']),
                   str(dstport.resourceName.split("--")[1]),
                   str(dstport.properties['VLAN']))
    return (srcendpoint, dstendpoint)
开发者ID:esnet,项目名称:enos,代码行数:25,代码来源:vc.py


示例3: getResource

def getResource(containerName,resourceName,owner=None):
    container = None
    if owner != None:
        container = Container.getContainer(owner,containerName)
    else:
        container = Container.getContainer(containerName)
    resource = container.loadResource(resourceName)
    return resource
开发者ID:esnet,项目名称:enos,代码行数:8,代码来源:resource.py


示例4: settopos

 def settopos(self, popstoponame, coretoponame):
     self.properties['topology'] = popstoponame
     self.topology = Container.getContainer(self.properties['topology'])
     self.properties['coretopology'] = coretoponame
     self.coretopology = Container.getContainer(self.properties['coretopology'])
     # We can now set up the callback
     self.setscc()
     self.saveService()
开发者ID:esnet,项目名称:enos,代码行数:8,代码来源:vpn.py


示例5: createlink

def createlink (topo,srcpop,dstpop,vlanbase,maxiter):
    srcanchor = srcpop.properties[CoreRouter]
    srcnode = Container.fromAnchor(srcanchor)
    dstanchor = dstpop.properties[CoreRouter]
    dstnode = Container.fromAnchor(dstpop.properties[CoreRouter])
    toposrcnode = topo.loadResource(srcnode.getResourceName())
    if toposrcnode == None:
        # Does not exists yet, create it
        toposrcnode = addnode(topo.getResourceName(),srcnode.getResourceName())
        container = Container.getContainer(srcanchor['containerOwner'],srcanchor['containerName'])
        toposrcnode.setParentResourceAnchor(container.getResourceAnchor(srcnode))
        topo.saveResource(toposrcnode)
    topodstnode = topo.loadResource(dstnode.getResourceName())
    if topodstnode == None:
        # Does not exists yet, create it
        topodstnode = addnode(topo.getResourceName(),dstnode.getResourceName())
        container = Container.getContainer(dstanchor['containerOwner'],dstanchor['containerName'])
        topodstnode.setParentResourceAnchor(container.getResourceAnchor(dstnode))
        topo.saveResource(topodstnode)
    srcports = srcnode.properties[PortsKey]
    srcpop.properties['counter'] += 1
    dstpop.properties['counter'] += 1
    srcportindex = srcpop.properties['counter'] % len(srcports)
    dstports = dstnode.properties[PortsKey]
    dstportindex = dstpop.properties['counter'] % len(dstports)
    vlan = vlanbase
    while maxiter > 0:
        if reduce(lambda x,y: x and y,
                  map (lambda x :not vlan in x,
                       [srcpop.properties['vlanmap'],dstpop.properties['vlanmap']])):
            # VLAN is available in both ports
            srcport = srcports.keys()[srcportindex]
            dstport = dstports.keys()[dstportindex]
            srcpop.properties['vlanmap'].append(vlan)
            dstpop.properties['vlanmap'].append(vlan)

            link = addlink(topology=topo.getResourceName(),
                           linkname=srcpop.getResourceName()+"--"+dstpop.getResourceName(),
                           srcnodename=srcnode.getResourceName(),
                           srcportname=srcport,
                           dstnodename=dstnode.getResourceName(),
                           dstportname=dstport,
                           srcvlan=vlan,
                           dstvlan=vlan)
            rlink= addlink(topology=topo.getResourceName(),
                           linkname=dstpop.getResourceName()+"--"+srcpop.getResourceName(),
                           srcnodename=dstnode.getResourceName(),
                           srcportname=dstport,
                           dstnodename=srcnode.getResourceName(),
                           dstportname=srcport,
                           srcvlan=vlan,
                           dstvlan=vlan)

            return (link,rlink)
        vlan += 1
        maxiter -= 1
    return None
开发者ID:esnet,项目名称:enos,代码行数:57,代码来源:tbctl.py


示例6: loadService

 def loadService(self):
     stored = Container.getContainer(self.getResourceName())
     mapResource (obj=self,resource=stored)
     if 'topology' in self.properties:
         self.topology = Container.getContainer(self.properties['topology'])
     if 'coretopology' in self.properties:
         self.coretopology = Container.getContainer(self.properties['coretopology'])
     vpns = self.loadResources({"resourceType":"VPN"})
     for v in vpns:
         vpn = VPN(v.getResourceName())
         vpn.loadVPN(self)
         self.vpnIndex[v.getResourceName()] = vpn
         self.vpnIndexById[vpn.vid] = vpn
     if not 'mat' in self.properties:
         self.properties['mat'] = True
开发者ID:esnet,项目名称:enos,代码行数:15,代码来源:vpn.py


示例7: dellink

def dellink(topology,linkname,srcnodename,dstnodename,both=False):
    container = Container.getContainer(topology)
    if container == None:
        print topology,"does not exist."
        return False
    print "not yet implemented"
    return False
开发者ID:esnet,项目名称:enos,代码行数:7,代码来源:topoctl.py


示例8: createcorelinks

def createcorelinks(containername,popsname,vlanbase=defaultvlanbase,maxiter=defaultvlaniter):
    pops = Container.getContainer(popsname)
    links = createtopo(containername)
    popsmap={}
    for (src,dst) in poptopology:
        if (not src in popsmap):
            pop = pops.loadResource(src)
            if pop == None:
                print "cannot find " + src + " in " + containername
                return None
            pop.properties['counter'] = 0
            pop.properties['vlanmap'] = []
            popsmap[src] = pop
        if (not dst in popsmap):
            pop = pops.loadResource(dst)
            if pop == None:
                print "cannot find " + src + " in " + containername
                return None
            pop.properties['counter'] = 0
            popsmap[dst] = pop
            pop.properties['vlanmap'] = []
        srcpop = popsmap.get(src)
        dstpop = popsmap.get(dst)
        (link ,rlink)= createlink(links,srcpop,dstpop,vlanbase,maxiter)
        if link == None:
            print "cannot create " + srcpop + " to " + dstpop
        if rlink == None:
            print "cannot create " + dstpop + " to " + srcpop
        printLink(links,link)
        printLink(links,rlink)
开发者ID:esnet,项目名称:enos,代码行数:30,代码来源:tbctl.py


示例9: addDataPlaneIP

def addDataPlaneIP(host, interface, vlan):
    """ Creates data plane ip from host id, project and adds it to host template"""
    container = Container.getContainer(HOST_CONTAINER)

    if exists(host):
        hostresource = container.loadResource(host)
        if interface in hostresource.properties:
            raise ValueError("Interface is already configured")

        hostid = hostresource.properties[HOSTID]
        projectid = int(hostresource.properties[PROJECT])
        dpip=""
    
        if(vlan == DATAPLANE_VLAN4012):
            ifaceid = interface.strip(string.ascii_letters)
            interface_number = ifaceid.split(".")[0]
            dpip = DATAPLANE_PREFIX+str(interface_number)+"."+str(projectid)+"."+str(hostid)
        elif (vlan == DATAPLANE_VLAN4020):
            ifaceid = interface.strip(string.ascii_letters)
            interface_number = int(ifaceid.split(".")[0])
            projectid += 100 #add 100 to project-id for vlan 4020
            dpip = DATAPLANE_PREFIX+str(interface_number)+"."+str(projectid)+"."+str(hostid)

        netmask = str(CONTROLPLANE_NETMASK)
        dpip = dpip + "/" + netmask

        return addIP(host, interface, dpip, vlan)

    else:
        raise ValueError("Host does not exist. Please create template first")
开发者ID:esnet,项目名称:enos,代码行数:30,代码来源:tbhost.py


示例10: stoplxc

def stoplxc(host):
    """ Stop lxc in proxmox using given hostresource configuration """
    
    #check if container is running and ask user to stop it
    if not exists(host):
    	raise ValueError("Host template is missing. Please create host template")
    
    container = Container.getContainer(HOST_CONTAINER)
    hostresource = container.loadResource(host)
        #get proxmox user and hypervisor 
    userresource = proxmoxutil.listuser()
    if userresource is None:
    	raise ValueError("No proxmox user found!! Please use proxmoxutil command to update user credentials")
    		
    user = userresource.properties[PROPERTIES_USER]
    password = userresource.properties[PROPERTIES_PASSWORD]
    authrealm = userresource.properties[PROPERTIES_AUTHREALM]
    puser = user+'@'+authrealm
    	  	
    primary = proxmoxutil.listprimary()
    		
    if primary is None:
    	raise ValueError("Primary proxmox hypervisor not found!! Please use proxmoxutil command to update primary hypervisor")
    	
    hypervisor = primary.properties[PROPERTIES_HYPERVISOR]
    print "Authenticating "+puser +" on "+ hypervisor
  
    proxmox = ProxmoxAPI(hypervisor, user=puser, password=password, verify_ssl=False)
    node = proxmox.nodes(hostresource.properties[HYPERVISOR])
    vmid = int(hostresource.properties[HOSTID])
    print "Stopping  container"
    node.lxc(vmid).status.stop.post()
    time.sleep(30)
    print "Stopped  container"
开发者ID:esnet,项目名称:enos,代码行数:34,代码来源:tbhost.py


示例11: localCreate

def localCreate(name, ctrl=None,dpid=None, config=None):
    if exists(name):
        return(None,"Switch's name already exist")
    res = ovsctl(['add-br',name])
    if not res:
        return (None,"Cannot create OVS swtch")
    switch = UserSwitch(name=name)
    if ctrl != None:
        if dpid == None:
            dpid = newDPID(name)
        # set openflow
        res = ovsctl(['set-fail-mode',name,'secure'])
        if not res:
            return (switch,"Cannot set set-fail-mode")
        # set DPID
        res = ovsctl(['set','bridge',name,"other-config:datapath-id="+dpid])
        if not res:
            return (switch,"Cannot set DPID")
        switch.properties['dpid'] = dpid
        # set controller
        if not ':' in ctrl:
            ctrl += ":6633"
        ctrl = "tcp:" + ctrl
        res = ovsctl(['set-controller',name,ctrl])
        if not res:
            return (switch,"Cannot set controller")
        switch.properties['controller'] = ctrl
    interface = newInterface(name=name,ctrl=ctrl,dpid=dpid)
    addConfig(interfaces={name:interface},config=config)
    container = Container.getContainer(getContinerName())
    container.saveResource(switch)
    return (switch,None)
开发者ID:esnet,项目名称:enos,代码行数:32,代码来源:ovsctl.py


示例12: listhypervisors

def listhypervisors():
    """ This method returns primary hypervisor """
    container = Container.getContainer(PROXMOX_CONTAINER)
    query={}
    key=PROPERTIES+"."+PROPERTIES_TYPE
    query[key] = HYPERVISORRESOURCE
    hypervisors = container.loadResources(query)
    return hypervisors
开发者ID:esnet,项目名称:enos,代码行数:8,代码来源:proxmoxutil.py


示例13: listostemplates

def listostemplates():
    """ This methodreturns a list of templates """
    container = Container.getContainer(PROXMOX_CONTAINER)
    query={}
    key=PROPERTIES+"."+PROPERTIES_TYPE
    query[key] = PROPERTIES_OS
    templates = container.loadResources(query)
    return templates
开发者ID:esnet,项目名称:enos,代码行数:8,代码来源:proxmoxutil.py


示例14: addnode

def addnode(topology,nodename):
    container = Container.getContainer(topology)
    if container == None:
        print topology,"does not exist."
        return None
    node = Node(nodename)
    node.properties[PortsKey] = {}
    container.saveResource(node)
    return node
开发者ID:esnet,项目名称:enos,代码行数:9,代码来源:topoctl.py


示例15: addstorage

def addstorage(host, size):
    """ Adds storage to host template"""
    container = Container.getContainer(HOST_CONTAINER)
    if exists(host):
    	hostresource = container.loadResource(host)
    	hostresource.properties[PROPERTIES_DISK] = size
    	container.saveResource(hostresource)
    	return hostresource
    else:
        raise ValueError("Host does not exist. Please create template first")
开发者ID:esnet,项目名称:enos,代码行数:10,代码来源:tbhost.py


示例16: removehost

def removehost(host):
	if exists(host):
		container = Container.getContainer(HOST_CONTAINER)
		hostresource = container.loadResource(host)
		hostid = str(hostresource.properties[HOSTID])
		idmanager.remove(hostid)	
		container.deleteResource(host)
		print "Removed host"
	else:
		print "Host not found"
开发者ID:esnet,项目名称:enos,代码行数:10,代码来源:tbhost.py


示例17: remove

def remove(hostid):
    """ This method removes the ID resource from persistent storage"""
    
    hid = int(hostid)

    if exists(hostid):
        container = Container.getContainer(ID_CONTAINER)
        container.deleteResource(hostid)
    else:
        raise ValueError("Id resource does not exist")
开发者ID:esnet,项目名称:enos,代码行数:10,代码来源:idmanager.py


示例18: removeostemplate

def removeostemplate(os):
    """ This method removes the template"""
    if(os != None ):
    	container = Container.getContainer(PROXMOX_CONTAINER)
        if(container.loadResource(os)):
            container.deleteResource(os)
        else:
            raise ValueError("Attempting to delete nonexistent Hypervisor")
    else:
        raise TypeError("OS cannot be None Type")
开发者ID:esnet,项目名称:enos,代码行数:10,代码来源:proxmoxutil.py


示例19: localDelete

def localDelete(name,config=None):
    if not exists(name):
        return(False,"Switch does not exist")
    res = ovsctl(['del-br',name])
    if not res:
        return (False,"Cannot delete OVS swtch")
    deleteFromConfig(nameconfig=config)
    container = Container.getContainer(getContinerName())
    container.deleteResource(name)
    return(True,None)
开发者ID:esnet,项目名称:enos,代码行数:10,代码来源:ovsctl.py


示例20: createpops

def createpops(popsname,inv):
    inventory = Container.getContainer(inv)
    pops = createtopo(popsname)
    pops.properties[Pops] = {}
    for (popname,hwname,coreroutername,swname,links) in testbedPops.values():
        pop = Resource(popname)
        hwswitch = addnode(popsname,hwname)
        swswitch = addnode(popsname,swname)
        corerouter = addnode(popsname,coreroutername)
        hwswitch.setParentResourceAnchor(inventory.getResourceAnchor(hwname))
        swswitch.setParentResourceAnchor(inventory.getResourceAnchor(swname))
        corerouter.setParentResourceAnchor(inventory.getResourceAnchor(coreroutername))
        copyswitchprops(hwswitch, inventory, hwname)
        copyswitchprops(swswitch, inventory, swname)
        copyswitchprops(corerouter, inventory, coreroutername)
        pops.saveResource(hwswitch)
        pops.saveResource(swswitch)
        pops.saveResource(corerouter)
        pop.properties[HwSwitch] = pops.getResourceAnchor(hwswitch)
        pop.properties[SwSwitch] = pops.getResourceAnchor(swswitch)
        pop.properties[CoreRouter] = pops.getResourceAnchor(corerouter)
        # Find and add the POP testbed host
        for tbn in tbns.values():
            if tbn['pop'] == popname:
                host = addnode(popsname,tbn['name'])
                host.setParentResourceAnchor(inventory.getResourceAnchor(tbn['name']))
                copyswitchprops(host, inventory, tbn['name'])
                host.properties[Role] = Host
                pops.saveResource(host)
        for (srcnodename,srcportname,dstnodename,dstportname) in links:
            linkname = Link.buildName(srcnodename,srcportname,dstnodename,dstportname)
            invlink = inventory.loadResource(linkname)
            if invlink == None:
                print "Cannot find link in inventory: ",linkname
                return
            link = addlink(topology=popsname,
                           linkname=linkname,
                           srcnodename=srcnodename,
                           srcportname=srcportname,
                           dstnodename=dstnodename,
                           dstportname=dstportname)
            if link == None:
                print "Could not add link " + linkname
            link.setParentResourceAnchor(inventory.getResourceAnchor(invlink))
            pops.saveResource(link)
            # Reverse link
            linkname = Link.buildName(dstnodename,dstportname,srcnodename,srcportname)
            invlink = inventory.loadResource(linkname)
            if invlink == None:
                print "Cannot find reverse link in inventory: ",linkname
                continue
        pops.saveResource(pop)
        pops.properties[Pops][popname] = pops.getResourceAnchor(pop)
    pops.save()
    return pops
开发者ID:esnet,项目名称:enos,代码行数:55,代码来源:tbctl.py



注:本文中的net.es.netshell.api.Container类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python http.HTTPPluginControl类代码示例发布时间:2022-05-27
下一篇:
Python logger.info函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap