Exemple #1
1
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"
Exemple #2
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
Exemple #3
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
Exemple #4
0
 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()
Exemple #5
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
Exemple #6
0
 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()
Exemple #7
0
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
Exemple #8
0
 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
Exemple #9
0
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)
Exemple #10
0
 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
Exemple #11
0
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")
Exemple #12
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)
Exemple #13
0
def loadSlices():
    multiplexerSlices = globals()['multiplexerSlices']
    slices = Container.getContainer(Slices)
    allocatedSlices = slices.loadResources(
        {"resourceType": ResourceTypes.SLICE})
    for slice in allocatedSlices:
        multiplexerSlices[slice.getResourceName()] = slice
Exemple #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
Exemple #15
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
Exemple #16
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
Exemple #17
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)
Exemple #18
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
Exemple #19
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
Exemple #20
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
Exemple #21
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
Exemple #22
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
Exemple #23
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
Exemple #24
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
Exemple #25
0
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"
Exemple #26
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")
Exemple #27
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)
Exemple #28
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")
Exemple #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")
Exemple #30
0
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")
Exemple #31
0
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
Exemple #32
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
Exemple #33
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"
Exemple #34
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
Exemple #35
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"
Exemple #36
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
Exemple #37
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")
Exemple #38
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")
Exemple #39
0
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")
Exemple #40
0
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")
Exemple #41
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
Exemple #42
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")
Exemple #43
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")
Exemple #44
0
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")
Exemple #45
0
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)
Exemple #46
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
Exemple #47
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")
Exemple #48
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()
Exemple #49
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")
Exemple #50
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')
Exemple #51
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")
Exemple #52
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
Exemple #53
0
def setprimary(hypervisor):
    """ This method sets the primary hypervisor to be used. Only hypervisors that exist in the database can be added"""
    if (hypervisor != None):
        container = Container.getContainer(PROXMOX_CONTAINER)
        hresource = container.loadResource(hypervisor)

        if (hresource != None):
            primaryhypervisor = Resource(PRIMARY_HYPERVISOR)
            primaryhypervisor.properties[
                PROPERTIES_HYPERVISOR] = hresource.properties[
                    PROPERTIES_HYPERVISOR]
            primaryhypervisor.properties[
                PROPERTIES_PORT] = hresource.properties[PROPERTIES_PORT]
            container.deleteResource(PRIMARY_HYPERVISOR)
            container.saveResource(primaryhypervisor)
        else:
            raise ValueError(
                "Attempting to make a nonexistent hypervisor as primary. Please add the hypervisor using addhypervisor command"
            )

    else:
        raise TypeError("Nonetype in hypervisor")
Exemple #54
0
def getid():
    """ Returns the next available id """
    rangequery = {}
    rangequery[DBQ_LESSER] = ID_MAX
    rangequery[DBQ_GREATER] = ID_MIN

    query = {}
    key = PROPERTIES+"."+IDRESOURCE_RESOURCEID

    query[key] = rangequery
    container = Container.getContainer(ID_CONTAINER)
    idresources = container.loadResources(query)

    # ProxMox requires id to be 100 or above.
    idbitmap = [True if i < 100 else False for i in range(ID_MAX+1)]

    for idresource in idresources:
        idbitmap[idresource.properties[IDRESOURCE_RESOURCEID]] = True

    for i in range(ID_MIN,ID_MAX+1):
        if not idbitmap[i]:
            return i

    raise ValueError('All ids have been allocated')
Exemple #55
0
def getnode(topology, nodename):
    container = Container.getContainer(topology)
    if container == None:
        print topology, "does not exist."
        return None
    return container.loadResource(nodename)