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


Python api.Container类代码示例

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


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


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