Revision 08208574

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
  pass
15346

  
15347
class LUNetworkRemove(LogicalUnit):
15348
  pass
15349

  
15350
class LUNetworkSetParams(LogicalUnit):
15351
  pass
15352

  
15353
class _NetworkQuery(_QueryBase):
15354
  pass
15355

  
15356
class LUNetworkQuery(NoHooksLU):
15357
  pass
15358

  
15359
class LUNetworkConnect(LogicalUnit):
15360
  pass
15361

  
15362
class LUNetworkDisconnect(LogicalUnit):
15363
  pass
15364

  
15343 15365

  
15344 15366
#: Query type implementations
15345 15367
_QUERY_IMPL = {
......
15347 15369
  constants.QR_INSTANCE: _InstanceQuery,
15348 15370
  constants.QR_NODE: _NodeQuery,
15349 15371
  constants.QR_GROUP: _GroupQuery,
15372
  constants.QR_NETWORK: _NetworkQuery,
15350 15373
  constants.QR_OS: _OsQuery,
15351 15374
  constants.QR_EXPORT: _ExportQuery,
15352 15375
  }
b/lib/constants.py
368 368
HTYPE_NODE = "NODE"
369 369
HTYPE_GROUP = "GROUP"
370 370
HTYPE_INSTANCE = "INSTANCE"
371
HTYPE_NETWORK = "NETWORK"
371 372

  
372 373
HKR_SKIP = 0
373 374
HKR_FAIL = 1
......
1090 1091

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

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

  
1098
NETWORK_TYPE_PRIVATE = "private"
1099
NETWORK_TYPE_PUBLIC = "public"
1100

  
1101
NETWORK_VALID_TYPES = frozenset([NETWORK_TYPE_PRIVATE, NETWORK_TYPE_PUBLIC])
1102

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

  
......
1625 1634
QR_OS = "os"
1626 1635
QR_JOB = "job"
1627 1636
QR_EXPORT = "export"
1637
QR_NETWORK = "network"
1628 1638

  
1629 1639
#: List of resources which can be queried using L{opcodes.OpQuery}
1630 1640
QR_VIA_OP = frozenset([
......
1634 1644
  QR_GROUP,
1635 1645
  QR_OS,
1636 1646
  QR_EXPORT,
1647
  QR_NETWORK,
1637 1648
  ])
1638 1649

  
1639 1650
#: List of resources which can be queried using Local UniX Interface
......
1725 1736
SS_MAINTAIN_NODE_HEALTH = "maintain_node_health"
1726 1737
SS_UID_POOL = "uid_pool"
1727 1738
SS_NODEGROUPS = "nodegroups"
1739
SS_NETWORKS = "networks"
1728 1740

  
1729 1741
SS_FILE_PERMS = 0444
1730 1742

  
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):
......
1383 1387
    "hv_state_static",
1384 1388
    "disk_state_static",
1385 1389
    "alloc_policy",
1390
    "networks",
1386 1391
    ] + _TIMESTAMPS + _UUID
1387 1392

  
1388 1393
  def ToDict(self):
......
1430 1435
    if self.ipolicy is None:
1431 1436
      self.ipolicy = MakeEmptyIPolicy()
1432 1437

  
1438
    if self.networks is None:
1439
      self.networks = {}
1440

  
1433 1441
  def FillND(self, node):
1434 1442
    """Return filled out ndparams for L{objects.Node}
1435 1443

  
......
2014 2022
    return True
2015 2023

  
2016 2024

  
2025
class Network(ConfigObject):
2026
  """Object representing a network definition for ganeti.
2027

  
2028
  """
2029
  __slots__ = [
2030
    "name",
2031
    "serial_no",
2032
    "network_type",
2033
    "mac_prefix",
2034
    "family",
2035
    "network",
2036
    "network6",
2037
    "gateway",
2038
    "gateway6",
2039
    "size",
2040
    "reservations",
2041
    "ext_reservations",
2042
    ] + _TIMESTAMPS + _UUID
2043

  
2044

  
2017 2045
class SerializableConfigParser(ConfigParser.SafeConfigParser):
2018 2046
  """Simple wrapper over ConfigParse that allows serialization.
2019 2047

  
b/lib/opcodes.py
166 166
_PAllowRuntimeChgs = ("allow_runtime_changes", True, ht.TBool,
167 167
                      "Allow runtime changes (eg. memory ballooning)")
168 168

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

  
170 172
#: OP_ID conversion regular expression
171 173
_OPID_RE = re.compile("([a-z])([A-Z])")
......
1200 1202
    ("identify_defaults", False, ht.TBool,
1201 1203
     "Reset instance parameters to default if equal"),
