Exemplo n.º 1
1
Arquivo: tbhost.py Projeto: esnet/enos
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"
Exemplo n.º 2
0
Arquivo: tbip.py Projeto: esnet/enos
 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
Exemplo n.º 3
0
Arquivo: vc.py Projeto: esnet/enos
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)
Exemplo n.º 4
0
Arquivo: vc.py Projeto: cygmris/enos
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)
Exemplo n.º 5
0
 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
Exemplo n.º 6
0
def connecthostbroadcast(localpop,
                         hwport_tosite,
                         sitevlan,
                         meter=3,
                         broadcast_rewritemac=None):
    """
    Create entries on the local hardware switch that pass broadcast traffic
    to and from the connected host
    :param localpop: POP object
    :param hwport_tosite: port on hardware switch facing the site (string)
    :param sitevlan: VLAN number of site attachment
    :param meter:
    :param broadcast_rewritemac: Mapped Ethernet broadcast address
    :return:
    """

    hwswitch = Container.fromAnchor(localpop.properties['HwSwitch'])
    hwswitchname = hwswitch.resourceName
    swswitch = Container.fromAnchor(localpop.properties['SwSwitch'])
    swswitchname = swswitch.resourceName
    topology = Container.getContainer(
        localpop.properties['SwSwitch']['containerName'])

    # Find the port on the HwSwitch connected to the software switch
    links = getlinks2(topology, hwswitchname, swswitchname)
    if links == None or len(links) == 0:
        print "No links from", hwswitchname, "to", swswitchname
        return False
    hwport_tosw = None
    for link in links:
        (node, port) = linkednode2(link, swswitchname)
        if port != None:
            # Found the link we're looking for
            hwport_tosw = port
            break

    broadcast = "FF:FF:FF:FF:FF:FF"
    translated_broadcast = broadcast
    if broadcast_rewritemac != None:
        translated_broadcast = broadcast_rewritemac

    fh1 = SCC.SdnInstallForward1(javaByteArray2(hwswitch.properties['DPID']),
                                 1, BigInteger.ZERO, str(hwport_tosw),
                                 int(sitevlan), "00:00:00:00:00:00",
                                 translated_broadcast, str(hwport_tosite),
                                 int(sitevlan), broadcast, 0, 0, meter)
    if fh1 == None:
        return None

    fh2 = SCC.SdnInstallForward1(javaByteArray2(hwswitch.properties['DPID']),
                                 1, BigInteger.ZERO, str(hwport_tosite),
                                 int(sitevlan), "00:00:00:00:00:00", broadcast,
                                 str(hwport_tosw), int(sitevlan),
                                 translated_broadcast, 0, 0, meter)
    if fh2 == None:
        SCC.deleteforward(fh1)
        return None

    return (fh1, fh2)
Exemplo n.º 7
0
Arquivo: vpn.py Projeto: esnet/enos
 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()
Exemplo n.º 8
0
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
Exemplo n.º 9
0
Arquivo: tbctl.py Projeto: esnet/enos
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
Exemplo n.º 10
0
Arquivo: vpn.py Projeto: cygmris/enos
 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()
