コード例 #1
0
 def testTierAndCustomMachineSpecified(self):
     args = self.parser.parse_args(
         '--tier D0 --cpu 2 --memory 1024MiB'.split())
     try:
         reducers.MachineType(tier=args.tier,
                              memory=args.memory,
                              cpu=args.cpu)
     except exceptions.InvalidArgumentException:
         assert True
コード例 #2
0
  def _ConstructBaseSettingsFromArgs(cls,
                                     sql_messages,
                                     args,
                                     instance=None,
                                     release_track=DEFAULT_RELEASE_TRACK):
    """Constructs instance settings from the command line arguments.

    Args:
      sql_messages: module, The messages module that should be used.
      args: argparse.Namespace, The arguments that this command was invoked
          with.
      instance: sql_messages.DatabaseInstance, The original instance, for
          settings that depend on the previous state.
      release_track: base.ReleaseTrack, the release track that this was run
          under.

    Returns:
      A settings object representing the instance settings.

    Raises:
      ToolException: An error other than http error occurred while executing the
          command.
    """
    settings = sql_messages.Settings(
        tier=reducers.MachineType(instance, args.tier, args.memory, args.cpu),
        pricingPlan=args.pricing_plan,
        replicationType=args.replication,
        activationPolicy=_ParseActivationPolicy(args.activation_policy))

    if args.authorized_gae_apps:
      settings.authorizedGaeApplications = args.authorized_gae_apps

    if any([
        args.assign_ip is not None, args.require_ssl is not None,
        args.authorized_networks
    ]):
      settings.ipConfiguration = sql_messages.IpConfiguration()
      if args.assign_ip is not None:
        cls.SetIpConfigurationEnabled(settings, args.assign_ip)

      if args.authorized_networks:
        cls.SetAuthorizedNetworks(settings, args.authorized_networks,
                                  sql_messages.AclEntry)

      if args.require_ssl is not None:
        settings.ipConfiguration.requireSsl = args.require_ssl

    if any([args.follow_gae_app, _GetZone(args)]):
      settings.locationPreference = sql_messages.LocationPreference(
          followGaeApplication=args.follow_gae_app, zone=_GetZone(args))

    if args.storage_size:
      settings.dataDiskSizeGb = int(args.storage_size / constants.BYTES_TO_GB)

    if args.storage_auto_increase is not None:
      settings.storageAutoResize = args.storage_auto_increase

    if args.IsSpecified('availability_type'):
      settings.availabilityType = args.availability_type.upper()

    # BETA args.
    if _IsBetaOrNewer(release_track):
      if args.IsSpecified('storage_auto_increase_limit'):
        # Resize limit should be settable if the original instance has resize
        # turned on, or if the instance to be created has resize flag.
        if (instance and instance.settings.storageAutoResize) or (
            args.storage_auto_increase):
          # If the limit is set to None, we want it to be set to 0. This is a
          # backend requirement.
          settings.storageAutoResizeLimit = (args.storage_auto_increase_limit or
                                             0)
        else:
          raise exceptions.RequiredArgumentException(
              '--storage-auto-increase', 'To set the storage capacity limit '
              'using [--storage-auto-increase-limit], '
              '[--storage-auto-increase] must be enabled.')

      if args.IsSpecified('network'):
        if not settings.ipConfiguration:
          settings.ipConfiguration = sql_messages.IpConfiguration()
        settings.ipConfiguration.privateNetwork = reducers.PrivateNetworkUrl(
            args.network)

    return settings
コード例 #3
0
 def testNoMemorySpecified(self):
     args = self.parser.parse_args('--cpu 2'.split())
     try:
         reducers.MachineType(cpu=args.cpu)
     except exceptions.RequiredArgumentException:
         assert True
コード例 #4
0
 def testNoCPUSpecified(self):
     args = self.parser.parse_args('--memory 1024MiB'.split())
     try:
         reducers.MachineType(memory=args.memory)
     except exceptions.RequiredArgumentException:
         assert True
コード例 #5
0
 def testExistingInstanceDefaultValue(self):
     instance = object()
     self.assertEqual(None, reducers.MachineType(instance))
