Revision 176b0ee2

b/lib/bootstrap.py
600 600
                                   nodegroups=nodegroups,
601 601
                                   nodes=nodes,
602 602
                                   instances={},
603
                                   networks={},
603 604
                                   serial_no=1,
604 605
                                   ctime=now, mtime=now)
605 606
  utils.WriteFile(cfg_file,
b/lib/cmdlib.py
15340 15340
      result = ial.out_text
15341 15341
    return result
15342 15342

  
15343
# Network LUs
15344
class LUNetworkAdd(LogicalUnit):
15345
  def BuildHooksNodes(self):
15346
    pass
15347

  
15348
  def BuildHooksEnv(self):
15349
    pass
15350

  
15351

  
15352
class LUNetworkRemove(LogicalUnit):
15353
  def BuildHooksNodes(self):
15354
    pass
15355

  
15356
  def BuildHooksEnv(self):
15357
    pass
15358

  
15359

  
15360
class LUNetworkSetParams(LogicalUnit):
15361
  def BuildHooksNodes(self):
15362
    pass
15363

  
15364
  def BuildHooksEnv(self):
15365
    pass
15366

  
15367

  
15368
class _NetworkQuery(_QueryBase):
15369
  def ExpandNames(self, lu):
15370
    pass
15371

  
15372
  def DeclareLocks(self, lu, level):
15373
    pass
15374

  
15375
  def _GetQueryData(self, lu):
15376
    pass
15377

  
15378

  
15379
class LUNetworkQuery(NoHooksLU):
15380
  pass
15381

  
15382

  
15383
class LUNetworkConnect(LogicalUnit):
15384
  def BuildHooksNodes(self):
15385
    pass
15386

  
15387
  def BuildHooksEnv(self):
15388
    pass
15389

  
15390

  
15391
class LUNetworkDisconnect(LogicalUnit):
15392
  def BuildHooksNodes(self):
15393
    pass
15394

  
15395
  def BuildHooksEnv(self):
15396
    pass
15397

  
15343 15398

  
15344 15399
#: Query type implementations
15345 15400
_QUERY_IMPL = {
......
15347 15402
  constants.QR_INSTANCE: _InstanceQuery,
15348 15403
  constants.QR_NODE: _NodeQuery,
15349 15404
  constants.QR_GROUP: _GroupQuery,
15405
  constants.QR_NETWORK: _NetworkQuery,
15350 15406
  constants.QR_OS: _OsQuery,
15351 15407
  constants.QR_EXPORT: _ExportQuery,
15352 15408
  }
b/lib/constants.py
369 369
HTYPE_NODE = "NODE"
370 370
HTYPE_GROUP = "GROUP"
371 371
HTYPE_INSTANCE = "INSTANCE"
372
HTYPE_NETWORK = "NETWORK"
372 373

  
373 374
HKR_SKIP = 0
374 375
HKR_FAIL = 1
......
1091 1092

  
1092 1093
NIC_MODE_BRIDGED = "bridged"
1093 1094
NIC_MODE_ROUTED = "routed"
1095
NIC_IP_POOL = "pool"
1094 1096

  
1095 1097
NIC_VALID_MODES = frozenset([NIC_MODE_BRIDGED, NIC_MODE_ROUTED])
1096 1098

  
1099
# An extra description of the network.
1100
# Can be used by hooks/kvm-vif-bridge to apply different rules
1101
NETWORK_TYPE_PRIVATE = "private"
1102
NETWORK_TYPE_PUBLIC = "public"
1103

  
1104
NETWORK_VALID_TYPES = frozenset([NETWORK_TYPE_PRIVATE, NETWORK_TYPE_PUBLIC])
1105

  
1097 1106
NICS_PARAMETER_TYPES = {
1098 1107
  NIC_MODE: VTYPE_STRING,
1099 1108
  NIC_LINK: VTYPE_STRING,
......
1121 1130
INIC_IP = "ip"
1122 1131
INIC_MODE = "mode"
1123 1132
INIC_LINK = "link"
1133
INIC_NETWORK = "network"
1124 1134
INIC_PARAMS_TYPES = {
1125 1135
  INIC_IP: VTYPE_MAYBE_STRING,
1126 1136
  INIC_LINK: VTYPE_STRING,
1127 1137
  INIC_MAC: VTYPE_STRING,
1128 1138
  INIC_MODE: VTYPE_STRING,
1139
  INIC_NETWORK: VTYPE_MAYBE_STRING,
1129 1140
  }
1130 1141
INIC_PARAMS = frozenset(INIC_PARAMS_TYPES.keys())
1131 1142

  
......
1626 1637
QR_OS = "os"
1627 1638
QR_JOB = "job"
1628 1639
QR_EXPORT = "export"
1640
QR_NETWORK = "network"
1629 1641

  
1630 1642
#: List of resources which can be queried using L{opcodes.OpQuery}
1631 1643
QR_VIA_OP = frozenset([
......
1635 1647
  QR_GROUP,
1636 1648
  QR_OS,
1637 1649
  QR_EXPORT,
1650
  QR_NETWORK,
1638 1651
  ])
1639 1652

  
1640 1653
#: List of resources which can be queried using Local UniX Interface
......
1726 1739
SS_MAINTAIN_NODE_HEALTH = "maintain_node_health"
1727 1740
SS_UID_POOL = "uid_pool"
1728 1741
SS_NODEGROUPS = "nodegroups"
1742
SS_NETWORKS = "networks"
1729 1743

  
1730 1744
SS_FILE_PERMS = 0444
1731 1745

  
b/lib/objects.py
50 50

  
51 51

  
52 52
__all__ = ["ConfigObject", "ConfigData", "NIC", "Disk", "Instance",
53
           "OS", "Node", "NodeGroup", "Cluster", "FillDict"]
53
           "OS", "Node", "NodeGroup", "Cluster", "FillDict", "Network"]
54 54

  
55 55
_TIMESTAMPS = ["ctime", "mtime"]
56 56
_UUID = ["uuid"]
......
439 439
    "nodes",
440 440
    "nodegroups",
441 441
    "instances",
442
    "networks",
442 443
    "serial_no",
443 444
    ] + _TIMESTAMPS