Exemplo n.º 11
0
def connectentryfanoutmac(localpop, hostmac, hostvlan, forwards, meter, mac):
    """
    Create fanout entry on source POP's software switch
    :param localpop:  POP object
    :param hostmac: host MAC address
    :param hostvlan: VLAN number of host attachment
    :param forwards: array of SDNControllerClientL2Forward
    :param meter:
    :param mac:
    :return: SdnControllerClientFlowHandle
    """
    hwswitch = Container.fromAnchor(localpop.properties['HwSwitch'])
    hwswitchname = hwswitch.resourceName
    swswitch = Container.fromAnchor(localpop.properties['SwSwitch'])
    swswitchname = swswitch.resourceName
    topology = Container.getContainer(
        localpop.properties['SwSwitch']['containerName'])

    # print "connectentryfanout localpop", localpop, "host", host, "hostvlan", hostvlan, "mac", mac

    # Find the port on the software switch connected to the hardware switch
    links = getlinks2(topology, swswitchname, hwswitchname)
    if links == None or len(links) == 0:
        print "No links from", swswitchname, "to", hwswitchname
        return None
    hwswitchlink = None
    swport_tohw = None
    for link in links:
        (node, port) = linkednode2(link, hwswitchname)
        if port != None:
            # Found it!
            hwswitchlink = link
            swport_tohw = port
            break
    if swport_tohw == None:
        print "No output port on", swswitchname, "facing", hwswitchname
        return None

    # The fanout flow is "interesting" in that the input plus the multiple outputs
    # all are on the same port (but different VLANs).  Fill in the outputs.
    for f in forwards:
        f.outPort = str(swport_tohw)
        # print "FORW:  outport", f.outPort, "vlan", f.vlan, "dstMac", f.dstMac

    # Convert the list of forwarding destinations to a Java array.
    fwdsarr = jarray.array(forwards, SdnControllerClientL2Forward)

    # print "dpid", swswitch.props['dpid']
    # This flow being installed is unusual in that it does a source MAC address
    # filter as well
    fh = SCC.SdnInstallForward(javaByteArray2(swswitch.properties['DPID']),
                               1, BigInteger.ZERO, str(swport_tohw),
                               int(hostvlan), hostmac, mac, fwdsarr, 0, 0,
                               meter)

    return fh
Exemplo n.º 12
0
def connectexitfanout(localpop, corevlan, forwards, meter, mac):
    """
    Create exit fanout flow on software switch of a destination POP.
    This handles broadcast traffic before it exits the network
    :param localpop: POP object
    :param corevlan: VLAN number coming from core
    :param forwards: array of SDNControllerClientL2Forward
    :param meter:
    :param mac:
    :return: SDNControllerClientFlowHandle
    """

    hwswitch = Container.fromAnchor(localpop.properties['HwSwitch'])
    hwswitchname = hwswitch.resourceName
    swswitch = Container.fromAnchor(localpop.properties['SwSwitch'])
    swswitchname = swswitch.resourceName
    topology = Container.getContainer(
        localpop.properties['SwSwitch']['containerName'])

    # print "connectexitfanout localpop", localpop, "corevlan", corevlan, "mac", mac

    # Find the port on the software switch connected to the hardware switch
    links = getlinks2(topology, swswitchname, hwswitchname)
    if links == None or len(links) == 0:
        print "No links from", swswitchname, "to", hwswitchname
        return None
    hwswitchlink = None
    swport_tohw = None
    for link in links:
        (node, port) = linkednode2(link, hwswitchname)
        if port != None:
            # Found it!
            hwswitchlink = link
            swport_tohw = port
            break
    if swport_tohw == None:
        print "No output port on", swswitchname, "facing", hwswitchname
        return None

    for f in forwards:
        f.outPort = str(swport_tohw)
        # print "FORW:  outport", f.outPort, "vlan", f.vlan, "dstMac", f.dstMac

    # Convert the list of forwarding destinations to a Java array.
    fwdsarr = jarray.array(forwards, SdnControllerClientL2Forward)

    # print "dpid", swswitch.props['dpid']
    fh = SCC.SdnInstallForward(javaByteArray2(swswitch.properties['DPID']),
                               1, BigInteger.ZERO, str(swport_tohw),
                               int(corevlan), None, mac, fwdsarr, 0, 0, meter)

    return fh
Exemplo n.º 13
0
Arquivo: vpn.py Projeto: esnet/enos
 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
Exemplo n.º 14
0
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
Exemplo n.º 15
0
Arquivo: tbctl.py Projeto: esnet/enos
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)
Exemplo n.º 16
0
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)
Exemplo n.º 17
0
def loadSlices():
    multiplexerSlices = globals()['multiplexerSlices']
    slices = Container.getContainer(Slices)
    allocatedSlices = slices.loadResources(
        {"resourceType": ResourceTypes.SLICE})
    for slice in allocatedSlices:
        multiplexerSlices[slice.getResourceName()] = slice
Exemplo n.º 18
0
Arquivo: vpn.py Projeto: cygmris/enos
 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
