slap.py 11.1 KB
Newer Older
Łukasz Nowak's avatar
Łukasz Nowak committed
1 2
##############################################################################
#
3 4
# Copyright (c) 2010, 2011, 2012 Vifib SARL and Contributors.
# All Rights Reserved.
Łukasz Nowak's avatar
Łukasz Nowak committed
5 6 7 8 9 10 11 12 13
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
14 15
# modify it under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation; either version 2.1
Łukasz Nowak's avatar
Łukasz Nowak committed
16 17 18 19 20 21 22
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
23
# You should have received a copy of the GNU Lesser General Public License
Łukasz Nowak's avatar
Łukasz Nowak committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
##############################################################################
from zope.interface import Interface

"""
Note: all strings accepted/returned by the slap library are encoded in UTF-8.
"""
class IException(Interface):
  """
  Classes which implement IException are used to report errors.
  """

class INotFoundError(IException):
  """
  Classes which implement INotFoundError are used to report missing
  informations on the slap server.
  """

class IUnauthorized(IException):
  """
  Classes which implement IUnauthorized are used to report missing
  permissions on the slap server.
  """

Romain Courteaud's avatar
Romain Courteaud committed
50 51 52 53 54 55
class IRequester(Interface):
  """
  Classes which implement IRequester can request software instance to the
  slapgrid server.
  """

56
  def request(software_release, software_type, partition_reference,
Romain Courteaud's avatar
Romain Courteaud committed
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
              shared=False, partition_parameter_kw=None, filter_kw=None):
    """
    Request software release instanciation to slapgrid server.

    Returns a new computer partition document, where this sofware release will
    be installed.

    software_release -- uri of the software release
                        which has to be instanciated

    software_type -- type of component provided by software_release

    partition_reference -- local reference of the instance used by the recipe
                           to identify the instances.

    shared -- boolean to use a shared service

    partition_parameter_kw -- dictionary of parameter used to fill the
                              parameter dict of newly created partition.

    filter_kw -- dictionary of filtering parameter to select the requested
                 computer partition.

      computer_guid - computer of the requested partition
      partition_type - virtio, slave, full, limited
      port - port provided by the requested partition

    Example:
       request('http://example.com/toto/titi', 'typeA', 'mysql_1')
    """

Łukasz Nowak's avatar
Łukasz Nowak committed
88 89 90 91 92 93 94 95
class IBuildoutController(Interface):
  """
  Classes which implement IBuildoutController can report the buildout run
  status to the slapgrid server.
  """

  def available():
    """
96
    Notify (to the slapgrid server) that the software instance is
Łukasz Nowak's avatar
Łukasz Nowak committed
97 98 99 100 101
    available.
    """

  def building():
    """
102
    Notify (to the slapgrid server) that the buildout is not
Łukasz Nowak's avatar
Łukasz Nowak committed
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
    available and under creation.
    """

  def error(error_log):
    """
    Notify (to the slapgrid server) that the buildout is not available
    and reports an error.

    error_log -- a text describing the error
                 It can be a traceback for example.
    """

class ISoftwareRelease(IBuildoutController):
  """
  Software release interface specification
  """

  def getURI():
    """
    Returns a string representing the uri of the software release.
    """

125 126 127 128 129 130 131 132 133 134 135 136 137 138
  def getState():
    """
    Returns a string representing the expected state of the software
    installation.

    The result can be: available, destroyed
    """

  def destroyed():
    """
    Notify (to the slapgrid server) that the software installation has
    been correctly destroyed.
    """

Romain Courteaud's avatar
Romain Courteaud committed
139
class IComputerPartition(IBuildoutController, IRequester):
Łukasz Nowak's avatar
Łukasz Nowak committed
140 141 142 143 144 145 146 147 148 149
  """
  Computer Partition interface specification

  Classes which implement IComputerPartition can propagate the computer
  partition state to the SLAPGRID server and request new computer partition
  creation.
  """

  def stopped():
    """
150
    Notify (to the slapgrid server) that the software instance is
Łukasz Nowak's avatar
Łukasz Nowak committed
151 152 153 154 155
    available and stopped.
    """

  def started():
    """
156
    Notify (to the slapgrid server) that the software instance is
Łukasz Nowak's avatar
Łukasz Nowak committed
157 158 159
    available and started.
    """

160 161 162 163 164 165
  def destroyed():
    """
    Notify (to the slapgrid server) that the software instance has
    been correctly destroyed.
    """

Łukasz Nowak's avatar
Łukasz Nowak committed
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
  def getId():
    """
    Returns a string representing the identifier of the computer partition
    inside the slapgrid server.
    """

  def getState():
    """
    Returns a string representing the expected state of the computer partition.

    The result can be: started, stopped, destroyed
    """

  def getSoftwareRelease():
    """
    Returns the software release associate to the computer partition.

    Raise an INotFoundError if no software release is associated.
    """

  def getInstanceParameterDict():
    """
    Returns a dictionary of instance parameters.

    The contained values can be used to fill the software instanciation
    profile.
    """

Yingjie Xu's avatar
Yingjie Xu committed
194 195 196 197 198 199 200
  def getConnectionParameterDict():
    """
    Returns a dictionary of connection parameters.

    The contained values are connection parameters of a compute partition.
    """

Łukasz Nowak's avatar
Łukasz Nowak committed
201 202 203 204 205 206 207 208 209 210
  def setUsage(usage_log):
    """
    Associate a usage log to the computer partition.
    This method does not report the usage to the slapgrid server. See
    IComputer.report.

    usage_log -- a text describing the computer partition usage.
                 It can be an XML for example.
    """

