コード例 #1
0
def NewAPIAdapter():
  """Initialize an api adapter for the given api_version.

  Returns:
    APIAdapter object.
  """
  api_client = core_apis.GetClientInstance('container', 'v1')
  api_client.check_response_func = CheckResponse
  messages = core_apis.GetMessagesModule('container', 'v1')

  api_compute_client = core_apis.GetClientInstance('compute', 'v1')
  api_compute_client.check_response_func = CheckResponse
  compute_messages = core_apis.GetMessagesModule('compute', 'v1')

  registry = cloud_resources.REGISTRY.CloneAndSwitchAPIs(
      api_client, api_compute_client)

  adapter = V1Adapter

  registry.SetParamDefault(
      api='compute', collection=None, param='project',
      resolver=resolvers.FromProperty(properties.VALUES.core.project))
  registry.SetParamDefault(
      api='container', collection=None, param='projectId',
      resolver=resolvers.FromProperty(properties.VALUES.core.project))
  registry.SetParamDefault(
      api='container', collection=None, param='zone',
      resolver=resolvers.FromProperty(properties.VALUES.compute.zone))

  return adapter(registry, api_client, messages, api_compute_client,
                 compute_messages)
コード例 #2
0
    def Filter(self, context, args):
        """Context() is a filter function that can update the context.

    Args:
      context: The current context.
      args: The argparse namespace that was specified on the CLI or API.

    Returns:
      The updated context.
    """
        properties.VALUES.compute.zone.Get(required=True)
        resources.REGISTRY.SetParamDefault(api='compute',
                                           collection=None,
                                           param='project',
                                           resolver=resolvers.FromProperty(
                                               properties.VALUES.core.project))
        resources.REGISTRY.SetParamDefault(api='compute',
                                           collection=None,
                                           param='zone',
                                           resolver=resolvers.FromProperty(
                                               properties.VALUES.compute.zone))
        resources.REGISTRY.SetParamDefault(api='replicapoolupdater',
                                           collection=None,
                                           param='project',
                                           resolver=resolvers.FromProperty(
                                               properties.VALUES.core.project))
        resources.REGISTRY.SetParamDefault(api='replicapoolupdater',
                                           collection=None,
                                           param='zone',
                                           resolver=resolvers.FromProperty(
                                               properties.VALUES.compute.zone))
        return context
コード例 #3
0
    def Filter(self, context, args):
        context['dataproc_messages'] = apis.GetMessagesModule('dataproc', 'v1')
        context['resources'] = resources.REGISTRY

        # TODO(user): Move outside of context in a place that will be easier to
        # convert into a property when there are multiple regions.
        context['dataproc_region'] = self.REGION
        context['dataproc_client'] = apis.GetClientInstance('dataproc', 'v1')

        resources.REGISTRY.SetParamDefault(api='dataproc',
                                           collection=None,
                                           param='projectId',
                                           resolver=resolvers.FromProperty(
                                               properties.VALUES.core.project))
        resources.REGISTRY.SetParamDefault(
            api='dataproc',
            collection=None,
            param='region',
            resolver=lambda: context['dataproc_region'])

        # These two properties are artifacts of how our Operations API get
        # converted into generated libraries.
        resources.REGISTRY.SetParamDefault(api='dataproc',
                                           collection=None,
                                           param='projectsId',
                                           resolver=resolvers.FromProperty(
                                               properties.VALUES.core.project))
        resources.REGISTRY.SetParamDefault(
            api='dataproc',
            collection=None,
            param='regionsId',
            resolver=lambda: context['dataproc_region'])

        return context
コード例 #4
0
  def Filter(self, context, args):
    """Context() is a filter function that can update the context.

    Args:
      context: The current context.
      args: The argparse namespace that was specified on the CLI or API.

    Returns:
      The updated context.
    """
    properties.VALUES.compute.zone.Get(required=True)
    context['updater_api'] = core_apis.GetClientInstance(
        'replicapoolupdater', 'v1beta1')
    context['updater_messages'] = core_apis.GetMessagesModule(
        'replicapoolupdater', 'v1beta1')
    resources.SetParamDefault(
        api='compute', collection=None, param='project',
        resolver=resolvers.FromProperty(properties.VALUES.core.project))
    resources.SetParamDefault(
        api='compute', collection=None, param='zone',
        resolver=resolvers.FromProperty(properties.VALUES.compute.zone))
    resources.SetParamDefault(
        api='replicapoolupdater', collection=None, param='project',
        resolver=resolvers.FromProperty(properties.VALUES.core.project))
    resources.SetParamDefault(
        api='replicapoolupdater', collection=None, param='zone',
        resolver=resolvers.FromProperty(properties.VALUES.compute.zone))
    context['updater_resources'] = resources
    return context
