コード例 #1
0
 def testCreateDevicePresentationSpecDefaults(self):
     expected_spec = presentation_specs.ResourcePresentationSpec(
         '--device',
         resource_args.GetDeviceResourceSpec(),
         'The device to test.',
         required=False,
         prefixes=True)
     actual_spec = resource_args.CreateDevicePresentationSpec('to test')
     self.assertEqual(expected_spec, actual_spec)
コード例 #2
0
def AddCreateChannelArg(parser):
    concept_parsers.ConceptParser(
        [
            presentation_specs.ResourcePresentationSpec('channel',
                                                        ChannelResourceSpec(),
                                                        'Channel to create.',
                                                        required=True),
            presentation_specs.ResourcePresentationSpec(
                '--provider',
                ProviderResourceSpec(),
                'Provider to use for the channel.',
                flag_name_overrides={'location': ''})
        ],
        # This configures the fallthrough from the provider's location to the
        # primary flag for the channel's location
        command_level_fallthroughs={
            '--provider.location': ['channel.location']
        }).AddToParser(parser)
コード例 #3
0
  def testTwoResourcesInRuntimeHandler(self):
    """Tests that a runtime handler has two concepts registered."""
    resource = presentation_specs.ResourcePresentationSpec(
        'book',
        self.resource_spec,
        'The book to act upon.',
        prefixes=True)
    other_resource = presentation_specs.ResourcePresentationSpec(
        '--other-book',
        self.resource_spec,
        'The second book to act upon.',
        prefixes=True)

    concept_parser = concept_parsers.ConceptParser([resource, other_resource])
    concept_parser.AddToParser(self.parser)

    self.assertTrue(hasattr(self.parser.data.concept_handler, 'book'))
    self.assertTrue(hasattr(self.parser.data.concept_handler, 'other_book'))
コード例 #4
0
ファイル: delete.py プロジェクト: PrateekKhatri/gcloud_cli
 def CommonArgs(parser):
   service_presentation = presentation_specs.ResourcePresentationSpec(
       'SERVICE',
       resource_args.GetServiceResourceSpec(),
       'Service to delete.',
       required=True,
       prefixes=False)
   concept_parsers.ConceptParser([service_presentation]).AddToParser(parser)
   flags.AddAsyncFlag(parser, default_async_for_cluster=True)
コード例 #5
0
def AddClusterArgToParser(parser):
  cluster_data = yaml_data.ResourceYAMLData.FromPath('vmware.cluster')
  resource_spec = concepts.ResourceSpec.FromYaml(cluster_data.GetData())
  presentation_spec = presentation_specs.ResourcePresentationSpec(
      name='cluster',
      concept_spec=resource_spec,
      required=True,
      group_help='cluster.')
  return concept_parsers.ConceptParser([presentation_spec]).AddToParser(parser)
コード例 #6
0
 def CommonArgs(parser):
     revision_presentation = presentation_specs.ResourcePresentationSpec(
         'REVISION',
         resource_args.GetRevisionResourceSpec(),
         'Revision to delete.',
         required=True,
         prefixes=False)
     concept_parsers.ConceptParser([revision_presentation
                                    ]).AddToParser(parser)
コード例 #7
0
 def CommonArgs(parser):
     domain_mapping_presentation = presentation_specs.ResourcePresentationSpec(
         '--domain',
         resource_args.GetDomainMappingResourceSpec(),
         'Domain name is the ID of DomainMapping resource.',
         required=True,
         prefixes=False)
     concept_parsers.ConceptParser([domain_mapping_presentation
                                    ]).AddToParser(parser)
コード例 #8
0
def AddIPArgToParser(parser):
  ip_address_id = yaml_data.ResourceYAMLData.FromPath('vmware.sddc.ip_address')
  resource_spec = concepts.ResourceSpec.FromYaml(ip_address_id.GetData())
  presentation_spec = presentation_specs.ResourcePresentationSpec(
      name='name',
      concept_spec=resource_spec,
      required=True,
      group_help='ip_address.')
  return concept_parsers.ConceptParser([presentation_spec]).AddToParser(parser)
コード例 #9
0
ファイル: resource_args.py プロジェクト: oarcia/cherrybit.io
def CreateAlertPolicyResourceArg(verb, positional=True):
    if positional:
        name = 'alert_policy'
    else:
        name = '--policy'
    help_text = 'Name of the Alert Policy ' + verb

    return presentation_specs.ResourcePresentationSpec(
        name, GetAlertPolicyResourceSpec(), help_text, required=True)
コード例 #10
0
 def CommonArgs(parser):
     """Defines arguments common to all release tracks."""
     trigger_presentation = presentation_specs.ResourcePresentationSpec(
         'trigger',
         resource_args.GetTriggerResourceSpec(),
         'Name of the trigger to delete',
         required=True)
     concept_parsers.ConceptParser([trigger_presentation
                                    ]).AddToParser(parser)
