Revision 9808764a

b/lib/cmdlib/cluster.py
688 688
  """Checks if a netmask is valid.
689 689

  
690 690
  @type cfg: L{config.ConfigWriter}
691
  @param cfg: The cluster configuration
691
  @param cfg: cluster configuration
692 692
  @type netmask: int
693
  @param netmask: the netmask to be verified
693
  @param netmask: netmask to be verified
694 694
  @raise errors.OpPrereqError: if the validation fails
695 695

  
696 696
  """
......
1371 1371
    instance communication network is connected to all existing node
1372 1372
    groups, if necessary, via the opcode 'OpNetworkConnect'.
1373 1373

  
1374
    @type cfg: L{ganeti.config.ConfigWriter}
1375
    @param cfg: Ganeti configuration
1374
    @type cfg: L{config.ConfigWriter}
1375
    @param cfg: cluster configuration
1376 1376

  
1377 1377
    @type network_name: string
1378 1378
    @param network_name: instance communication network name
......
1427 1427
    and connected to all groups (see
1428 1428
    L{LUClusterSetParams._EnsureInstanceCommunicationNetwork}).
1429 1429

  
1430
    @type cfg: L{ganeti.config.ConfigWriter}
1431
    @param cfg: Ganeti configuration
1430
    @type cfg: L{config.ConfigWriter}
1431
    @param cfg: cluster configuration
1432 1432

  
1433 1433
    @type cluster: L{ganeti.objects.Cluster}
1434 1434
    @param cluster: Ganeti cluster
b/lib/cmdlib/instance.py
2895 2895
      CheckInstanceState(self, self.instance, CAN_CHANGE_INSTANCE_OFFLINE,
2896 2896
                         msg="can't change to offline")
2897 2897

  
2898
  @staticmethod
2899
  def _InstanceCommunicationDDM(cfg, instance_communication, instance):
2900
    """Create a NIC mod that adds or removes the instance
2901
    communication NIC to a running instance.
2902

  
2903
    The NICS are dynamically created using the Dynamic Device
2904
    Modification (DDM).  This function produces a NIC modification
2905
    (mod) that inserts an additional NIC meant for instance
2906
    communication in or removes an existing instance communication NIC
2907
    from a running instance, using DDM.
2908

  
2909
    @type cfg: L{config.ConfigWriter}
2910
    @param cfg: cluster configuration
2911

  
2912
    @type instance_communication: boolean
2913
    @param instance_communication: whether instance communication is
2914
                                   enabled or disabled
2915

  
2916
    @type instance: L{objects.Instance}
2917
    @param instance: instance to which the NIC mod will be applied to
2918

  
2919
    @rtype: (L{constants.DDM_ADD}, -1, parameters) or
2920
            (L{constants.DDM_REMOVE}, -1, parameters) or
2921
            L{None}
2922
    @return: DDM mod containing an action to add or remove the NIC, or
2923
             None if nothing needs to be done
2924

  
2925
    """
2926
    nic_name = "%s%s" % (constants.INSTANCE_COMMUNICATION_NIC_PREFIX,
2927
                         instance.name)
2928

  
2929
    instance_communication_nic = None
2930

  
2931
    for nic in instance.nics:
2932
      if nic.name == nic_name:
2933
        instance_communication_nic = nic
2934
        break
2935

  
2936
    if instance_communication and not instance_communication_nic:
2937
      action = constants.DDM_ADD
2938
      params = {constants.INIC_NAME: nic_name,
2939
                constants.INIC_MAC: constants.VALUE_GENERATE,
2940
                constants.INIC_IP: constants.NIC_IP_POOL,
2941
                constants.INIC_NETWORK:
2942
                  cfg.GetInstanceCommunicationNetwork()}
2943
    elif not instance_communication and instance_communication_nic:
2944
      action = constants.DDM_REMOVE
2945
      params = None
2946
    else:
2947
      action = None
2948
      params = None
2949

  
2950
    if action is not None:
2951
      return (action, -1, params)
2952
    else:
2953
      return None
2954

  
2898 2955
  def CheckPrereq(self):
2899 2956
    """Check prerequisites.
2900 2957

  
......
2953 3010
        self.op.hotplug = True
2954 3011

  
2955 3012
    # Prepare NIC modifications
3013
    # add or remove NIC for instance communication
3014
    if self.op.instance_communication is not None:
3015
      mod = self._InstanceCommunicationDDM(self.cfg,
3016
                                           self.op.instance_communication,
3017
                                           self.instance)
3018
      if mod is not None:
3019
        self.op.nics.append(mod)
3020

  
2956 3021
    self.nicmod = _PrepareContainerMods(self.op.nics, _InstNicModPrivate)
2957 3022

  
2958 3023
    # OS change

Also available in: Unified diff