コード例 #5
0
    def Filter(self, context, args):
        """Initialize context for source commands.

    Args:
      context: The current context.
      args: The argparse namespace that was specified on the CLI or API.

    Returns:
      The updated context.
    """
        resources.REGISTRY.SetParamDefault(api='source',
                                           collection=None,
                                           param='projectId',
                                           resolver=resolvers.FromProperty(
                                               properties.VALUES.core.project))
        resources.REGISTRY.SetParamDefault(api='sourcerepo',
                                           collection=None,
                                           param='projectId',
                                           resolver=resolvers.FromProperty(
                                               properties.VALUES.core.project))

        source.Source.SetResourceParser(resources.REGISTRY)
        source.Source.SetApiEndpoint()
        sourcerepo.Source.SetResourceParser(resources.REGISTRY)
        sourcerepo.Source.SetApiEndpoint()
コード例 #6
0
    def Filter(self, context, args):
        client = core_apis.GetClientInstance('autoscaler', 'v1beta2')
        context['autoscaler-client'] = client

        messages_v2 = core_apis.GetMessagesModule('autoscaler', 'v1beta2')
        context['autoscaler_messages_module'] = messages_v2

        resources.SetParamDefault(api='compute',
                                  collection=None,
                                  param='project',
                                  resolver=resolvers.FromProperty(
                                      properties.VALUES.core.project))
        resources.SetParamDefault(api='autoscaler',
                                  collection=None,
                                  param='project',
                                  resolver=resolvers.FromProperty(
                                      properties.VALUES.core.project))
        resources.SetParamDefault(api='autoscaler',
                                  collection=None,
                                  param='zone',
                                  resolver=resolvers.FromProperty(
                                      properties.VALUES.compute.zone))
        resources.SetParamDefault(api='replicapool',
                                  collection=None,
                                  param='project',
                                  resolver=resolvers.FromProperty(
                                      properties.VALUES.core.project))
        resources.SetParamDefault(api='replicapool',
                                  collection=None,
                                  param='zone',
                                  resolver=resolvers.FromProperty(
                                      properties.VALUES.compute.zone))

        context['autoscaler_resources'] = resources
        return context
コード例 #7
0
    def Filter(self, context, args):
        client = autoscaler_v1beta2.AutoscalerV1beta2(get_credentials=False,
                                                      http=self.Http())
        context['autoscaler_messages_module'] = messages_v2

        context['autoscaler-client'] = client
        resources.SetParamDefault(api='compute',
                                  collection=None,
                                  param='project',
                                  resolver=resolvers.FromProperty(
                                      properties.VALUES.core.project))
        resources.SetParamDefault(api='autoscaler',
                                  collection=None,
                                  param='project',
                                  resolver=resolvers.FromProperty(
                                      properties.VALUES.core.project))
        resources.SetParamDefault(api='autoscaler',
                                  collection=None,
                                  param='zone',
                                  resolver=resolvers.FromProperty(
                                      properties.VALUES.compute.zone))
        resources.SetParamDefault(api='replicapool',
                                  collection=None,
                                  param='project',
                                  resolver=resolvers.FromProperty(
                                      properties.VALUES.core.project))
        resources.SetParamDefault(api='replicapool',
                                  collection=None,
                                  param='zone',
                                  resolver=resolvers.FromProperty(
                                      properties.VALUES.compute.zone))

        context['autoscaler_resources'] = resources
        return context