211 212 213 214 215 216 217 218
  def bang(log):
    """
    Report a problem detected on a computer partition.
    This will trigger the reinstanciation of all partitions in the instance tree.

    log -- a text explaining why the method was called
    """

219 220
  def getCertificate():
    """
221
    Returns a dictionnary containing the authentification certificates
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
    associated to the computer partition.
    The dictionnary keys are:
      key -- value is a SSL key
      certificate -- value is a SSL certificate

    Raise an INotFoundError if no software release is associated.
    """

  def setConnectionDict(connection_dict, slave_reference=None):
    """
    Store the connection parameters associated to a partition.

    connection_dict -- dictionary of parameter used to fill the
                              connection dict of the partition.

    slave_reference -- current reference of the slave instance to modify
    """

Yingjie Xu's avatar
Yingjie Xu committed
240 241 242 243 244 245 246 247 248
  def getInstanceParameter(key):
    """
    Returns the instance parameter associated to the key.

    Raise an INotFoundError if no key is defined.

    key -- a string name of the parameter
    """

249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
  def getConnectionParameter(key):
    """
    Return the connection parameter associate to the key.

    Raise an INotFoundError if no key is defined.

    key -- a string name of the parameter
    """

  def rename(partition_reference, slave_reference=None):
    """
    Change the partition reference of a partition

    partition_reference -- new local reference of the instance used by the recipe
                           to identify the instances.

    slave_reference -- current reference of the slave instance to modify
    """

Łukasz Nowak's avatar
Łukasz Nowak committed
268 269 270 271 272 273 274 275 276
class IComputer(Interface):
  """
  Computer interface specification

  Classes which implement IComputer can fetch informations from the slapgrid
  server to know which Software Releases and Software Instances have to be
  installed.
  """

277
  def getSoftwareReleaseList():
Łukasz Nowak's avatar
Łukasz Nowak committed
278 279 280 281 282 283 284
    """
    Returns the list of software release which has to be supplied by the
    computer.

    Raise an INotFoundError if computer_guid doesn't exist.
    """

285
  def getComputerPartitionList():
Łukasz Nowak's avatar
Łukasz Nowak committed
286 287 288 289 290 291 292 293 294
    """
    Returns the list of configured computer partitions associated to this
    computer.

    Raise an INotFoundError if computer_guid doesn't exist.
    """

  def reportUsage(computer_partition_list):
    """
295
    Report the computer usage to the slapgrid server.
Łukasz Nowak's avatar
Łukasz Nowak committed
296 297 298 299 300 301 302
    IComputerPartition.setUsage has to be called on each computer partition to
    define each usage.

    computer_partition_list -- a list of computer partition for which the usage
                               needs to be reported.
    """

303 304 305 306 307 308 309 310 311
  def bang(log):
    """
    Report a problem detected on a computer.
    This will trigger IComputerPartition.bang on all instances hosted by the
    Computer.

    log -- a text explaining why the method was called
    """

312 313 314 315 316 317 318
  def updateConfiguration(configuration_xml):
    """
    Report the current computer configuration.

    configuration_xml -- computer XML description generated by slapformat
    """

Romain Courteaud's avatar
Romain Courteaud committed
319
class IOpenOrder(IRequester):
Łukasz Nowak's avatar
Łukasz Nowak committed
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
  """
  Open Order interface specification

  Classes which implement Open Order describe which kind of software instances
  is requested by a given client.
  """

class ISupply(Interface):
  """
  Supply interface specification

  Classes which implement Supply describe which kind of software releases
  a given client is ready to supply.
  """

  def supply(software_release, computer_guid=None):
    """
    Tell that given client is ready to supply given sofware release

    software_release -- uri of the software release
                        which has to be instanciated

342
    computer_guid -- the identifier of the computer inside the slapgrid
Łukasz Nowak's avatar
Łukasz Nowak committed
343 344 345 346 347 348 349
                     server.
    """

class slap(Interface):
  """
  Initialise slap connection to the slapgrid server

350
  Slapgrid server URL is defined during the slap library installation,
Łukasz Nowak's avatar
Łukasz Nowak committed
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
  as recipes should not use another server.
  """

  def initializeConnection(slapgrid_uri, authentification_key=None):
    """
    Initialize the connection parameters to the slapgrid servers.

    slapgrid_uri -- uri the slapgrid server connector

    authentification_key -- string the authentificate the agent.

    Example: https://slapos.server/slap_interface
    """

  def registerComputer(computer_guid):
    """
    Instanciate a computer in the slap library.

    computer_guid -- the identifier of the computer inside the slapgrid server.
    """

  def registerComputerPartition(computer_guid, partition_id):
    """
    Instanciate a computer partition in the slap library.

    computer_guid -- the identifier of the computer inside the slapgrid server.

378
    partition_id -- the identifier of the computer partition inside the
Łukasz Nowak's avatar
Łukasz Nowak committed
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
                    slapgrid server.

    Raise an INotFoundError if computer_guid doesn't exist.
    """

  def registerSoftwareRelease(software_release):
    """
    Instanciate a software release in the slap library.

    software_release -- uri of the software release definition
    """

  def registerOpenOrder():
    """
    Instanciate an open order in the slap library.
    """
395

Łukasz Nowak's avatar
Łukasz Nowak committed
396
  def registerSupply():
397
    """
Łukasz Nowak's avatar
Łukasz Nowak committed
398 399
    Instanciate a supply in the slap library.
    """