Revision 11eeb1b9 lib/cmdlib/cluster.py

b/lib/cmdlib/cluster.py
1034 1034
            "Cannot disable disk template '%s', because there is at least one"
1035 1035
            " instance using it." % disk_template)
1036 1036

  
1037
  @staticmethod
1038
  def _CheckInstanceCommunicationNetwork(network, warning_fn):
1039
    """Check whether an existing network is configured for instance
1040
    communication.
1041

  
1042
    Checks whether an existing network is configured with the
1043
    parameters that are advisable for instance communication, and
1044
    otherwise issue security warnings.
1045

  
1046
    @type network: L{ganeti.objects.Network}
1047
    @param network: L{ganeti.objects.Network} object whose
1048
                    configuration is being checked
1049
    @type warning_fn: function
1050
    @param warning_fn: function used to print warnings
1051
    @rtype: None
1052
    @return: None
1053

  
1054
    """
1055
    def _MaybeWarn(err, val, default):
1056
      if val != default:
1057
        warning_fn("Supplied instance communication network '%s' %s '%s',"
1058
                   " this might pose a security risk (default is '%s').",
1059
                   network.name, err, val, default)
1060

  
1061
    if network.network is None:
1062
      raise errors.OpPrereqError("Supplied instance communication network '%s'"
1063
                                 " must have an IPv4 network address.",
1064
                                 network.name)
1065

  
1066
    _MaybeWarn("has an IPv4 gateway", network.gateway, None)
1067
    _MaybeWarn("has a non-standard IPv4 network address", network.network,
1068
               constants.INSTANCE_COMMUNICATION_NETWORK4)
1069
    _MaybeWarn("has an IPv6 gateway", network.gateway6, None)
1070
    _MaybeWarn("has a non-standard IPv6 network address", network.network6,
1071
               constants.INSTANCE_COMMUNICATION_NETWORK6)
1072
    _MaybeWarn("has a non-standard MAC prefix", network.mac_prefix,
1073
               constants.INSTANCE_COMMUNICATION_MAC_PREFIX)
1074

  
1037 1075
  def CheckPrereq(self):
1038 1076
    """Check prerequisites.
1039 1077

  
......
1218 1256
                                   " specified" % self.op.default_iallocator,
1219 1257
                                   errors.ECODE_INVAL)
1220 1258

  
1259
    if self.op.instance_communication_network:
1260
      network_name = self.op.instance_communication_network
1261

  
1262
      try:
1263
        network_uuid = self.cfg.LookupNetwork(network_name)
1264
      except errors.OpPrereqError:
1265
        network_uuid = None
1266

  
1267
      if network_uuid is not None:
1268
        network = self.cfg.GetNetwork(network_uuid)
1269
        self._CheckInstanceCommunicationNetwork(network, self.LogWarning)
1270

  
1221 1271
  def _BuildOSParams(self, cluster):
1222 1272
    "Calculate the new OS parameters for this operation."
1223 1273

  

Also available in: Unified diff