コード例 #11
0
 def CommonArgs(parser):
     service_presentation = presentation_specs.ResourcePresentationSpec(
         'SERVICE',
         resource_args.GetServiceResourceSpec(),
         'Service to describe.',
         required=True,
         prefixes=False)
     concept_parsers.ConceptParser([service_presentation
                                    ]).AddToParser(parser)
コード例 #12
0
def CreateTopicResourcePresentationSpec(verb, help_text, group):
    """Create add_topic, remove_topic or update_topic specs."""
    name = '--' + verb + '-topic'

    return presentation_specs.ResourcePresentationSpec(name,
                                                       GetTopicResourceSpec(),
                                                       help_text,
                                                       prefixes=True,
                                                       group=group)
コード例 #13
0
ファイル: create.py プロジェクト: bopopescu/GoogleAPI
 def Args(parser):
   reusable_config_group = parser.add_group(
       mutex=True, required=False,
       help='The X.509 configuration used for the CA certificate.')
   concept_parsers.ConceptParser(
       [
           presentation_specs.ResourcePresentationSpec(
               'CERTIFICATE_AUTHORITY',
               privateca_resource_args.CreateCertificateAuthorityResourceSpec(
                   'Certificate Authority'),
               'The name of the root CA to create.',
               required=True,
               # We'll get these from the KMS key resource.
               flag_name_overrides={
                   'location': '',
                   'project': '',
               }),
           presentation_specs.ResourcePresentationSpec(
               '--kms-key-version',
               kms_resource_args.GetKmsKeyVersionResourceSpec(),
               'The KMS key version backing this CA.',
               required=True),
           presentation_specs.ResourcePresentationSpec(
               '--reusable-config',
               privateca_resource_args.CreateReusableConfigResourceSpec(),
               'The Reusable Config containing X.509 values for this CA.',
               flag_name_overrides={
                   'location': '',
                   'project': '',
               },
               group=reusable_config_group)
       ]).AddToParser(parser)
   flags.AddSubjectFlag(parser, required=True)
   flags.AddSubjectAlternativeNameFlags(parser)
   flags.AddPublishCaCertFlag(parser, use_update_help_text=False)
   flags.AddPublishCrlFlag(parser, use_update_help_text=False)
   flags.AddInlineReusableConfigFlags(reusable_config_group, is_ca=True)
   flags.AddValidityFlag(
       parser,
       resource_name='CA',
       default_value='P10Y',
       default_value_text='10 years')
   flags.AddCertificateAuthorityIssuancePolicyFlag(parser)
   labels_util.AddCreateLabelsFlags(parser)
コード例 #14
0
 def Args(parser):
     flags.AddCopyDefaultSecret(parser)
     namespace_presentation = presentation_specs.ResourcePresentationSpec(
         'namespace',
         resource_args.GetCoreNamespaceResourceSpec(),
         'Namespace to copy secret to.',
         required=True,
         prefixes=False)
     concept_parsers.ConceptParser([namespace_presentation
                                    ]).AddToParser(parser)
コード例 #15
0
 def CommonArgs(parser):
     revision_presentation = presentation_specs.ResourcePresentationSpec(
         'REVISION',
         resource_args.GetRevisionResourceSpec(),
         'Revision to delete.',
         required=True,
         prefixes=False)
     concept_parsers.ConceptParser([revision_presentation
                                    ]).AddToParser(parser)
     flags.AddAsyncFlag(parser, default_async_for_cluster=True)
コード例 #16
0
ファイル: delete.py プロジェクト: piotradamczyk5/gcloud_cli
 def Args(parser):
     flags.AddBrokerArg(parser)
     namespace_presentation = presentation_specs.ResourcePresentationSpec(
         '--namespace',
         resource_args.GetCoreNamespaceResourceSpec(),
         'Namespace to create the Broker in.',
         required=True,
         prefixes=False)
     concept_parsers.ConceptParser([namespace_presentation
                                    ]).AddToParser(parser)
コード例 #17
0
  def CommonArgs(parser):
    job_presentation = presentation_specs.ResourcePresentationSpec(
        'JOB',
        resource_args.GetJobResourceSpec(),
        'Job to describe.',
        required=True,
        prefixes=False)
    concept_parsers.ConceptParser([job_presentation]).AddToParser(parser)

    parser.display_info.AddFormat('yaml')
コード例 #18
0
def AddResourceArg(parser, verb):
    """Add a resource argument for a gcpUserAccessBinding.

  Args:
    parser: the parser for the command.
    verb: str, the verb to describe the resource, such as 'to update'.
  """
    concept_parsers.ConceptParser([
        presentation_specs.ResourcePresentationSpec(
            '--binding',
            GetResourceSpec(),
            'The access binding {}.'.format(verb),
            required=True),
        presentation_specs.ResourcePresentationSpec(
            '--level',
            levels.GetResourceSpec(),
            'The access level {}.'.format(verb),
            required=True)
    ]).AddToParser(parser)