コード例 #8
0
    def Filter(self, context, args):
        """Modify the context that will be given to this group's commands when run.

    Args:
      context: {str:object}, The current context, which is a set of key-value
          pairs that can be used for common initialization among commands.
      args: argparse.Namespace: The same Namespace given to the corresponding
          .Run() invocation.

    Returns:
      The refined command context.
    """
        http = self.Http()
        testing_url = properties.VALUES.api_endpoint_overrides.testing.Get()
        toolresults_url = properties.VALUES.api_endpoint_overrides.toolresults.Get(
        )
        log.info('Test Service endpoint: [{0}]'.format(testing_url))
        log.info('Tool Results endpoint: [{0}]'.format(toolresults_url))

        # Create the Testing service client
        resources.SetParamDefault(api='test',
                                  collection=None,
                                  param='project',
                                  resolver=resolvers.FromProperty(
                                      properties.VALUES.core.project))
        # TODO(user) Support multiple versions when they exist
        testing_client_v1 = testing_v1.TestingV1(get_credentials=False,
                                                 url=testing_url,
                                                 http=http)
        testing_registry = resources.REGISTRY.CloneAndSwitchAPIs(
            testing_client_v1)
        context['testing_client'] = testing_client_v1
        context['testing_messages'] = testing_v1
        context['testing_registry'] = testing_registry

        # Create the Tool Results service client.
        resources.SetParamDefault(api='toolresults',
                                  collection=None,
                                  param='project',
                                  resolver=resolvers.FromProperty(
                                      properties.VALUES.core.project))
        toolresults_client_v1 = toolresults_v1beta3.ToolresultsV1beta3(
            get_credentials=False, url=toolresults_url, http=http)
        tr_registry = resources.REGISTRY.CloneAndSwitchAPIs(
            toolresults_client_v1)
        context['toolresults_client'] = toolresults_client_v1
        context['toolresults_messages'] = toolresults_v1beta3
        context['toolresults_registry'] = tr_registry

        # Get the android catalog and store in the context
        context['android_catalog'] = util.GetAndroidCatalog(context)

        # TODO(user): remove this message for general release.
        log.status.Print(
            '\nHave questions, feedback, or issues? Please let us know by using '
            'this Google Group:\n  https://groups.google.com/forum/#!forum'
            '/google-cloud-test-lab-external\n')

        return context
コード例 #9
0
ファイル: api_adapter.py プロジェクト: bopopescu/8220-lab
def NewAPIAdapter(api_version, endpoint_url, compute_endpoint_url, http):
    """Initialize an api adapter for the given api_version.

  Args:
    api_version: str, version to create api adapter for.
    endpoint_url: str, endpoint url for the api client.
    compute_endpoint_url: str, endpoint url for the compute api client.
    http: httplib2.Http object for api client to use.

  Returns:
    APIAdapter object.
  """
    if api_version == 'v1':
        api = container_v1
        api_compute = compute_v1
        api_client = api.ContainerV1
        api_compute_client = api_compute.ComputeV1
        zone_field = 'zone'
        adapter = V1Adapter
    else:
        raise exceptions.InvalidArgumentException(
            'api_client_overrides/container',
            '{0} is not a valid api version'.format(api_version))

    api_client = api_client(url=endpoint_url, get_credentials=False, http=http)
    api_client.check_response_func = CheckResponse
    api_compute_client = api_compute_client(url=compute_endpoint_url,
                                            get_credentials=False,
                                            http=http)
    api_compute_client.check_response_func = CheckResponse
    messages = api
    compute_messages = api_compute
    registry = cloud_resources.REGISTRY.CloneAndSwitchAPIs(
        api_client, api_compute_client)
    registry.SetParamDefault(api='compute',
                             collection=None,
                             param='project',
                             resolver=resolvers.FromProperty(
                                 properties.VALUES.core.project))
    registry.SetParamDefault(api='container',
                             collection=None,
                             param='projectId',
                             resolver=resolvers.FromProperty(
                                 properties.VALUES.core.project))
    registry.SetParamDefault(api='container',
                             collection=None,
                             param=zone_field,
                             resolver=resolvers.FromProperty(
                                 properties.VALUES.compute.zone))

    return adapter(api_version, registry, api_client, messages,
                   api_compute_client, compute_messages)