444 445

  
......
451 452
    """
452 453
    mydict = super(ConfigData, self).ToDict()
453 454
    mydict["cluster"] = mydict["cluster"].ToDict()
454
    for key in "nodes", "instances", "nodegroups":
455
    for key in "nodes", "instances", "nodegroups", "networks":
455 456
      mydict[key] = self._ContainerToDicts(mydict[key])
456 457

  
457 458
    return mydict
......
466 467
    obj.nodes = cls._ContainerFromDicts(obj.nodes, dict, Node)
467 468
    obj.instances = cls._ContainerFromDicts(obj.instances, dict, Instance)
468 469
    obj.nodegroups = cls._ContainerFromDicts(obj.nodegroups, dict, NodeGroup)
470
    obj.networks = cls._ContainerFromDicts(obj.networks, dict, Network)
469 471
    return obj
470 472

  
471 473
  def HasAnyDiskOfType(self, dev_type):
......
502 504
      # gives a good approximation.
503 505
      if self.HasAnyDiskOfType(constants.LD_DRBD8):
504 506
        self.cluster.drbd_usermode_helper = constants.DEFAULT_DRBD_HELPER
507
    if self.networks is None:
508
      self.networks = {}
505 509

  
506 510

  
507 511
class NIC(ConfigObject):
508 512
  """Config object representing a network card."""
509
  __slots__ = ["mac", "ip", "nicparams"]
513
  __slots__ = ["mac", "ip", "network", "nicparams"]
510 514

  
511 515
  @classmethod
512 516
  def CheckParameterSyntax(cls, nicparams):
......
1389 1393
    "hv_state_static",
1390 1394
    "disk_state_static",
1391 1395
    "alloc_policy",
1396
    "networks",
1392 1397
    ] + _TIMESTAMPS + _UUID
1393 1398

  
1394 1399
  def ToDict(self):
......
1436 1441
    if self.ipolicy is None:
1437 1442
      self.ipolicy = MakeEmptyIPolicy()
1438 1443

  
1444
    if self.networks is None:
1445
      self.networks = {}
1446

  
1439 1447
  def FillND(self, node):
1440 1448
    """Return filled out ndparams for L{objects.Node}