コード例 #19
0
 def Args(parser):
   service_presentation = presentation_specs.ResourcePresentationSpec(
       'SERVICE',
       resource_args.GetServiceResourceSpec(prompt=True),
       'Service to update the configuration of.',
       required=True,
       prefixes=False)
   flags.AddAsyncFlag(parser)
   flags.AddUpdateTrafficFlags(parser)
   concept_parsers.ConceptParser([service_presentation]).AddToParser(parser)
コード例 #20
0
 def testResourceArgsInMutexGroup(self):
   """Test a concept parser with two resource args."""
   group = self.parser.add_group('A group', mutex=True)
   resource = presentation_specs.ResourcePresentationSpec(
       'book',
       self.resource_spec,
       'The book to act upon.',
       group=group,
       prefixes=True)
   other_resource = presentation_specs.ResourcePresentationSpec(
       '--other',
       self.resource_spec,
       'The second book to act upon.',
       group=group,
       prefixes=True)
   concept_parsers.ConceptParser([resource, other_resource]).AddToParser(
       self.parser)
   with self.AssertRaisesArgumentErrorMatches('At most one of'):
     self.parser.parser.parse_args(['example', '--other', 'otherexample'])
コード例 #21
0
    def ForResource(cls,
                    name,
                    resource_spec,
                    group_help,
                    required=False,
                    flag_name_overrides=None,
                    plural=False,
                    prefixes=False,
                    group=None,
                    command_level_fallthroughs=None):
        """Constructs a ConceptParser for a single resource argument.

    Automatically sets prefixes to False.

    Args:
      name: str, the name of the main arg for the resource.
      resource_spec: googlecloudsdk.calliope.concepts.ResourceSpec, The spec
        that specifies the resource.
      group_help: str, the help text for the entire arg group.
      required: bool, whether the main argument should be required for the
        command.
      flag_name_overrides: {str: str}, dict of attribute names to the desired
        flag name. To remove a flag altogether, use '' as its rename value.
      plural: bool, True if the resource will be parsed as a list, False
        otherwise.
      prefixes: bool, True if flag names will be prefixed with the resource
        name, False otherwise. Should be False for all typical use cases.
      group: the parser or subparser for a Calliope command that the resource
        arguments should be added to. If not provided, will be added to the main
        parser.
      command_level_fallthroughs: a map of attribute names to lists of command-
        specific fallthroughs. These will be prioritized over the default
        fallthroughs for the attribute.

    Returns:
      (googlecloudsdk.calliope.concepts.concept_parsers.ConceptParser) The fully
        initialized ConceptParser.
    """
        presentation_spec = presentation_specs.ResourcePresentationSpec(
            name,
            resource_spec,
            group_help,
            required=required,
            flag_name_overrides=flag_name_overrides or {},
            plural=plural,
            prefixes=prefixes,
            group=group)
        fallthroughs_map = {}
        UpdateFallthroughsMap(fallthroughs_map, name,
                              command_level_fallthroughs)
        for attribute_name, fallthroughs in six.iteritems(
                command_level_fallthroughs or {}):
            key = '{}.{}'.format(presentation_spec.name, attribute_name)
            fallthroughs_map[key] = fallthroughs
        return cls([presentation_spec], fallthroughs_map)
コード例 #22
0
    def RunResourceCompleter(self,
                             resource_spec,
                             attribute_name,
                             prefix='',
                             expected_completions=None,
                             args=None,
                             presentation_name=None,
                             dest=None,
                             flag_name_overrides=None,
                             projects=None):
        """Run a test of a resource completer.

    Args:
      resource_spec: googlecloudsdk.calliope.concepts.concepts.ResourceSpec,
        the resource spec.
      attribute_name: str, the name of the attribute.
      prefix: str, the value to be completed if any. Defaults to ''.
      expected_completions: [str], the list of expected results if any.
      args: {str: str}, a dict of args to be parsed into the mock namespace.
      presentation_name: str, the name of the presentation spec. Defaults to
        the resource name (i.e. a positional arg).
      dest: str, the name of the argument for which completion is running.
        Defaults to the name of the attribute.
      flag_name_overrides: {str: str} | None, the flag name overrides for the
        presentation spec, if any.
      projects: [str], a list of project IDs to be returned by a list projects
        call if the project argument needs to be completed. If None, no list
        projects call is expected.
    """
        args = args or {}
        flag_name_overrides = flag_name_overrides or {}
        presentation_name = presentation_name or resource_spec.name
        dest = dest or attribute_name
        expected_completions = expected_completions or []
        presentation_spec = presentation_specs.ResourcePresentationSpec(
            presentation_name,
            resource_spec,
            'Help text',
            prefixes=False,
            flag_name_overrides=flag_name_overrides)
        resource_info = concept_parsers.ConceptParser(
            [presentation_spec]).GetInfo(presentation_spec.name)
        if projects is not None:
            self._ExpectListProjects(projects)

        completer = self.Completer(completers.CompleterForAttribute(
            resource_spec, attribute_name),
                                   args=args,
                                   handler_info=resource_info,
                                   cli=self.cli)
        argument = mock.MagicMock(dest=dest)
        parameter_info = completer.ParameterInfo(self.parsed_args, argument)

        completions = completer.Complete(prefix, parameter_info)
        self.assertEqual(expected_completions, completions)