コード例 #10
0
 def FromContext(cls, context):
     """Updates required global state and constructs ConfigurationHelper."""
     holder = compute_base.ComputeApiHolder(base.ReleaseTrack.GA)
     batch_url = holder.client.batch_url
     compute = holder.client.apitools_client
     resources = holder.resources
     zone_prop = properties.VALUES.compute.zone
     project_prop = properties.VALUES.core.project
     project = project_prop.Get(required=True)
     resources.SetParamDefault('compute', None, 'project',
                               resolvers.FromProperty(project_prop))
     resources.SetParamDefault('compute', None, 'zone',
                               resolvers.FromProperty(zone_prop))
     return cls(batch_url, compute, project, resources)
コード例 #11
0
 def FromContext(cls, context):
     """Updates required global state and constructs ConfigurationHelper."""
     http = context['http']
     compute_utils.UpdateContextEndpointEntries(context, http)
     batch_url = context['batch-url']
     compute = context['compute']
     resources = context['resources']
     zone_prop = properties.VALUES.compute.zone
     project_prop = properties.VALUES.core.project
     project = project_prop.Get(required=True)
     resources.SetParamDefault('compute', None, 'project',
                               resolvers.FromProperty(project_prop))
     resources.SetParamDefault('compute', None, 'zone',
                               resolvers.FromProperty(zone_prop))
     return cls(batch_url, compute, http, project, resources)
コード例 #12
0
ファイル: __init__.py プロジェクト: eduardofacanha/Robin
 def __init__(self):
     project = properties.VALUES.core.project
     resolver = resolvers.FromProperty(project)
     resources.REGISTRY.SetParamDefault('spanner',
                                        collection=None,
                                        param='projectsId',
                                        resolver=resolver)
コード例 #13
0
ファイル: __init__.py プロジェクト: AlexisMarie8330/Doll
 def Filter(self, context, args):
     project = properties.VALUES.core.project
     resolver = resolvers.FromProperty(project)
     resources.REGISTRY.SetParamDefault('bigtableadmin',
                                        collection=None,
                                        param='projectsId',
                                        resolver=resolver)
コード例 #14
0
    def Filter(self, context, args):
        """Context() is a filter function that can update the context.

    Args:
      context: The current context.
      args: The argparse namespace that was specified on the CLI or API.

    Returns:
      The updated context.
    Raises:
      ToolException: When no project is specified.
    """

        client = apis.GetClientInstance('serviceregistry', 'v1alpha')
        context[constants.CLIENT] = client
        context[constants.MESSAGES] = apis.GetMessagesModule(
            'serviceregistry', 'v1alpha')

        project = properties.VALUES.core.project
        resolver = resolvers.FromProperty(project)
        resources.REGISTRY.SetParamDefault('serviceregistry', None, 'project',
                                           resolver)
        # guarantee we use the same API as our client
        context[constants.RESOURCES] = resources.REGISTRY.CloneAndSwitchAPIs(
            client)

        return context
コード例 #15
0
  def Filter(self, context, args):
    """Context() is a filter function that can update the context.

    Args:
      context: The current context.
      args: The argparse namespace that was specified on the CLI or API.

    Returns:
      The updated context.
    Raises:
      ToolException: When no project is specified.
    """

    api_name = 'serviceregistry'
    api_version = 'v1alpha'
    context[constants.CLIENT] = apis.GetClientInstance(api_name, api_version)
    context[constants.MESSAGES] = apis.GetMessagesModule(api_name, api_version)

    project = properties.VALUES.core.project
    resolver = resolvers.FromProperty(project)

    registry = resources.REGISTRY.Clone()
    registry.SetParamDefault('serviceregistry', None, 'project', resolver)
    registry.RegisterApiByName(api_name, api_version)

    context[constants.RESOURCES] = registry

    return context
