Package ganeti :: Package server :: Module masterd
[hide private]
[frames] | no frames]

Source Code for Module ganeti.server.masterd

  1  # 
  2  # 
  3   
  4  # Copyright (C) 2006, 2007, 2010, 2011, 2012 Google Inc. 
  5  # All rights reserved. 
  6  # 
  7  # Redistribution and use in source and binary forms, with or without 
  8  # modification, are permitted provided that the following conditions are 
  9  # met: 
 10  # 
 11  # 1. Redistributions of source code must retain the above copyright notice, 
 12  # this list of conditions and the following disclaimer. 
 13  # 
 14  # 2. Redistributions in binary form must reproduce the above copyright 
 15  # notice, this list of conditions and the following disclaimer in the 
 16  # documentation and/or other materials provided with the distribution. 
 17  # 
 18  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 
 19  # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 
 20  # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
 21  # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
 22  # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
 23  # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
 24  # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
 25  # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
 26  # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
 27  # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
 28  # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 29   
 30   
 31  """Master daemon program. 
 32   
 33  Some classes deviates from the standard style guide since the 
 34  inheritance from parent classes requires it. 
 35   
 36  """ 
 37   
 38  # pylint: disable=C0103 
 39  # C0103: Invalid name ganeti-masterd 
 40   
 41  import logging 
 42   
 43  from ganeti import config 
 44  from ganeti import constants 
 45  from ganeti import jqueue 
 46  from ganeti import utils 
 47  import ganeti.rpc.node as rpc 
 48   
 49   
 50  CLIENT_REQUEST_WORKERS = 16 
 51   
 52  EXIT_NOTMASTER = constants.EXIT_NOTMASTER 
 53  EXIT_NODESETUP_ERROR = constants.EXIT_NODESETUP_ERROR 
 54   
 55   
56 -class GanetiContext(object):
57 """Context common to all ganeti threads. 58 59 This class creates and holds common objects shared by all threads. 60 61 """ 62 # pylint: disable=W0212 63 # we do want to ensure a singleton here 64 _instance = None 65
66 - def __init__(self, livelock=None):
67 """Constructs a new GanetiContext object. 68 69 There should be only a GanetiContext object at any time, so this 70 function raises an error if this is not the case. 71 72 """ 73 assert self.__class__._instance is None, "double GanetiContext instance" 74 75 # Create a livelock file 76 if livelock is None: 77 self.livelock = utils.livelock.LiveLock("masterd") 78 else: 79 self.livelock = livelock 80 81 # Job queue 82 cfg = self.GetConfig(None) 83 logging.debug("Creating the job queue") 84 self.jobqueue = jqueue.JobQueue(self, cfg) 85 86 # setting this also locks the class against attribute modifications 87 self.__class__._instance = self
88
89 - def __setattr__(self, name, value):
90 """Setting GanetiContext attributes is forbidden after initialization. 91 92 """ 93 assert self.__class__._instance is None, "Attempt to modify Ganeti Context" 94 object.__setattr__(self, name, value)
95
96 - def GetWConfdContext(self, ec_id):
97 return config.GetWConfdContext(ec_id, self.livelock)
98
99 - def GetConfig(self, ec_id):
100 return config.GetConfig(ec_id, self.livelock)
101 102 # pylint: disable=R0201 103 # method could be a function, but keep interface backwards compatible
104 - def GetRpc(self, cfg):
105 return rpc.RpcRunner(cfg, lambda _: None)
106
107 - def AddNode(self, cfg, node, ec_id):
108 """Adds a node to the configuration. 109 110 """ 111 # Add it to the configuration 112 cfg.AddNode(node, ec_id)
113
114 - def RemoveNode(self, cfg, node):
115 """Removes a node from the configuration and lock manager. 116 117 """ 118 # Remove node from configuration 119 cfg.RemoveNode(node.uuid)
120