Revision 09a3d21f

b/lib/cmdlib.py
1315 1315
  """Wrapper over L{_ExpandItemName} for instance."""
1316 1316
  return _ExpandItemName(cfg.ExpandInstanceName, name, "Instance")
1317 1317

  
1318
def _BuildNetworkHookEnv(name, network, gateway, network6, gateway6,
1319
                         network_type, mac_prefix):
1320
  env = dict()
1321
  if name:
1322
    env["NETWORK_NAME"] = name
1323
  if network:
1324
    env["NETWORK_SUBNET"] = network
1325
  if gateway:
1326
    env["NETWORK_GATEWAY"] = gateway
1327
  if network6:
1328
    env["NETWORK_SUBNET6"] = network6
1329
  if gateway6:
1330
    env["NETWORK_GATEWAY6"] = gateway6
1331
  if mac_prefix:
1332
    env["NETWORK_MAC_PREFIX"] = mac_prefix
1333
  if network_type:
1334
    env["NETWORK_TYPE"] = network_type
1335

  
1336
  return env
1337

  
1338

  
1339
def _BuildNetworkHookEnvByObject(lu, network):
1340
  args = {
1341
    "name": network.name,
1342
    "network": network.network,
1343
    "gateway": network.gateway,
1344
    "network6": network.network6,
1345
    "gateway6": network.gateway6,
1346
    "network_type": network.network_type,
1347
    "mac_prefix": network.mac_prefix,
1348
  }
1349
  return _BuildNetworkHookEnv(**args)
1350

  
1318 1351

  
1319 1352
def _BuildInstanceHookEnv(name, primary_node, secondary_nodes, os_type, status,
1320 1353
                          minmem, maxmem, vcpus, nics, disk_template, disks,
......
1375 1408
  }
1376 1409
  if nics:
1377 1410
    nic_count = len(nics)
1378
    for idx, (ip, mac, mode, link, network) in enumerate(nics):
1411
    for idx, (ip, mac, mode, link, network, netinfo) in enumerate(nics):
1379 1412
      if ip is None:
1380 1413
        ip = ""
1381 1414
      env["INSTANCE_NIC%d_IP" % idx] = ip
1382 1415
      env["INSTANCE_NIC%d_MAC" % idx] = mac
1383 1416
      env["INSTANCE_NIC%d_MODE" % idx] = mode
1384 1417
      env["INSTANCE_NIC%d_LINK" % idx] = link
1385
      env["INSTANCE_NIC%d_NETWORK" % idx] = network
1418
      if network:
1419
        env["INSTANCE_NIC%d_NETWORK" % idx] = network
1420
        if netinfo:
1421
          nobj = objects.Network.FromDict(netinfo)
1422
          if nobj.network:
1423
            env["INSTANCE_NIC%d_NETWORK_SUBNET" % idx] = nobj.network
1424
          if nobj.gateway:
1425
            env["INSTANCE_NIC%d_NETWORK_GATEWAY" % idx] = nobj.gateway
1426
          if nobj.network6:
1427
            env["INSTANCE_NIC%d_NETWORK_SUBNET6" % idx] = nobj.network6
1428
          if nobj.gateway6:
1429
            env["INSTANCE_NIC%d_NETWORK_GATEWAY6" % idx] = nobj.gateway6
1430
          if nobj.mac_prefix:
1431
            env["INSTANCE_NIC%d_NETWORK_MAC_PREFIX" % idx] = nobj.mac_prefix
1432
          if nobj.network_type:
1433
            env["INSTANCE_NIC%d_NETWORK_TYPE" % idx] = nobj.network_type
1386 1434
      if mode == constants.NIC_MODE_BRIDGED:
1387 1435
        env["INSTANCE_NIC%d_BRIDGE" % idx] = link
1388 1436
  else:
......
1411 1459

  
1412 1460
  return env
1413 1461

  
1462
def _NICToTuple(lu, nic):
1463
  """Build a tupple of nic information.
1464

  
1465
  @type lu:  L{LogicalUnit}
1466
  @param lu: the logical unit on whose behalf we execute
1467
  @type nic: L{objects.NIC}
1468
  @param nic: nic to convert to hooks tuple
1469

  
1470
  """
1471
  cluster = lu.cfg.GetClusterInfo()
1472
  ip = nic.ip
1473
  mac = nic.mac
1474
  filled_params = cluster.SimpleFillNIC(nic.nicparams)
1475
  mode = filled_params[constants.NIC_MODE]
1476
  link = filled_params[constants.NIC_LINK]
1477
  network = nic.network
1478
  netinfo = None
1479
  if network:
1480
    net_uuid = lu.cfg.LookupNetwork(network)
1481
    if net_uuid:
1482
      nobj = lu.cfg.GetNetwork(net_uuid)
1483
      netinfo = objects.Network.ToDict(nobj)
1484
  return (ip, mac, mode, link, network, netinfo)