コード例 #16
0
ファイル: __init__.py プロジェクト: phrayezzen/media-database
def _DoFilter(context, api_version, http):
    """Set up and return the context to be used by all SQL release tracks."""
    cloud_resources.SetParamDefault(api='sql',
                                    collection=None,
                                    param='project',
                                    resolver=resolvers.FromProperty(
                                        properties.VALUES.core.project))

    url = '/'.join([properties.VALUES.core.api_host.Get(), 'sql'])

    context['sql_client-v1beta3'] = sql_v1beta3.SqladminV1beta3(
        get_credentials=False, url='/'.join([url, 'v1beta3']), http=http)
    context['sql_messages-v1beta3'] = sql_v1beta3
    context['registry-v1beta3'] = cloud_resources.REGISTRY.CloneAndSwitchAPIs(
        context['sql_client-v1beta3'])

    context['sql_client-v1beta4'] = sql_v1beta4.SqladminV1beta4(
        get_credentials=False, url='/'.join([url, 'v1beta4']), http=http)
    context['sql_messages-v1beta4'] = sql_v1beta4
    context['registry-v1beta4'] = cloud_resources.REGISTRY.CloneAndSwitchAPIs(
        context['sql_client-v1beta4'])

    context['sql_client'] = context['sql_client-' + api_version]
    context['sql_messages'] = context['sql_messages-' + api_version]
    context['registry'] = context['registry-' + api_version]

    return context
コード例 #17
0
ファイル: __init__.py プロジェクト: bopopescu/packmybot
    def Filter(self, context, args):
        """Modify the context that will be given to this group's commands when run.

    Args:
      context: The current context.
      args: The argparse namespace given to the corresponding .Run() invocation.

    Returns:
      The updated context.
    """
        url = properties.VALUES.api_endpoint_overrides.logging.Get()

        # All logging collections use projectId, so we can set a default value.
        resources.SetParamDefault(api='logging',
                                  collection=None,
                                  param='projectsId',
                                  resolver=resolvers.FromProperty(
                                      properties.VALUES.core.project))

        client_v1beta3 = v1beta3.LoggingV1beta3(url=url,
                                                http=self.Http(),
                                                get_credentials=False)

        context['logging_client'] = client_v1beta3
        context['logging_messages'] = v1beta3
        context['logging_resources'] = resources
        return context
コード例 #18
0
  def Filter(self, context, args):
    """Modify the context that will be given to this group's commands when run.

    Args:
      context: The current context.
      args: The argparse namespace given to the corresponding .Run() invocation.

    Returns:
      The updated context.
    """
    # All logging collections use projectId, so we can set a default value.
    resources.SetParamDefault(
        api='logging', collection=None, param='projectsId',
        resolver=resolvers.FromProperty(properties.VALUES.core.project))

    context['logging_client_v1beta3'] = apis.GetClientInstance(
        'logging', 'v1beta3')
    context['logging_messages_v1beta3'] = apis.GetMessagesModule(
        'logging', 'v1beta3')

    context['logging_client_v2beta1'] = apis.GetClientInstance(
        'logging', 'v2beta1')
    context['logging_messages_v2beta1'] = apis.GetMessagesModule(
        'logging', 'v2beta1')

    context['logging_resources'] = resources
    return context
コード例 #19
0
def ParseRegionDisksResources(resources, disks, replica_zones, project,
                              region):
  """Parse disks arguments taking into account project, region and zones.

  Try to deduce --region from --replica-zones and parse disk references:
  0. parse --project
  1. parse --region falling back to 0 for project
  2. for each disk:
   2.1. parse disk falling back to 0 and 1 falling back to property if necessary
   2.2. extract disk project from 2.1
   2.3. parse --replica-zones falling back to 2.2
   2.4. check zones are in disk project
   2.5. check zones are from the same region
   2.6. if --region is present, check if equal to 2.5
   2.7. parse disk falling back to 2.2 and 2.5
   2.8. check if disk is in 2.5 region
   2.9. yield 2.7

  Function is greedy - checks/deduces/parses all data before returning. If any
  error occurs, exception is raised.

  Args:
    resources: resources.Registry: resource parser
    disks: str, parsed disks argument (args.DISK_NAME)
    replica_zones: str, parsed --replica-zones flag (args.replica_zones)
    project: str, parsed --project flag or None (args.project)
    region: str, parsed --region flag or None (args.region)

  Returns:
    List disk resources [compute.regionDisks]
  """
  result_disks = []
  project_to_region = {}  # cache
  dummy = '$DUMMY$'  # shouldn't escape from this function

  # --project may be provided or not, URI should be accepted
  project_res = resources.Parse(
      project, collection='compute.projects', params={'project': dummy})
  project_name = project_res.project
  # --region may be provided or not, URI should be accepted
  # project embedded in URI takes precedence over project_res
  region_res = resources.Parse(
      region,
      collection='compute.regions',
      params={'project': project_name,
              'region': dummy})
  if region_res.project != project_name:
    project_name = region_res.project
  region_name = region_res.region
  if project_name == dummy:
    # no project in --project nor --region - fallback to property
    project_name = resolvers.FromProperty(properties.VALUES.core.project)
  # parse each disk separately as meaning of other flags may depend on disk URI
  for disk in disks:
    result_disk = _ParseDisk(resources, disk, dummy, project_name,
                             project_to_region, region, region_name,
                             replica_zones)
    result_disks.append(result_disk)

  return result_disks