1441 1449

  
......
2020 2028
    return True
2021 2029

  
2022 2030

  
2031
class Network(ConfigObject):
2032
  """Object representing a network definition for ganeti.
2033

  
2034
  """
2035
  __slots__ = [
2036
    "name",
2037
    "serial_no",
2038
    "network_type",
2039
    "mac_prefix",
2040
    "family",
2041
    "network",
2042
    "network6",
2043
    "gateway",
2044
    "gateway6",
2045
    "size",
2046
    "reservations",
2047
    "ext_reservations",
2048
    ] + _TIMESTAMPS + _UUID
2049

  
2050

  
2023 2051
class SerializableConfigParser(ConfigParser.SafeConfigParser):
2024 2052
  """Simple wrapper over ConfigParse that allows serialization.
2025 2053

  
b/lib/opcodes.py
35 35

  
36 36
import logging
37 37
import re
38
import ipaddr
38 39

  
39 40
from ganeti import constants
40 41
from ganeti import errors
......
166 167
_PAllowRuntimeChgs = ("allow_runtime_changes", True, ht.TBool,
167 168
                      "Allow runtime changes (eg. memory ballooning)")
168 169

  
170
#: a required network name
171
_PNetworkName = ("network_name", ht.NoDefault, ht.TNonEmptyString,
172
                 "Set network name")
169 173

  
170 174
#: OP_ID conversion regular expression
171 175
_OPID_RE = re.compile("([a-z])([A-Z])")
......
341 345
_PStorageType = ("storage_type", ht.NoDefault, _CheckStorageType,
342 346
                 "Storage type")
343 347

  
348
_CheckNetworkType = ht.TElemOf(constants.NETWORK_VALID_TYPES)
349

  
350
#: Network type parameter
351
_PNetworkType = ("network_type", None, ht.TOr(ht.TNone, _CheckNetworkType),
352
                 "Network type")
353

  
354
def _CheckCIDRNetNotation(value):
355
  """Ensure a given cidr notation type is valid.
356

  
357
  """
358
  try:
359
    ipaddr.IPv4Network(value)
360
  except ipaddr.AddressValueError:
361
    return False
362
  return True
363

  
364
def _CheckCIDRAddrNotation(value):
365
  """Ensure a given cidr notation type is valid.
366

  
367
  """
368
  try:
369
    ipaddr.IPv4Address(value)
370
  except ipaddr.AddressValueError:
371
    return False
372
  return True
373

  
374
def _CheckCIDR6AddrNotation(value):
375
  """Ensure a given cidr notation type is valid.
376

  
377
  """
378
  try:
379
    ipaddr.IPv6Address(value)
380
  except ipaddr.AddressValueError:
381
    return False
382
  return True
383

  
384
def _CheckCIDR6NetNotation(value):
385
  """Ensure a given cidr notation type is valid.
386

  
387
  """
388
  try:
389
    ipaddr.IPv6Network(value)
390
  except ipaddr.AddressValueError:
391
    return False
392
  return True
344 393

  
345 394
class _AutoOpParamSlots(type):
346 395
  """Meta class for opcode definitions.
......
1200 1249
    ("identify_defaults", False, ht.TBool,
1201 1250
     "Reset instance parameters to default if equal"),
1202 1251
    ("ip_check", True, ht.TBool, _PIpCheckDoc),
1252
    ("conflicts_check", True, ht.TBool, "Check for conflicting IPs"),
1203 1253
    ("mode", ht.NoDefault, ht.TElemOf(constants.INSTANCE_CREATE_MODES),
1204 1254
     "Instance creation mode"),
1205 1255
    ("nics", ht.NoDefault, ht.TListOf(_TestNicDef),
......
1531 1581
    ("wait_for_sync", True, ht.TBool,
1532 1582
     "Whether to wait for the disk to synchronize, when changing template"),
1533 1583
    ("offline", None, ht.TMaybeBool, "Whether to mark instance as offline"),
1584
    ("conflicts_check", True, ht.TBool, "Check for conflicting IPs"),
1534 1585
    ]
1535 1586
  OP_RESULT = _TSetParamsResult
