diff options
author | 2017-12-20 12:48:17 -0500 | |
---|---|---|
committer | 2017-12-20 12:53:44 -0500 | |
commit | b5437b0702015314a95ab34d1360b9b5589d7ae9 (patch) | |
tree | a958c2f1b8620477166af67ad3c4435efb8c80ad /source/network.py | |
parent | d229b80b597dc15d31a4a4326519cf87f8310ebe (diff) |
Initial Commit for new LaaS Software
JIRA: PHAROS-318
The old code I had in here was super beta and no good. I reworked the code
to use Stackstorm instead of trying to roll my own automation services.
This commit adds a README, install scripts, and the skeleton of a stackstorm
pack
Change-Id: Ia1c0c29e23316ad0e635c9c181c9a68fdacee664
Signed-off-by: Parker Berberian <pberberian@iol.unh.edu>
Diffstat (limited to 'source/network.py')
-rw-r--r-- | source/network.py | 103 |
1 files changed, 0 insertions, 103 deletions
diff --git a/source/network.py b/source/network.py deleted file mode 100644 index 234ba22..0000000 --- a/source/network.py +++ /dev/null @@ -1,103 +0,0 @@ -""" -############################################################################# -#Copyright 2017 Parker Berberian and others # -# # -#Licensed under the Apache License, Version 2.0 (the "License"); # -#you may not use this file except in compliance with the License. # -#You may obtain a copy of the License at # -# # -# http://www.apache.org/licenses/LICENSE-2.0 # -# # -#Unless required by applicable law or agreed to in writing, software # -#distributed under the License is distributed on an "AS IS" BASIS, # -#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # -#See the License for the specific language governing permissions and # -#limitations under the License. # -############################################################################# -""" - -import sys -import xml.dom -import xml.dom.minidom -import yaml - - -class Network: - """ - This class has a similar role as the Domain class. - This class will parse a config file and - write the xml definitions of those networks for libvirt. - """ - - def __init__(self, propertiesDict): - """ - init. propertiesDict should be - one of the dictionaries returned by parseConfigFile - """ - self.name = propertiesDict['name'] - self.brName = propertiesDict['brName'] - self.brAddr = propertiesDict['brAddr'] - self.netmask = propertiesDict['netmask'] - self.forward = propertiesDict['forward'] - self.dhcp = propertiesDict['dhcp'] - self.cidr = propertiesDict['cidr'] - - def toXML(self): - """ - Takes the config of this network and writes a valid xml definition - for libvirt. - returns a string - """ - definition = xml.dom.minidom.parseString("<network>\n</network>") - nameElem = definition.createElement('name') - nameElem.appendChild(definition.createTextNode(self.name)) - definition.documentElement.appendChild(nameElem) - - if self.forward['used']: - forwardElem = definition.createElement('forward') - forwardElem.setAttribute('mode', self.forward['type']) - definition.documentElement.appendChild(forwardElem) - - bridgeElem = definition.createElement('bridge') - bridgeElem.setAttribute('name', self.brName) - bridgeElem.setAttribute('stp', 'on') - bridgeElem.setAttribute('delay', '5') - definition.documentElement.appendChild(bridgeElem) - - ipElem = definition.createElement('ip') - ipElem.setAttribute('address', self.brAddr) - ipElem.setAttribute('netmask', self.netmask) - if self.dhcp['used']: - dhcpElem = definition.createElement('dhcp') - rangeElem = definition.createElement('range') - rangeElem.setAttribute('start', self.dhcp['rangeStart']) - rangeElem.setAttribute('end', self.dhcp['rangeEnd']) - dhcpElem.appendChild(rangeElem) - ipElem.appendChild(dhcpElem) - - definition.documentElement.appendChild(ipElem) - - self.xml = definition.toprettyxml() - return self.xml - - def writeXML(self, filePath): - """ - writes xml definition to given file - """ - f = open(filePath, 'w') - f.write(self.toXML()) - f.close() - - @staticmethod - def parseConfigFile(path): - """ - parses given config file - """ - configFile = open(path, 'r') - try: - config = yaml.safe_load(configFile) - except Exception: - print "Bad network configuration file. exiting" - sys.exit(1) - - return config |