コード例 #20
0
ファイル: __init__.py プロジェクト: bopopescu/brydzenie
def _DoFilter(context, http, api_version_default, api_version_arg):
    """Set up and return the context to be used by all SQL release tracks."""

    api_version = api_version_default
    if properties.VALUES.api_client_overrides.sql.Get():
        api_version = properties.VALUES.api_client_overrides.sql.Get()
    if api_version_arg:
        api_version = api_version_arg

    cloud_resources.SetParamDefault(api='sql',
                                    collection=None,
                                    param='project',
                                    resolver=resolvers.FromProperty(
                                        properties.VALUES.core.project))

    url = properties.VALUES.api_endpoint_overrides.sql.Get()

    context['sql_client-v1beta3'] = sql_v1beta3.SqladminV1beta3(
        get_credentials=False, url=url, http=http)
    context['sql_messages-v1beta3'] = sql_v1beta3
    context['registry-v1beta3'] = cloud_resources.REGISTRY.CloneAndSwitchAPIs(
        context['sql_client-v1beta3'])

    context['sql_client-v1beta4'] = sql_v1beta4.SqladminV1beta4(
        get_credentials=False, url=url, http=http)
    context['sql_messages-v1beta4'] = sql_v1beta4
    context['registry-v1beta4'] = cloud_resources.REGISTRY.CloneAndSwitchAPIs(
        context['sql_client-v1beta4'])

    context['sql_client'] = context['sql_client-' + api_version]
    context['sql_messages'] = context['sql_messages-' + api_version]
    context['registry'] = context['registry-' + api_version]

    return context
コード例 #21
0
ファイル: __init__.py プロジェクト: bopopescu/packmybot
  def Filter(self, context, args):
    """Setup the API client within the context for this group's commands.

    Args:
      context: {str:object}, A set of key-value pairs that can be used for
          common initialization among commands.
      args: argparse.Namespace: The same namespace given to the corresponding
          .Run() invocation.

    Returns:
      The updated context.
    """

    project = properties.VALUES.core.project
    resolver = resolvers.FromProperty(project)
    resources.SetParamDefault('genomics', None, 'project', resolver)

    genomics_client = genomics_v1_client.GenomicsV1(
        url=properties.VALUES.api_endpoint_overrides.genomics.Get(),
        get_credentials=False,
        http=self.Http())

    context[lib.GENOMICS_APITOOLS_CLIENT_KEY] = genomics_client
    context[lib.GENOMICS_MESSAGES_MODULE_KEY] = genomics_v1_messages
    context[lib.GENOMICS_RESOURCES_KEY] = resources

    return context
コード例 #22
0
ファイル: __init__.py プロジェクト: bopopescu/brydzenie
    def Filter(self, context, args):
        """Initialize context for bigquery commands.

    Args:
      context: The current context.
      args: The argparse namespace that was specified on the CLI or API.

    Returns:
      The updated context.
    """
        resources.SetParamDefault(api='bigquery',
                                  collection=None,
                                  param='projectId',
                                  resolver=resolvers.FromProperty(
                                      properties.VALUES.core.project))

        # TODO(user): remove command dependence on these.
        context[BIGQUERY_API_MODULE_KEY] = bigquery_v2_client
        context[BIGQUERY_MESSAGES_MODULE_KEY] = bigquery_v2_messages

        context[APITOOLS_CLIENT_KEY] = bigquery_v2_client.BigqueryV2(
            url=properties.VALUES.api_endpoint_overrides.bigquery.Get(),
            get_credentials=False,
            http=self.Http())
        context[BIGQUERY_REGISTRY_KEY] = resources.REGISTRY

        # Inject bigquery backend params.
        bigquery.Bigquery.SetResourceParser(resources.REGISTRY)
        bigquery.Bigquery.SetApiEndpoint(
            self.Http(),
            properties.VALUES.api_endpoint_overrides.bigquery.Get())