コード例 #6
0
 def testNoInstanceDefaultValue(self):
     self.assertEqual('db-n1-standard-1', reducers.MachineType())
コード例 #7
0
 def testCustomMemoryAndCpu(self):
     args = self.parser.parse_args('--cpu 1 --memory 1024MiB'.split())
     self.assertEqual(
         'db-custom-1-1024',
         reducers.MachineType(memory=args.memory, cpu=args.cpu))
コード例 #8
0
 def testTier(self):
     args = self.parser.parse_args('--tier D0'.split())
     self.assertEqual('D0', reducers.MachineType(tier=args.tier))
コード例 #9
0
ファイル: instances.py プロジェクト: bopopescu/deep-learning
    def _ConstructSettingsFromArgs(cls, sql_messages, args, instance=None):
        """Constructs instance settings from the command line arguments.

    Args:
      sql_messages: module, The messages module that should be used.
      args: argparse.Namespace, The arguments that this command was invoked
          with.
      instance: sql_messages.DatabaseInstance, The original instance, for
          settings that depend on the previous state.

    Returns:
      A settings object representing the instance settings.

    Raises:
      ToolException: An error other than http error occured while executing the
          command.
    """
        settings = sql_messages.Settings(
            tier=reducers.MachineType(instance, args.tier, args.memory,
                                      args.cpu),
            pricingPlan=args.pricing_plan,
            replicationType=args.replication,
            activationPolicy=args.activation_policy)

        labels = None
        if hasattr(args, 'labels'):
            labels = reducers.UserLabels(sql_messages,
                                         instance,
                                         labels=args.labels)
        elif (hasattr(args, 'update_labels') and args.update_labels
              or hasattr(args, 'remove_labels') and args.remove_labels):
            update_labels, remove_labels = labels_util.GetAndValidateOpsFromArgs(
                args)
            labels = reducers.UserLabels(sql_messages,
                                         instance,
                                         update_labels=update_labels,
                                         remove_labels=remove_labels)
        elif hasattr(args, 'clear_labels'):
            labels = reducers.UserLabels(sql_messages,
                                         instance,
                                         clear_labels=args.clear_labels)
        if labels:
            settings.userLabels = labels

        # these args are only present for the patch command
        clear_authorized_networks = getattr(args, 'clear_authorized_networks',
                                            False)
        clear_gae_apps = getattr(args, 'clear_gae_apps', False)

        if args.authorized_gae_apps:
            settings.authorizedGaeApplications = args.authorized_gae_apps
        elif clear_gae_apps:
            settings.authorizedGaeApplications = []

        if any([
                args.assign_ip is not None, args.require_ssl is not None,
                args.authorized_networks, clear_authorized_networks
        ]):
            settings.ipConfiguration = sql_messages.IpConfiguration()
            if args.assign_ip is not None:
                if hasattr(settings.ipConfiguration, 'enabled'):
                    # v1beta3 is being used; use 'enabled' instead of 'ipv4Enabled'.
                    settings.ipConfiguration.enabled = args.assign_ip
                else:
                    settings.ipConfiguration.ipv4Enabled = args.assign_ip

            if args.authorized_networks:
                # AclEntry is only available in the v1beta4 version of the API. If it is
                # present, the API expects an AclEntry for the authorizedNetworks list;
                # otherwise, it expects a string.
                if getattr(sql_messages, 'AclEntry', None) is not None:
                    authorized_networks = [
                        sql_messages.AclEntry(value=n)
                        for n in args.authorized_networks
                    ]
                else:
                    authorized_networks = args.authorized_networks
                settings.ipConfiguration.authorizedNetworks = authorized_networks
            if clear_authorized_networks:
                # For patch requests, this field needs to be labeled explicitly cleared.
                settings.ipConfiguration.authorizedNetworks = []

            if args.require_ssl is not None:
                settings.ipConfiguration.requireSsl = args.require_ssl

        if any([args.follow_gae_app, args.gce_zone]):
            settings.locationPreference = sql_messages.LocationPreference(
                followGaeApplication=args.follow_gae_app, zone=args.gce_zone)

        if getattr(args, 'enable_database_replication', None) is not None:
            settings.databaseReplicationEnabled = args.enable_database_replication

        return settings