Exemplo n.º 19
0
Arquivo: tbhost.py Projeto: esnet/enos
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")
Exemplo n.º 20
0
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
Exemplo n.º 21
0
def addlink(topology,
            linkname,
            srcnodename,
            dstnodename,
            srcportname,
            dstportname,
            srcvlan=0,
            dstvlan=0):

    container = None
    if isinstance(topology, Container):
        container = topology
    else:
        container = Container.getContainer(topology)
    if container == None:
        print "topology ", topology, " does not exist."
        return None
    srcnode = container.loadResource(srcnodename)
    if srcnode == None:
        print "src node ", srcnodename, " does not exist"
        return None
    dstnode = container.loadResource(dstnodename)
    if dstnode == None:
        print "dst node ", dstnodename, " does not exist"
        return None
    link = Link(linkname)
    srcport = container.loadResource(
        toPortResourceName(srcnodename, srcportname, srcvlan))
    if srcport == None:
        srcport = Port(toPortResourceName(srcnodename, srcportname, srcvlan))
        srcnode.properties[PortsKey][srcportname] = {}
        srcport.properties[LinksKey] = {}
        srcport.properties[VlanKey] = srcvlan
        srcport.properties[NodeKey] = container.getResourceAnchor(srcnode)
        container.saveResource(srcport)
    srcnode.properties[PortsKey][srcportname] = container.getResourceAnchor(
        srcport)
    srcport.properties[LinksKey][linkname] = container.getResourceAnchor(link)
    dstport = container.loadResource(
        toPortResourceName(dstnodename, dstportname, dstvlan))
    if dstport == None:
        dstport = Port(toPortResourceName(dstnodename, dstportname, dstvlan))
        dstnode.properties[PortsKey][dstportname] = {}
        dstport.properties[LinksKey] = {}
        dstport.properties[NodeKey] = container.getResourceAnchor(dstnode)
        dstport.properties[VlanKey] = dstvlan
        container.saveResource(dstport)
    dstnode.properties[PortsKey][dstportname] = container.getResourceAnchor(
        dstport)
    dstport.properties[LinksKey][linkname] = container.getResourceAnchor(link)
    link.properties[SrcPortKey] = container.getResourceAnchor(srcport)
    link.properties[DstPortKey] = container.getResourceAnchor(dstport)
    link.setWeight(1)  # default
    container.saveResource(link)
    container.saveResource(srcport)
    container.saveResource(dstport)
    container.saveResource(srcnode)
    container.saveResource(dstnode)
    return link
Exemplo n.º 22
0
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
Exemplo n.º 23
0
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
Exemplo n.º 24
0
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
Exemplo n.º 25
0
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
Exemplo n.º 26
0
Arquivo: vpn.py Projeto: cygmris/enos
    def addpop(self, pop):
        rc = True
        # See if we've already added the POP
        if pop.resourceName in self.pops:
            return False

        with self.lock:

            fhlist = []  # List of FlowHandles for this POP

            # We need to make sure that meter(s) are set correctly on the switches in the POP.
            # In particular we need to do this on Corsas before pushing flows to it that reference
            # any of the meters we use here.  This code is a bit of a hard-coded hack, but it'll
            # have to do until we can figure out what's the desired behavior.  Note that we can
            # set a meter multiple times.  It is however a requirement that the driver needs to
            # have a set a meter before a flow references it; in particular we cannot use an
            # external mechanism (e.g. CLI) to set the meter and then try to have the driver
            # push a flow that references it.
            sw = Container.fromAnchor(pop.properties['HwSwitch'])
            meter = self.meter
            rc = setmeter(sw, meter, 0, 0, 0, 0)
            # if not rc:

            # Iterate over the existing POPs to set up entries to handle broadcast traffic
            # between the POP being added and the existing POPs.  These all go in the
            # hardware switches.
            broadcastmac = "FF:FF:FF:FF:FF:FF"
            broadcastmac_mat = broadcastmac
            if MultiPointVPNServiceFactory.getVpnService().properties['mat']:
                broadcastmac_mat = self.generateBroadcastMAC()
            for (remotepopname, remotepop) in self.pops.items():
                vc = self.interconnectpops(pop.getResourceName(),
                                           remotepop.getResourceName())
                fhs = swconnect(pop, remotepop, broadcastmac_mat, vc,
                                self.meter)
                self.popflows[remotepop.getResourceName()].extend(fhs)
                fhlist.extend(fhs)

            # This POP is now added.
            self.pops[pop.resourceName] = pop
            self.popflows[pop.resourceName] = fhlist

            # Regenerate entry fanout flows for various hosts because they need to learn
            # about a new POP
            for (hostmac, hostsitename) in self.hostsites.items():
                hostsite = self.vpnsites[hostsitename]
                hostvlan = self.vpnsitevlans[hostsitename]
                localpop = self.pops[hostsite['pop']]
                fh = self.makeentryfanoutflows(localpop=localpop,
                                               hostmac=hostmac,
                                               hostvlan=hostvlan,
                                               hostsite=hostsite)
                if fh != None:
                    self.hostflows[hostmac].append(fh)

            # print "addpop ending with pop flow handles", self.popflows[pop.name]

        return rc