1414 1485

  
1415 1486
def _NICListToTuple(lu, nics):
1416 1487
  """Build a list of nic information tuples.
......
1427 1498
  hooks_nics = []
1428 1499
  cluster = lu.cfg.GetClusterInfo()
1429 1500
  for nic in nics:
1430
    ip = nic.ip
1431
    mac = nic.mac
1432
    filled_params = cluster.SimpleFillNIC(nic.nicparams)
1433
    mode = filled_params[constants.NIC_MODE]
1434
    link = filled_params[constants.NIC_LINK]
1435
    network = nic.network
1436
    hooks_nics.append((ip, mac, mode, link, network))
1501
    hooks_nics.append(_NICToTuple(lu, nic))
1437 1502
  return hooks_nics
1438 1503

  
1439

  
1440 1504
def _BuildInstanceHookEnvByObject(lu, instance, override=None):
1441 1505
  """Builds instance related env variables for hooks from an object.
1442 1506

  
......
12773 12837
      nics = []
12774 12838

  
12775 12839
      for nic in self._new_nics:
12776
        nicparams = self.cluster.SimpleFillNIC(nic.nicparams)
12777
        mode = nicparams[constants.NIC_MODE]
12778
        link = nicparams[constants.NIC_LINK]
12779
        nics.append((nic.ip, nic.mac, mode, link, nic.network))
12840
        n = copy.deepcopy(nic)
12841
        nicparams = self.cluster.SimpleFillNIC(n.nicparams)
12842
        n.nicparams = nicparams
12843
        nics.append(_NICToTuple(self, n))
12780 12844

  
12781 12845
      args["nics"] = nics
12782 12846

  
......
15489 15553
    """Build hooks env.
15490 15554

  
15491 15555
    """
15492
    env = {
15493
      "NETWORK_NAME": self.op.network_name,
15494
      "NETWORK_SUBNET": self.op.network,
15495
      "NETWORK_GATEWAY": self.op.gateway,
15496
      "NETWORK_SUBNET6": self.op.network6,
15497
      "NETWORK_GATEWAY6": self.op.gateway6,
15498
      "NETWORK_MAC_PREFIX": self.op.mac_prefix,
15499
      "NETWORK_TYPE": self.op.network_type,
15556
    args = {
15557
      "name": self.op.network_name,
15558
      "network": self.op.network,
15559
      "gateway": self.op.gateway,
15560
      "network6": self.op.network6,
15561
      "gateway6": self.op.gateway6,
15562
      "mac_prefix": self.op.mac_prefix,
15563
      "network_type": self.op.network_type,
15500 15564
      }
15501
    return env
15565
    return _BuildNetworkHookEnv(**args)
15502 15566

  
15503 15567
  def Exec(self, feedback_fn):
15504 15568
    """Add the ip pool to the cluster.
......
15693 15757
    """Build hooks env.
15694 15758

  
15695 15759
    """
15696
    env = {
15697
      "NETWORK_NAME": self.op.network_name,
15698
      "NETWORK_SUBNET": self.network.network,
15699
      "NETWORK_GATEWAY": self.gateway,
15700
      "NETWORK_SUBNET6": self.network6,
15701
      "NETWORK_GATEWAY6": self.gateway6,
15702
      "NETWORK_MAC_PREFIX": self.mac_prefix,
15703
      "NETWORK_TYPE": self.network_type,
15760
    args = {
15761
      "name": self.op.network_name,
15762
      "network": self.network.network,
15763
      "gateway": self.gateway,
15764
      "network6": self.network6,
15765
      "gateway6": self.gateway6,
15766
      "mac_prefix": self.mac_prefix,
15767
      "network_type": self.network_type,
15704 15768
      }
15705
    return env
15769
    return _BuildNetworkHookEnv(**args)
15706 15770

  
15707 15771
  def BuildHooksNodes(self):
15708 15772
    """Build hooks nodes.
......
15921 15985
  def BuildHooksEnv(self):
15922 15986
    ret = dict()
15923 15987
    ret["GROUP_NAME"] = self.group_name
15924
    ret["GROUP_NETWORK_NAME"] = self.network_name
15925 15988
    ret["GROUP_NETWORK_MODE"] = self.network_mode
15926 15989
    ret["GROUP_NETWORK_LINK"] = self.network_link
15990
    ret.update(_BuildNetworkHookEnvByObject(self, self.network))
15927 15991
    return ret
15928 15992

  
15929 15993
  def BuildHooksNodes(self):
......
16015 16079
  def BuildHooksEnv(self):
16016 16080
    ret = dict()
16017 16081
    ret["GROUP_NAME"] = self.group_name
16018
    ret["GROUP_NETWORK_NAME"] = self.network_name
16082
    ret.update(_BuildNetworkHookEnvByObject(self, self.network))
16019 16083
    return ret
16020 16084

  
16021 16085
  def BuildHooksNodes(self):

Also available in: Unified diff