1536 1587

  
......
1887 1938
  WITH_LU = False
1888 1939

  
1889 1940

  
1941
# Network opcodes
1942
# Add a new network in the cluster
1943
class OpNetworkAdd(OpCode):
1944
  """Add an IP network to the cluster."""
1945
  OP_DSC_FIELD = "network_name"
1946
  OP_PARAMS = [
1947
    _PNetworkName,
1948
    _PNetworkType,
1949
    ("network", None, ht.TAnd(ht.TString ,_CheckCIDRNetNotation), None),
1950
    ("gateway", None, ht.TOr(ht.TNone, _CheckCIDRAddrNotation), None),
1951
    ("network6", None, ht.TOr(ht.TNone, _CheckCIDR6NetNotation), None),
1952
    ("gateway6", None, ht.TOr(ht.TNone, _CheckCIDR6AddrNotation), None),
1953
    ("mac_prefix", None, ht.TMaybeString, None),
1954
    ("add_reserved_ips", None,
1955
     ht.TOr(ht.TNone, ht.TListOf(_CheckCIDRAddrNotation)), None),
1956
    ]
1957

  
1958
class OpNetworkRemove(OpCode):
1959
  """Remove an existing network from the cluster.
1960
     Must not be connected to any nodegroup.
1961

  
1962
  """
1963
  OP_DSC_FIELD = "network_name"
1964
  OP_PARAMS = [
1965
    _PNetworkName,
1966
    _PForce,
1967
    ]
1968

  
1969
class OpNetworkSetParams(OpCode):
1970
  """Modify Network's parameters except for IPv4 subnet"""
1971
  OP_DSC_FIELD = "network_name"
1972
  OP_PARAMS = [
1973
    _PNetworkName,
1974
    _PNetworkType,
1975
    ("gateway", None, ht.TOr(ht.TNone, _CheckCIDRAddrNotation), None),
1976
    ("network6", None, ht.TOr(ht.TNone, _CheckCIDR6NetNotation), None),
1977
    ("gateway6", None, ht.TOr(ht.TNone, _CheckCIDR6AddrNotation), None),
1978
    ("mac_prefix", None, ht.TMaybeString, None),
1979
    ("add_reserved_ips", None,
1980
     ht.TOr(ht.TNone, ht.TListOf(_CheckCIDRAddrNotation)), None),
1981
    ("remove_reserved_ips", None,
1982
     ht.TOr(ht.TNone, ht.TListOf(_CheckCIDRAddrNotation)), None),
1983
    ]
1984

  
1985
class OpNetworkConnect(OpCode):
1986
  """Connect a Network to a specific Nodegroup with the defined netparams
1987
     (mode, link). Nics in this Network will inherit those params.
1988
     Produce errors if a NIC (that its not already assigned to a network)
1989
     has an IP that is contained in the Network this will produce error unless
1990
     --no-conflicts-check is passed.
1991

  
1992
  """
1993
  OP_DSC_FIELD = "network_name"
1994
  OP_PARAMS = [
1995
    _PGroupName,
1996
    _PNetworkName,
1997
    ("network_mode", None, ht.TString, None),
1998
    ("network_link", None, ht.TString, None),
1999
    ("conflicts_check", True, ht.TBool, "Check for conflicting IPs"),
2000
    ]
2001

  
2002
class OpNetworkDisconnect(OpCode):
2003
  """Disconnect a Network from a Nodegroup. Produce errors if NICs are
2004
     present in the Network unless --no-conficts-check option is passed.
2005

  
2006
  """
2007
  OP_DSC_FIELD = "network_name"
2008
  OP_PARAMS = [
2009
    _PGroupName,
2010
    _PNetworkName,
2011
    ("conflicts_check", True, ht.TBool, "Check for conflicting IPs"),
2012
    ]
2013

  
2014
class OpNetworkQuery(OpCode):
2015
  """Compute the list of networks."""
2016
  OP_PARAMS = [
2017
    _POutputFields,
2018
    ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
2019
     "Empty list to query all groups, group names otherwise"),
2020
    ]
2021

  
2022

  
1890 2023
def _GetOpList():
1891 2024
  """Returns list of all defined opcodes.
1892 2025

  

Also available in: Unified diff