Exemplo n.º 27
0
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
Exemplo n.º 28
0
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
Exemplo n.º 29
0
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")
Exemplo n.º 30
0
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)
Exemplo n.º 31
0
Arquivo: tbhost.py Projeto: esnet/enos
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")
Exemplo n.º 32
0
Arquivo: tbhost.py Projeto: esnet/enos
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"
Exemplo n.º 33
0
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")
Exemplo n.º 34
0
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")
Exemplo n.º 35
0
Arquivo: tbctl.py Projeto: esnet/enos
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
Exemplo n.º 36
0
def exists(hostid):
    """ This method checks if the ID resource exists in persistent storage"""
    
    hid = int(hostid)
    container = Container.getContainer(ID_CONTAINER)
    idexists = container.loadResource(hostid)

    if idexists != None:
        return True
    else:
        return False
Exemplo n.º 37
0
def deleteSlice(id):
    id = str(id)
    multiplexerSlices = globals()['multiplexerSlices']
    slicerLock = globals()['slicerLock']
    with slicerLock:
        if id in multiplexerSlices:
            slices = Container.getContainer(Slices)
            slices.deleteResource(id)
            del multiplexerSlices[id]
        else:
            print "slice ",id," does not exist"
Exemplo n.º 38
0
def deleteSlice(id):
    id = str(id)
    multiplexerSlices = globals()['multiplexerSlices']
    slicerLock = globals()['slicerLock']
    with slicerLock:
        if id in multiplexerSlices:
            slices = Container.getContainer(Slices)
            slices.deleteResource(id)
            del multiplexerSlices[id]
        else:
            print "slice ", id, " does not exist"
Exemplo n.º 39
0
def delnode(topology,nodename):
    container = Container.getContainer(topology)
    if container == None:
        print topology,"does not exist."
        return False
    node = container.loadResource(nodename)
    if node == None:
        print nodename,"does not exist"
        return False
    node.delete(container)
    return True
Exemplo n.º 40
0
def delnode(topology, nodename):
    container = Container.getContainer(topology)
    if container == None:
        print topology, "does not exist."
        return False
    node = container.loadResource(nodename)
    if node == None:
        print nodename, "does not exist"
        return False
    node.delete(container)
    return True
Exemplo n.º 41
0
def addostemplate(os, ostemplate):
    """ This method adds ostemplate file location to the database """
    if(ostemplate != None):
        container = Container.getContainer(PROXMOX_CONTAINER)
        osresource = Resource(os)
        osresource.properties[PROPERTIES_TYPE] = PROPERTIES_OS
        osresource.properties[PROPERTIES_OS] = os
        osresource.properties[PROPERTIES_OSTEMPLATE] = ostemplate
        container.deleteResource(os)
        container.saveResource(osresource)
    else:
        raise TypeError("ostemplate is null")
Exemplo n.º 42
0
def addostemplate(os, ostemplate):
    """ This method adds ostemplate file location to the database """
    if (ostemplate != None):
        container = Container.getContainer(PROXMOX_CONTAINER)
        osresource = Resource(os)
        osresource.properties[PROPERTIES_TYPE] = PROPERTIES_OS
        osresource.properties[PROPERTIES_OS] = os
        osresource.properties[PROPERTIES_OSTEMPLATE] = ostemplate
        container.deleteResource(os)
        container.saveResource(osresource)
    else:
        raise TypeError("ostemplate is null")