コード例 #23
0
  def Filter(self, context, args):
    """Context() is a filter function that can update the context.

    Args:
      context: The current context.
      args: The argparse namespace that was specified on the CLI or API.

    Returns:
      The updated context.
    """

    cloud_resources.SetParamDefault(
        api='sql', collection=None, param='project',
        resolver=resolvers.FromProperty(properties.VALUES.core.project))
    credentials = cli.Credentials()

    context['sql_client-v1beta3'] = sql_v1beta3.SqladminV1beta3(
        credentials=credentials)
    context['sql_messages-v1beta3'] = sql_v1beta3
    context['registry-v1beta3'] = cloud_resources.REGISTRY

    context['sql_client-v1beta1'] = sql_v1beta1.SqladminV1beta1(
        credentials=credentials)
    context['sql_messages-v1beta1'] = sql_v1beta1
    context['registry-v1beta1'] = cloud_resources.REGISTRY.CloneAndSwitchAPIs(
        context['sql_client-v1beta1'])

    return context
コード例 #24
0
ファイル: __init__.py プロジェクト: Silentsoul04/bias_crawler
    def Filter(self, context, args):
        """Modify the context that will be given to this group's commands when run.

    Args:
      context: {str:object}, A set of key-value pairs that can be used for
          common initialization among commands.
      args: argparse.Namespace: The same namespace given to the corresponding
          .Run() invocation.

    Returns:
      The refined command context.
    """

        if not properties.VALUES.core.project.Get():
            raise properties.RequiredPropertyError(
                properties.VALUES.core.project, flag='--project')

        resources.REGISTRY.SetParamDefault(api='cloudbuild',
                                           collection=None,
                                           param='projectId',
                                           resolver=resolvers.FromProperty(
                                               properties.VALUES.core.project))

        context['registry'] = resources.REGISTRY

        return context
コード例 #25
0
    def Filter(self, context, args):
        http = cli.Http()
        core_values = properties.VALUES.core
        compute_values = properties.VALUES.compute
        context['http'] = http
        context['project'] = core_values.project.Get(required=True)

        for api, param, prop in (('compute', 'project', core_values.project),
                                 ('resourceviews', 'projectName',
                                  core_values.project), ('compute', 'zone',
                                                         compute_values.zone),
                                 ('resourceviews', 'zone',
                                  compute_values.zone),
                                 ('compute', 'region', compute_values.region),
                                 ('resourceviews', 'region',
                                  compute_values.region)):
            resources.SetParamDefault(api=api,
                                      collection=None,
                                      param=param,
                                      resolver=resolvers.FromProperty(prop))

        api_host = properties.VALUES.core.api_host.Get()
        v1_version_component = 'compute/v1/'

        compute_url = urlparse.urljoin(api_host, v1_version_component)
        context['batch-url'] = urlparse.urljoin(api_host, 'batch')

        v1_compute = compute_v1_client.ComputeV1(url=compute_url,
                                                 get_credentials=False,
                                                 http=http)
        context['compute'] = v1_compute
        context['resources'] = resources.REGISTRY.CloneAndSwitchAPIs(
            v1_compute)