1202 1204
    ("ip_check", True, ht.TBool, _PIpCheckDoc),
1205
    ("conflicts_check", True, ht.TBool, "Check for conflicting IPs"),
1203 1206
    ("mode", ht.NoDefault, ht.TElemOf(constants.INSTANCE_CREATE_MODES),
1204 1207
     "Instance creation mode"),
1205 1208
    ("nics", ht.NoDefault, ht.TListOf(_TestNicDef),
......
1531 1534
    ("wait_for_sync", True, ht.TBool,
1532 1535
     "Whether to wait for the disk to synchronize, when changing template"),
1533 1536
    ("offline", None, ht.TMaybeBool, "Whether to mark instance as offline"),
1537
    ("conflicts_check", True, ht.TBool, "Check for conflicting IPs"),
1534 1538
    ]
1535 1539
  OP_RESULT = _TSetParamsResult
1536 1540

  
......
1887 1891
  WITH_LU = False
1888 1892

  
1889 1893

  
1894
# Network opcodes
1895
class OpNetworkAdd(OpCode):
1896
  """Add an IP network to the cluster."""
1897
  OP_DSC_FIELD = "network_name"
1898
  OP_PARAMS = [
1899
    _PNetworkName,
1900
    ("network", None, ht.TString, None),
1901
    ("gateway", None, ht.TMaybeString, None),
1902
    ("network6", None, ht.TMaybeString, None),
1903
    ("gateway6", None, ht.TMaybeString, None),
1904
    ("mac_prefix", None, ht.TMaybeString, None),
1905
    ("network_type", None, ht.TMaybeString, None),
1906
    ("reserved_ips", None, ht.TOr(ht.TListOf(ht.TNonEmptyString), ht.TNone), None),
1907
    ]
1908

  
1909
class OpNetworkRemove(OpCode):
1910
  """Remove an IP network from the cluster."""
1911
  OP_DSC_FIELD = "network_name"
1912
  OP_PARAMS = [
1913
    _PNetworkName,
1914
    _PForce,
1915
    ]
1916

  
1917
class OpNetworkSetParams(OpCode):
1918
  """Set parameters of an IP network"""
1919
  OP_DSC_FIELD = "network_name"
1920
  OP_PARAMS = [
1921
    _PNetworkName,
1922
    ("gateway", None, ht.TMaybeString, None),
1923
    ("reserved_ips", None, ht.TOr(ht.TListOf(ht.TNonEmptyString), ht.TNone), None),
1924
    ("network6", None, ht.TMaybeString, None),
1925
    ("gateway6", None, ht.TMaybeString, None),
1926
    ("mac_prefix", None, ht.TMaybeString, None),
1927
    ("network_type", None, ht.TMaybeString, None),
1928
    ]
1929

  
1930
class OpNetworkConnect(OpCode):
1931
  OP_DSC_FIELD = "network_name"
1932
  OP_PARAMS = [
1933
    _PGroupName,
1934
    _PNetworkName,
1935
    ("network_mode", None, ht.TString, None),
1936
    ("network_link", None, ht.TString, None),
1937
    ("conflicts_check", True, ht.TBool, "Check for conflicting IPs"),
1938
    ]
1939

  
1940
class OpNetworkDisconnect(OpCode):
1941
  OP_DSC_FIELD = "network_name"
1942
  OP_PARAMS = [
1943
    _PGroupName,
1944
    _PNetworkName,
1945
    ("conflicts_check", True, ht.TBool, "Check for conflicting IPs"),
1946
    ]
1947

  
1948
class OpNetworkConnectAll(OpCode):
1949
  OP_DSC_FIELD = "network_name"
1950
  OP_PARAMS = [
1951
    _PNetworkName,
1952
    ("network_mode", None, ht.TString, None),
1953
    ("network_link", None, ht.TString, None),
1954
    ("conflicts_check", True, ht.TBool, "Check for conflicting IPs"),
1955
    ]
1956

  
1957
class OpNetworkDisconnectAll(OpCode):
1958
  OP_DSC_FIELD = "network_name"
1959
  OP_PARAMS = [
1960
    _PNetworkName,
1961
    ("conflicts_check", True, ht.TBool, "Check for conflicting IPs"),
1962
    ]
1963

  
1964

  
1965
class OpNetworkQuery(OpCode):
1966
  """Compute the list of networks."""
1967
  OP_PARAMS = [
1968
    _POutputFields,
1969
    ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1970
     "Empty list to query all groups, group names otherwise"),
1971
    ]
1972

  
1973

  
1890 1974
def _GetOpList():
1891 1975
  """Returns list of all defined opcodes.
1892 1976

  

Also available in: Unified diff