Exemplo n.º 43
0
Arquivo: vpn.py Projeto: esnet/enos
    def addpop(self,pop):
        rc = True
        # See if we've already added the POP
        if pop.resourceName in self.pops:
            return False

        with self.lock:

            fhlist = [] # List of FlowHandles for this POP

            # We need to make sure that meter(s) are set correctly on the switches in the POP.
            # In particular we need to do this on Corsas before pushing flows to it that reference
            # any of the meters we use here.  This code is a bit of a hard-coded hack, but it'll
            # have to do until we can figure out what's the desired behavior.  Note that we can
            # set a meter multiple times.  It is however a requirement that the driver needs to
            # have a set a meter before a flow references it; in particular we cannot use an
            # external mechanism (e.g. CLI) to set the meter and then try to have the driver
            # push a flow that references it.
            sw = Container.fromAnchor(pop.properties['HwSwitch'])
            meter = self.meter
            rc = setmeter(sw, meter, 0, 0, 0, 0)
            # if not rc:

            # Iterate over the existing POPs to set up entries to handle broadcast traffic
            # between the POP being added and the existing POPs.  These all go in the
            # hardware switches.
            broadcastmac = "FF:FF:FF:FF:FF:FF"
            broadcastmac_mat = broadcastmac
            if MultiPointVPNServiceFactory.getVpnService().properties['mat']:
                broadcastmac_mat = self.generateBroadcastMAC()
            for (remotepopname, remotepop) in self.pops.items():
                vc = self.interconnectpops(pop.getResourceName(), remotepop.getResourceName())
                fhs = swconnect(pop, remotepop, broadcastmac_mat, vc, self.meter)
                self.popflows[remotepop.getResourceName()].extend(fhs)
                fhlist.extend(fhs)

            # This POP is now added.
            self.pops[pop.resourceName] = pop
            self.popflows[pop.resourceName] = fhlist

            # Regenerate entry fanout flows for various hosts because they need to learn
            # about a new POP
            for (hostmac, hostsitename) in self.hostsites.items():
                hostsite = self.vpnsites[hostsitename]
                hostvlan = self.vpnsitevlans[hostsitename]
                localpop = self.pops[hostsite['pop']]
                fh = self.makeentryfanoutflows(localpop= localpop, hostmac= hostmac, hostvlan= hostvlan, hostsite= hostsite)
                if fh != None:
                    self.hostflows[hostmac].append(fh)

            # print "addpop ending with pop flow handles", self.popflows[pop.name]

        return rc
Exemplo n.º 44
0
Arquivo: tbhost.py Projeto: esnet/enos
def addmemory(host, memory, swap):
    """ Adds memory to host template"""
    container = Container.getContainer(HOST_CONTAINER)

    if exists(host):         
        hostresource = container.loadResource(host)
        hostresource.properties[PROPERTIES_MEMORY] = memory
        hostresource.properties[PROPERTIES_SWAP] = swap
        container.saveResource(hostresource)
        return hostresource
    else:
        raise ValueError("Host does not exist. Please create template first")
Exemplo n.º 45
0
Arquivo: vpn.py Projeto: cygmris/enos
    def makeentryfanoutflows(self, localpop, hostmac, hostvlan, hostsite):
        # Create entry fanout flow on the software switch.  This flow fans out traffic
        # from the host/site to other hosts/sites on the same POP, as well as to all the
        # other POPs.
        # XXX need to re-run this part if we add another host/site to this POP or add
        # another POP
        forwards = []

        broadcast_mat = "FF:FF:FF:FF:FF:FF"
        if MultiPointVPNServiceFactory.getVpnService().properties['mat']:
            broadcast_mat = self.generateBroadcastMAC()

        # Locate all other sites on this POP.  For each of these, make a forwarding entry to it.
        for (othersitename, othersite) in self.vpnsites.items():
            if othersite[
                    'pop'] == localpop.resourceName and othersitename != hostsite[
                        'name']:
                fwd = SdnControllerClientL2Forward()
                fwd.outPort = "0"  # to be filled in by connectentryfanout
                fwd.vlan = int(self.vpnsitevlans[othersitename])
                fwd.dstMac = broadcast_mat
                forwards.append(fwd)

        # Locate other POPs
        for (otherpopname, otherpop) in self.pops.items():
            if otherpopname != localpop.resourceName:
                vc = self.interconnectpops(localpop.resourceName, otherpopname)
                core = Container.fromAnchor(localpop.properties['CoreRouter'])
                coreresname = core.resourceName
                (corename, coredom, coreport,
                 corevlan) = getvcnode(vc, coreresname)
                fwd = SdnControllerClientL2Forward()
                fwd.outPort = "0"  # to be filled in by connectentryfanout
                fwd.vlan = int(corevlan)
                fwd.dstMac = broadcast_mat
                forwards.append(fwd)

        # If we've already made an entry fanout flow for this host, then delete it.
        if hostmac in self.entryfanoutflows:
            oldfh = self.entryfanoutflows[hostmac]
            if oldfh.isValid():
                deleteforward(oldfh)
                del self.entryfanoutflows[hostmac]
                oldfh.invalidate()
        fh = connectentryfanoutmac(localpop=localpop,
                                   hostmac=hostmac,
                                   hostvlan=hostvlan,
                                   forwards=forwards,
                                   meter=self.meter,
                                   mac=broadcast_mat)
        if fh != None:
            self.entryfanoutflows[hostmac] = fh
        return fh