コード例 #26
0
    def Filter(self, context, args):
        """Initialize context for bigquery commands.

    Args:
      context: The current context.
      args: The argparse namespace that was specified on the CLI or API.

    Returns:
      The updated context.
    """
        resources.REGISTRY.SetParamDefault(api='bigquery',
                                           collection=None,
                                           param='projectId',
                                           resolver=resolvers.FromProperty(
                                               properties.VALUES.core.project))

        # TODO(user): remove command dependence on these.
        context[BIGQUERY_MESSAGES_MODULE_KEY] = apis.GetMessagesModule(
            'bigquery', 'v2')
        context[APITOOLS_CLIENT_KEY] = apis.GetClientInstance('bigquery', 'v2')
        context[BIGQUERY_REGISTRY_KEY] = resources.REGISTRY

        # Inject bigquery backend params.
        bigquery.Bigquery.SetResourceParser(resources.REGISTRY)
        bigquery.Bigquery.SetApiEndpoint()
コード例 #27
0
    def Run(self, args):
        """Delete a named GCP repository in the current project.

    Args:
      args: argparse.Namespace, the arguments this command is run with.

    Returns:
      The path to the deleted git repository.

    Raises:
      ToolException: on project initialization errors.
    """
        project_id = resolvers.FromProperty(properties.VALUES.core.project)
        res = resources.REGISTRY.Parse(args.name,
                                       params={'projectsId': project_id},
                                       collection='sourcerepo.projects.repos')
        delete_warning = (
            'If {repo} is deleted, the name cannot be reused for up '
            'to seven days.'.format(repo=res.Name()))
        prompt_string = ('Delete "{repo}" in project "{prj}"'.format(
            repo=res.Name(), prj=res.projectsId))
        if args.force or console_io.PromptContinue(message=delete_warning,
                                                   prompt_string=prompt_string,
                                                   default=True):
            sourcerepo_handler = sourcerepo.Source()
            # This returns an empty proto buffer as a response, so there's
            # nothing to return.
            sourcerepo_handler.DeleteRepo(res)
            log.DeletedResource(res.Name())
            return res.Name()
コード例 #28
0
ファイル: bio.py プロジェクト: eroberts20/bias_crawler
 def _InitResources(cls):
     project = properties.VALUES.core.project
     resolver = resolvers.FromProperty(project)
     resources.REGISTRY.SetParamDefault('bio',
                                        collection=None,
                                        param='projectsId',
                                        resolver=resolver)
コード例 #29
0
  def Filter(self, context, args):
    """Setup the API client within the context for this group's commands.

    Args:
      context: {str:object}, A set of key-value pairs that can be used for
          common initialization among commands.
      args: argparse.Namespace: The same namespace given to the corresponding
          .Run() invocation.
    """
    cloud_resources.SetParamDefault(
        api='dataflow', collection=None, param='projectId',
        resolver=resolvers.FromProperty(properties.VALUES.core.project))

    context[DATAFLOW_MESSAGES_MODULE_KEY] = dataflow_v1b3_messages

    context[DATAFLOW_APITOOLS_CLIENT_KEY] = (
        dataflow_v1b3_client.DataflowV1b3(
            url=properties.VALUES.api_endpoint_overrides.dataflow.Get(),
            get_credentials=False,
            http=self.Http()))
    context[DATAFLOW_REGISTRY_KEY] = cloud_resources.REGISTRY

    if args.endpoint:
      log.warn('The --endpoint flag is deprecated and will be removed.  '
               'Set the api_endpoint_overrides/dataflow property instead.  '
               'e.g. gcloud config set api_endpoint_overrides/dataflow '
               'https://www.googleapis.com/dataflow/v1b3')
コード例 #30
0
ファイル: __init__.py プロジェクト: TobiahRex/Wingman
    def Filter(self, context, args):
        """Modify the context that will be given to this group's commands when run.

    Args:
      context: {str:object}, A set of key-value pairs that can be used for
          common initialization among commands.
      args: argparse.Namespace: The same namespace given to the corresponding
          .Run() invocation.

    Returns:
      The refined command context.
    """

        # client = core_apis.GetClientInstance('cloudbuild', 'v1')
        # registry = resources.REGISTRY.CloneAndSwitchAPIs(client)
        # registry = registry.CloneAndSwitchAPIs(
        #     core_apis.GetClientInstance('storage', 'v1'))

        resources.REGISTRY.SetParamDefault(api='cloudbuild',
                                           collection=None,
                                           param='projectId',
                                           resolver=resolvers.FromProperty(
                                               properties.VALUES.core.project))

        context['registry'] = resources.REGISTRY

        return context