summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael DeHaan <mdehaan@mdehaan.rdu.redhat.com>2007-09-20 16:22:42 -0400
committerMichael DeHaan <mdehaan@mdehaan.rdu.redhat.com>2007-09-20 16:22:42 -0400
commit2d318c3c0e7a615552e8c5ca103614be0b40eab7 (patch)
treee0558a94c3ba516841bd3036d4207e1087c7048e
parent7b335ce91ff9520dc46e7d80e526ae19e4b27900 (diff)
downloadthird_party-func-2d318c3c0e7a615552e8c5ca103614be0b40eab7.tar.gz
third_party-func-2d318c3c0e7a615552e8c5ca103614be0b40eab7.tar.xz
third_party-func-2d318c3c0e7a615552e8c5ca103614be0b40eab7.zip
Basic config file. Intentionally short. Slowly removing VF code.
-rw-r--r--config/settings6
-rwxr-xr-xserver/codes.py235
-rwxr-xr-xserver/config_data.py27
3 files changed, 20 insertions, 248 deletions
diff --git a/config/settings b/config/settings
new file mode 100644
index 0000000..e15fe9f
--- /dev/null
+++ b/config/settings
@@ -0,0 +1,6 @@
+# configuration for master servers
+
+[general]
+is_master = 0
+is_minion = 1
+master_server = funcmaster
diff --git a/server/codes.py b/server/codes.py
index 82bfb0a..637a0b2 100755
--- a/server/codes.py
+++ b/server/codes.py
@@ -2,9 +2,8 @@
"""
Virt-factory backend code.
-Copyright 2006, Red Hat, Inc
-Michael DeHaan <mdehaan@redhat.com>
-Scott Seago <sseago@redhat.com>
+Copyright 2007, Red Hat, Inc
+See AUTHORS
This software may be freely redistributed under the terms of the GNU
general public license.
@@ -20,233 +19,7 @@ import sys
import traceback
-
-# internal codes for the types of operations (used by validation logic)
-OP_ADD = "add"
-OP_EDIT = "edit"
-OP_DELETE = "delete"
-OP_LIST = "list"
-OP_METHOD = "method"
-OP_GET = "get"
-
-# error codes for the web service.
-SUCCESS = ERR_SUCCESS = 0
-ERR_TOKEN_EXPIRED = 1
-ERR_TOKEN_INVALID = 2
-ERR_USER_INVALID = 3
-ERR_PASSWORD_INVALID = 4
-ERR_INTERNAL_ERROR = 5
-ERR_INVALID_ARGUMENTS = 6
-ERR_NO_SUCH_OBJECT = 7
-ERR_ORPHANED_OBJECT = 8
-ERR_SQL = 9
-ERR_MISCONFIGURED = 10
-ERR_UNCAUGHT = 11
-ERR_INVALID_METHOD = 12
-ERR_TASK = 13
-ERR_REG_TOKEN_INVALID = 14
-ERR_REG_TOKEN_EXHAUSTED = 15
-ERR_PUPPET_NODE_NOT_SIGNED = 16
-
-
-
class FuncException(exceptions.Exception):
- error_code = ERR_INTERNAL_ERROR
-
- def __init__(self, **kwargs):
- self.job_id = self.load(kwargs,"job_id")
- self.stacktrace = self.load(kwargs,"stacktrace")
- self.invalid_fields = self.load(kwargs,"invalid_fields")
- self.data = self.load(kwargs,"data")
- self.comment = self.load(kwargs,"comment")
- self.tb_data = traceback.extract_stack()
- exceptions.Exception.__init__(self)
-
-
- def format(self):
- msg = """
-Exception Name: %s
-Exception Comment: %s
-Exception Data: %s
-Stack Trace:
-%s""" % (self.__class__, self.comment, self.data,
- string.join(traceback.format_list(self.tb_data)))
-
- return msg
-
- def ok(self):
- return self.error_code == 0
-
- def load(self,hash,key,default=None):
- if hash.has_key(key):
- return hash[key]
- else:
- return default
-
- def __get_additional_data(self):
- data = {}
- if not self.job_id is None:
- data["job_id"] = self.job_id
- if not self.stacktrace is None:
- data["stacktrace"] = self.stacktrace
- if not self.invalid_fields is None:
- data["invalid_fields"] = self.invalid_fields
- if not self.data is None:
- data["data"] = self.data
- if not self.comment is None:
- data["comment"] = self.comment
- return data
-
- def to_datastruct(self):
- return (self.error_code, self.__get_additional_data())
-
-#FIXME: hack
-VirtFactoryException = FuncException
-
-class SuccessException(VirtFactoryException):
- """
- Not an error / return success and data to caller.
- """
- error_code = ERR_SUCCESS
-
-class TokenExpiredException(VirtFactoryException):
- """
- The user token that was passed in has been logged out
- due to inactivity. Call user_login again.
- """
- error_code = ERR_TOKEN_EXPIRED
-
-class TokenInvalidException(VirtFactoryException):
- """
- The user token doesn't exist, so this function call isn't
- permitted. Call user_login to get a valid token.
- """
- error_code = ERR_TOKEN_INVALID
-
-class RegTokenInvalidException(VirtFactoryException):
- """
- The registration token doesn't exist, so this function call isn't
- permitted.
- """
- error_code = ERR_REG_TOKEN_INVALID
-
-class RegTokenExhaustedException(VirtFactoryException):
- """
- The registration token that was passed in has been used
- it allowed number of uses.
- """
- error_code = ERR_REG_TOKEN_EXHAUSTED
-
-class UserInvalidException(VirtFactoryException):
- """
- Can't log in this user since the user account doesn't
- exist in the database.
- """
- error_code = ERR_USER_INVALID
-
-class PasswordInvalidException(VirtFactoryException):
- """
- Wrong password. Bzzzt. Try again.
- """
- error_code = ERR_PASSWORD_INVALID
-
-class InternalErrorException(VirtFactoryException):
- """
- FIXME: This is a generic error code, and if something is
- throwing that error, it probably
- should be changed to throw something more specific.
- """
- error_code = ERR_INTERNAL_ERROR
-
-class InvalidArgumentsException(VirtFactoryException):
- """
- The arguments passed in to this function failed to pass
- validation. See additional_data for the
- names of which arguments were rejected.
- """
- error_code = ERR_INVALID_ARGUMENTS
-
-class NoSuchObjectException(VirtFactoryException):
- """
- The id passed in doesn't refer to an object.
- """
- error_code = ERR_NO_SUCH_OBJECT
-
-class InvalidMethodException(VirtFactoryException):
- """The method called does not exist"""
- error_code = ERR_INVALID_METHOD
-
-class UncaughtException(VirtFactoryException):
- """
- The python code choked. additional_data contains the
- stacktrace, and it's ok to give the stacktrace
- since the user is already logged in. user_login shouldn't
- give stacktraces for security reasons.
- """
- error_code = ERR_UNCAUGHT
-
-class OrphanedObjectException(VirtFactoryException):
- """
- A delete can't proceed because another object references
- this one, or an add can't proceed because a
- referenced object doesn't exist.
- """
- error_code = ERR_ORPHANED_OBJECT
-
-class SQLException(VirtFactoryException):
- """
- The code died inside a SQL call. This is probably
- a sign that the validation prior to making
- the call needs to be improved, or maybe SQL was just
- more efficient (i.e. referential integrity).
- """
- error_code = ERR_SQL
-
-class TaskException(VirtFactoryException):
- """
- Something went wrong with the background task engine
- """
- error_code = ERR_TASK
-
-class MisconfiguredException(VirtFactoryException):
- """
- The virt-factory service isn't properly configured and
- no calls can be processed until this is corrected on the
- server side. The UI/WUI/etc is non-functional and should
- display a splash screen telling the user to finish their
- setup of the virt-factory service by running "vf_server init", edit
- /var/lib/virt-factory/settings, and then run "vf_server import".
- """
- error_code = ERR_MISCONFIGURED
-
-
-class PuppetNodeNotSignedException(VirtFactoryException):
- """
- The puppet node certificate could not be signed, either
- because there was no matching certificate requrest or
- due to another puppetca error.
- """
- error_code = ERR_PUPPET_NODE_NOT_SIGNED
-
-def success(data=None,job_id=None):
- """
- Shortcut around success exception that returns equivalent data
- w/o raise.
- """
- ret = SuccessException(data=data, job_id=job_id)
- return ret
-
-
-if __name__ == "__main__":
- # run this module as main to generate a ruby compatible constants
- # file.
- module = sys.modules[__name__]
- for x in sorted(module.__dict__.keys()):
- obj = module.__dict__[x]
- if (type(obj) == int or type(obj) == str) and not x.startswith("__"):
- if type(obj) == int:
- print "%s = %s" % (x, obj)
- else:
- print "%s = \"%s\"" % (x, obj)
-
+ pass
+# FIXME: more sub-exceptions maybe
diff --git a/server/config_data.py b/server/config_data.py
index 9ccca75..bda7635 100755
--- a/server/config_data.py
+++ b/server/config_data.py
@@ -16,19 +16,10 @@
from codes import *
-
import os
-import yaml
-
-CONFIG_FILE = "/etc/virt-factory/settings"
-
-# from the comments in http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531
-#class Singleton(object):
-# def __new__(type):
-# if not '_the_instance' in type.__dict__:
-# type._the_instance = object.__new__(type)
-# return type._the_instance
+import ConfigParser
+CONFIG_FILE = "/etc/func/settings"
class Config:
@@ -40,16 +31,18 @@ class Config:
self.__dict__ = self.__shared_state
if not self.has_read:
self.read()
- print "***** CONFIG RELOAD *****"
Config.has_read = True
def read(self):
+
if not os.path.exists(CONFIG_FILE):
- raise MisconfiguredException(comment="Missing %s" % CONFIG_FILE)
- config_file = open(CONFIG_FILE)
- data = config_file.read()
- self.ds = yaml.load(data).next()
-
+ raise FuncException(comment="Missing %s" % CONFIG_FILE)
+
+ cp = ConfigParser.ConfigParser()
+
+ self.ds["is_master"] = int(cp.get("general","is_master"))
+ self.ds["is_minion"] = int(cp.get("general","is_minion"))
+ self.ds["master_server"] = cp.get("general","master")
def get(self):
return self.ds