Exemplo n.º 46
0
Arquivo: tbhost.py Projeto: esnet/enos
def listhostdetails(host):
    """ Adds memory to host template"""
    container = Container.getContainer(HOST_CONTAINER)

    if exists(host):         
        hostresource = container.loadResource(host)
        print "HostProperty\t\tValue"
        for key in hostresource.properties:
        	print "%s\t\t%s" %(key, hostresource.properties[key])
        return hostresource
    else:
        raise ValueError("Host does not exist")
Exemplo n.º 47
0
def setuser(username,password,authrealm):
    """ This method stores the username and password to be used on proxmox hypervisors """
    if(username != None and password != None):
        container = Container.getContainer(PROXMOX_CONTAINER)
        userresource = Resource(PROPERTIES_USER)
        userresource.properties[PROPERTIES_TYPE] = USERRESOURCE
        userresource.properties[PROPERTIES_USER] = username
        userresource.properties[PROPERTES_PASSWORD] = password
        userresource.properties[PROPERTES_AUTHREALM] = authrealm
        container.deleteResource(PROPERTIES_USER)
        container.saveResource(userresource)
    else:
        raise TypeError("Username/password cannot be None Type")
Exemplo n.º 48
0
def setuser(username, password, authrealm):
    """ This method stores the username and password to be used on proxmox hypervisors """
    if (username != None and password != None):
        container = Container.getContainer(PROXMOX_CONTAINER)
        userresource = Resource(PROPERTIES_USER)
        userresource.properties[PROPERTIES_TYPE] = USERRESOURCE
        userresource.properties[PROPERTIES_USER] = username
        userresource.properties[PROPERTES_PASSWORD] = password
        userresource.properties[PROPERTES_AUTHREALM] = authrealm
        container.deleteResource(PROPERTIES_USER)
        container.saveResource(userresource)
    else:
        raise TypeError("Username/password cannot be None Type")
Exemplo n.º 49
0
Arquivo: tbhost.py Projeto: esnet/enos
def addcpu(host, cpuunits, cpulimit):
    """ Adds storage to host template"""
    container = Container.getContainer(HOST_CONTAINER)

    if exists(host):
            
        hostresource = container.loadResource(host)
        hostresource.properties[PROPERTIES_CPUUNITS] = cpuunits
        hostresource.properties[PROPERTIES_CPULIMIT] = cpulimit
        container.saveResource(hostresource)
        return hostresource
    else:
        raise ValueError("Host does not exist. Please create template first")
