当前位置: 首页>>代码示例>>Python>>正文


Python Container.getContainer方法代码示例

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


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

示例1: get_ipcontainer

# 需要导入模块: from net.es.netshell.api import Container [as 别名]
# 或者: from net.es.netshell.api.Container import getContainer [as 别名]
 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,代码行数:9,代码来源:tbip.py

示例2: settopos

# 需要导入模块: from net.es.netshell.api import Container [as 别名]
# 或者: from net.es.netshell.api.Container import getContainer [as 别名]
 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,代码行数:10,代码来源:vpn.py

示例3: getResource

# 需要导入模块: from net.es.netshell.api import Container [as 别名]
# 或者: from net.es.netshell.api.Container import getContainer [as 别名]
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,代码行数:10,代码来源:resource.py

示例4: createlink

# 需要导入模块: from net.es.netshell.api import Container [as 别名]
# 或者: from net.es.netshell.api.Container import getContainer [as 别名]
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,代码行数:59,代码来源:tbctl.py

示例5: loadService

# 需要导入模块: from net.es.netshell.api import Container [as 别名]
# 或者: from net.es.netshell.api.Container import getContainer [as 别名]
 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,代码行数:17,代码来源:vpn.py

示例6: addDataPlaneIP

# 需要导入模块: from net.es.netshell.api import Container [as 别名]
# 或者: from net.es.netshell.api.Container import getContainer [as 别名]
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,代码行数:32,代码来源:tbhost.py

示例7: stoplxc

# 需要导入模块: from net.es.netshell.api import Container [as 别名]
# 或者: from net.es.netshell.api.Container import getContainer [as 别名]
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,代码行数:36,代码来源:tbhost.py

示例8: localCreate

# 需要导入模块: from net.es.netshell.api import Container [as 别名]
# 或者: from net.es.netshell.api.Container import getContainer [as 别名]
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,代码行数:34,代码来源:ovsctl.py

示例9: createcorelinks

# 需要导入模块: from net.es.netshell.api import Container [as 别名]
# 或者: from net.es.netshell.api.Container import getContainer [as 别名]
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,代码行数:32,代码来源:tbctl.py

示例10: dellink

# 需要导入模块: from net.es.netshell.api import Container [as 别名]
# 或者: from net.es.netshell.api.Container import getContainer [as 别名]
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,代码行数:9,代码来源:topoctl.py

示例11: listostemplates

# 需要导入模块: from net.es.netshell.api import Container [as 别名]
# 或者: from net.es.netshell.api.Container import getContainer [as 别名]
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,代码行数:10,代码来源:proxmoxutil.py

示例12: listhypervisors

# 需要导入模块: from net.es.netshell.api import Container [as 别名]
# 或者: from net.es.netshell.api.Container import getContainer [as 别名]
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,代码行数:10,代码来源:proxmoxutil.py

示例13: addnode

# 需要导入模块: from net.es.netshell.api import Container [as 别名]
# 或者: from net.es.netshell.api.Container import getContainer [as 别名]
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,代码行数:11,代码来源:topoctl.py

示例14: removehost

# 需要导入模块: from net.es.netshell.api import Container [as 别名]
# 或者: from net.es.netshell.api.Container import getContainer [as 别名]
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,代码行数:12,代码来源:tbhost.py

示例15: remove

# 需要导入模块: from net.es.netshell.api import Container [as 别名]
# 或者: from net.es.netshell.api.Container import getContainer [as 别名]
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,代码行数:12,代码来源:idmanager.py


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