コード例 #23
0
ファイル: delete.py プロジェクト: Akiho-Yasuda/wip
 def Args(parser):
     flags.AddRegionArg(parser)
     revision_presentation = presentation_specs.ResourcePresentationSpec(
         'REVISION',
         resource_args.GetRevisionResourceSpec(),
         'Revision to delete.',
         required=True,
         prefixes=False)
     concept_parsers.ConceptParser(
         [resource_args.CLUSTER_PRESENTATION,
          revision_presentation]).AddToParser(parser)
コード例 #24
0
ファイル: describe.py プロジェクト: osakipokima/Social-Lite
 def CommonArgs(parser):
   """Defines arguments common to all release tracks."""
   trigger_presentation = presentation_specs.ResourcePresentationSpec(
       'trigger',
       resource_args.GetTriggerResourceSpec(),
       'Name of the trigger to delete',
       required=True)
   concept_parsers.ConceptParser([trigger_presentation]).AddToParser(parser)
   parser.display_info.AddFormat("""multi[separator='\n'](
       serialized_trigger:format="yaml",
       serialized_source:format="yaml(spec)")""")
コード例 #25
0
 def Args(parser):
   flags.AddRegionArg(parser)
   domain_mapping_presentation = presentation_specs.ResourcePresentationSpec(
       '--domain',
       resource_args.GetDomainMappingResourceSpec(),
       'Domain name is the ID of DomainMapping resource.',
       required=True,
       prefixes=False)
   concept_parsers.ConceptParser([
       resource_args.CLUSTER_PRESENTATION,
       domain_mapping_presentation]).AddToParser(parser)
コード例 #26
0
ファイル: delete.py プロジェクト: aklomkaew/lets-help-123
 def Args(parser):
     flags.AddRegionArg(parser)
     service_presentation = presentation_specs.ResourcePresentationSpec(
         'SERVICE',
         resource_args.GetServiceResourceSpec(),
         'Service to delete.',
         required=True,
         prefixes=False)
     concept_parsers.ConceptParser(
         [resource_args.CLUSTER_PRESENTATION,
          service_presentation]).AddToParser(parser)
コード例 #27
0
    def CommonArgs(parser):
        configuration_presentation = presentation_specs.ResourcePresentationSpec(
            'CONFIGURATION',
            resource_args.GetConfigurationResourceSpec(),
            'Configuration to describe.',
            required=True,
            prefixes=False)
        concept_parsers.ConceptParser([configuration_presentation
                                       ]).AddToParser(parser)

        parser.display_info.AddFormat('yaml')
コード例 #28
0
    def CommonArgs(parser):
        # Flags not specific to any platform
        route_presentation = presentation_specs.ResourcePresentationSpec(
            'ROUTE',
            resource_args.GetRouteResourceSpec(),
            'Route to describe.',
            required=True,
            prefixes=False)
        concept_parsers.ConceptParser([route_presentation]).AddToParser(parser)

        parser.display_info.AddFormat('yaml')
コード例 #29
0
def AddOperationArgToParser(parser):
    """Sets up an argument for the operation resource."""
    operation_data = yaml_data.ResourceYAMLData.FromPath('vmware.operation')
    resource_spec = concepts.ResourceSpec.FromYaml(operation_data.GetData())
    presentation_spec = presentation_specs.ResourcePresentationSpec(
        name='operation',
        concept_spec=resource_spec,
        required=True,
        group_help='operation.')
    return concept_parsers.ConceptParser([presentation_spec
                                          ]).AddToParser(parser)
コード例 #30
0
 def testPresentationSpecValidatesFlagNameOverrides(self):
   """Test error is raised if an incorrect attribute name is provided."""
   with self.AssertRaisesExceptionMatches(
       ValueError,
       'Attempting to override the name for an attribute not present in the '
       'concept: [booksId]. Available attributes: [project, shelf, book]'):
     presentation_specs.ResourcePresentationSpec(
         '--book',
         self.resource_spec,
         'The book',
         flag_name_overrides={'booksId': '--book-flag'})