Exemplo n.º 50
0
Arquivo: tbhost.py Projeto: esnet/enos
def rebuildlxc(host):
    """ Creates 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])
    
    hostname = hostresource.properties[HOSTNAME]  		
    vmid = int(hostresource.properties[HOSTID])
    memory = int(hostresource.properties[PROPERTIES_MEMORY])
    swap = int(hostresource.properties[PROPERTIES_SWAP])
    interfaces = hostresource.properties[INTERFACES]
    
    i=0
    netconfig = dict()
    for interface in interfaces:
    	print "Configuring %s" %interface    	
    	netconfig["net"+str(i)] = hostresource.properties[interface]
    	i=i+1
    	
    print "Reconfiguring LXC with the following parameters:"
    print "Vmid: %d" %vmid
    print "Memory: %d" %memory
    print "Swap: %d" %swap
    
    node.lxc(vmid).config.put(memory=memory, swap=swap, **netconfig)
    print "Reconfiguring LXC....."
    time.sleep(30)
Exemplo n.º 51
0
def checkSlicerEnvironment():
    slices = Container.getContainer(Slices)
    if not "initialized" in slices.properties:
        # First time the MP-VPN Multiplexer is used. Need to intialize inventory
        print "First time running this command."
        print "creating MP-VPN Multiplexer environment. May takes a few seconds."
        from layer2.testbed.tbctl import createinv
        createinv(toponame=Inventory)
        slices.properties["initialized"] = True
        slices.save()
        print slices
        print "done"
    else:
        loadSlices()
Exemplo n.º 52
0
def newDPID(name=None):
    with ovsCtlLock:
        if name == None:
            name = "user"
        else:
            name = name[:4]
        container = Container.getContainer(getContinerName())
        userSwitchIndex = 1
        if ("userSwitchIndex" in container.properties):
            userSwitchIndex = container.properties["userSwitchIndex"]
        dpid = encodeDPID(vendor=Vendors.OVS,role=Roles.UserSwSwitch,location=name,id=userSwitchIndex)
        container.properties["userSwitchIndex"] = userSwitchIndex + 1
        container.save()
        return dpid
Exemplo n.º 53
0
def addhypervisor(hypervisor, port):
    """ This method adds hypervisor to the database """
    if (hypervisor != None):
        container = Container.getContainer(PROXMOX_CONTAINER)
        hresource = Resource(hypervisor)
        hresource.properties[PROPERTIES_HYPERVISOR] = hypervisor
        hresource.properties[PROPERTIES_TYPE] = HYPERVISORRESOURCE
        if (port != None):
            hresource.properties[PROPERTIES_PORT] = port
        else:
            hresource.properties[PROPERTIES_PORT] = DEFAULT_PORT
        container.deleteResource(hypervisor)
        container.saveResource(hresource)
    else:
        raise TypeError("hypervisor is null")
Exemplo n.º 54
0
def register(hostid, host, owner, pid):
    """ This method creates the ID resource from the given arguments and registers it in persistent storage """
    hid = int(hostid)

    idresource = Resource(hostid)
    idresource.properties[IDRESOURCE_HOST] = host
    idresource.properties[IDRESOURCE_PROJECT] = pid
    idresource.properties[IDRESOURCE_OWNER] = owner
    idresource.properties[IDRESOURCE_RESOURCEID] = hid
    container = Container.getContainer(ID_CONTAINER)
    idexists = container.loadResource(hostid)
    if idexists == None:
        container.saveResource(idresource)
    else:
        raise ValueError('ID exists. Attempting duplicate registration')
Exemplo n.º 55
0
def removehypervisor(hypervisor):
    """ This method removes the hypervisor"""
    if (hypervisor != None):
        container = Container.getContainer(PROXMOX_CONTAINER)
        primary = container.loadResource(PRIMARY_HYPERVISOR)
        if (primary
                and primary.properties[PROPERTIES_HYPERVISOR] == hypervisor):
            raise ValueError(
                hypervisor +
                " is primary hypervisor. Clear primary before removing hypervisor"
            )
        else:
            if (container.loadResource(hypervisor) != None):
                hresource = container.deleteResource(hypervisor)
            else:
                raise ValueError("Attempting to delete nonexistent Hypervisor")
    else:
        raise TypeError("Hypervisor cannot be None Type")
Exemplo n.º 56
0
def createSlice(name, owner, id=None):
    multiplexerSlices = globals()['multiplexerSlices']
    id = str(id)
    if id in multiplexerSlices:
        print "id ", id, " exists already."
    else:
        id = allocateNewID()
        if id == None:
            print("cannot allocate new slice id")
            return None
    slice = Resource(id)
    slice.setDescription(name)
    slice.properties[SliceOwner] = owner
    slice.setResourceType(ResourceTypes.SLICE)
    slices = Container.getContainer(Slices)
    slices.saveResource(slice)
    multiplexerSlices[id] = slice
    return id