def Create(instance_name, content, location, version, realm_configs):
    """Create a new Immersive Stream for XR service instance.

  Args:
    instance_name: string - name of the service instance
    content: string - resource path of the content resource that is served by
      the instance
    location: string - location where the resource will be created
    version: string - content build version tag
    realm_configs: List of realm config dicts of the form:
      [{'realm': realm1, 'capacity': capacity1}, ...] These specify the
        deployment configuration of the instance in realms.

  Returns:
    An Operation object which can be used to check on the progress of the
    service instance creation.
  """
    client = api_util.GetClient()
    messages = api_util.GetMessages()
    build_version = messages.BuildVersion(contentVersionTag=version)

    instance = messages.StreamInstance(
        content=content,
        contentBuildVersion=build_version,
        name=instance_name,
        realmConfigs=ParseRealmConfigsFromArg(realm_configs))
    service = client.ProjectsLocationsStreamInstancesService(client)
    return service.Create(
        messages.StreamProjectsLocationsStreamInstancesCreateRequest(
            parent=ProjectLocation(properties.VALUES.core.project.Get(),
                                   location),
            streamInstance=instance,
            streamInstanceId=instance_name))
def Get(instance_relative_name):
    """Get resource details of an Immersive Stream for XR service instance.

  Args:
    instance_relative_name: string - canonical resource name of the instance

  Returns:
    A service instance resource object.
  """
    client = api_util.GetClient()
    messages = api_util.GetMessages()
    service = client.ProjectsLocationsStreamInstancesService(client)

    return service.Get(
        messages.StreamProjectsLocationsStreamInstancesGetRequest(
            name=instance_relative_name))
예제 #3
0
    def Run(self, args):
        realm_configs = args.add_realm
        content_ref = args.CONCEPTS.content.Parse()
        content_name = content_ref.RelativeName()
        location = content_ref.locationsId
        instance_name = args.instance
        version = args.version

        client = api_util.GetClient()
        result_operation = instances.Create(instance_name, content_name,
                                            location, version, realm_configs)
        log.status.Print(
            'Create request issued for: [{}]'.format(instance_name))
        if args.async_:
            log.status.Print('Check operation [{}] for status.\n'.format(
                result_operation.name))
            return result_operation

        operation_resource = resources.REGISTRY.Parse(
            result_operation.name,
            collection='stream.projects.locations.operations',
            api_version='v1alpha1')
        created_instance = waiter.WaitFor(
            waiter.CloudOperationPoller(
                client.projects_locations_streamInstances,
                client.projects_locations_operations), operation_resource,
            'Waiting for operation [{}] to complete'.format(
                result_operation.name))

        instance_resource = resources.REGISTRY.Parse(
            None,
            collection='stream.projects.locations.streamInstances',
            api_version='v1alpha1',
            params={
                'projectsId':
                properties.VALUES.core.project.Get(required=True),
                'locationsId': 'global',
                'streamInstancesId': instance_name
            })

        log.CreatedResource(instance_resource)

        return created_instance
def UpdateCapacity(instance_ref, current_instance, realm_configs):
    """Update capacity of a realm for an Immersive Stream for XR service instance.

  Args:
    instance_ref: resource object - service instance to be updated
    current_instance: instance object - current state of the service instance
      before update
    realm_configs: List of a single realm config dict of the form:
      [{'realm': realm1, 'capacity': capacity1}]. This specifies the deployment
        configuration of the instance in the realm.

  Returns:
    An Operation object which can be used to check on the progress of the
    service instance update.
  """
    client = api_util.GetClient()
    messages = api_util.GetMessages()
    service = client.ProjectsLocationsStreamInstancesService(client)
    new_realm_configs = ParseRealmConfigsFromArg(realm_configs)
    # TODO(b/230366148)
    if not new_realm_configs:
        raise exceptions.Error('Realm configs must not be empty')

    new_realm_config = ParseRealmConfigsFromArg(realm_configs)[0]

    instance = messages.StreamInstance()
    instance.realmConfigs = []
    for realm_config in current_instance.realmConfigs:
        if realm_config.realm == new_realm_config.realm:
            instance.realmConfigs.append(new_realm_config)
        else:
            instance.realmConfigs.append(realm_config)

    return service.Patch(
        messages.StreamProjectsLocationsStreamInstancesPatchRequest(
            name=instance_ref.RelativeName(),
            streamInstance=instance,
            updateMask='realm_configs'))
def UpdateContentBuildVersion(instance_ref, version):
    """Update content build version of an Immersive Stream for XR service instance.

  Args:
    instance_ref: resource object - service instance to be updated
    version: string - content build version tag

  Returns:
    An Operation object which can be used to check on the progress of the
    service instance update.
  """
    client = api_util.GetClient()
    messages = api_util.GetMessages()
    service = client.ProjectsLocationsStreamInstancesService(client)

    build_version = messages.BuildVersion(contentVersionTag=version)
    instance = messages.StreamInstance()
    instance.contentBuildVersion = build_version
    return service.Patch(
        messages.StreamProjectsLocationsStreamInstancesPatchRequest(
            name=instance_ref.RelativeName(),
            streamInstance=instance,
            updateMask='content_build_version'))
예제 #6
0
  def Run(self, args):
    realm_configs = args.update_realm
    instance_name = args.instance
    version = args.version

    instance_ref = resources.REGISTRY.Parse(
        None,
        collection='stream.projects.locations.streamInstances',
        api_version='v1alpha1',
        params={
            'projectsId': properties.VALUES.core.project.Get(required=True),
            'locationsId': 'global',
            'streamInstancesId': instance_name
        })

    if realm_configs:
      if len(realm_configs) > 1:
        log.status.Print(
            'Only one realm may be updated at a time. Please try again with only one --update-realm argument.'
        )
        return
      current_instance = instances.Get(instance_ref.RelativeName())
      if not instances.ValidateRealmExists(current_instance.realmConfigs,
                                           realm_configs):
        error_message = (
            '{} is not an existing realm for instance {}. Capacity'
            ' updates can only be applied to existing realms, '
            'adding a new realm is not currently supported.').format(
                realm_configs[0]['realm'], instance_name)
        raise exceptions.Error(error_message)
      result_operation = instances.UpdateCapacity(instance_ref,
                                                  current_instance,
                                                  realm_configs)
    else:
      result_operation = instances.UpdateContentBuildVersion(
          instance_ref, version)

    client = api_util.GetClient()

    log.status.Print('Update request issued for: [{}]'.format(instance_name))
    if args.async_:
      log.status.Print('Check operation [{}] for status.\n'.format(
          result_operation.name))
      return result_operation

    operation_resource = resources.REGISTRY.Parse(
        result_operation.name,
        collection='stream.projects.locations.operations',
        api_version='v1alpha1')
    updated_instance = waiter.WaitFor(
        waiter.CloudOperationPoller(client.projects_locations_streamInstances,
                                    client.projects_locations_operations),
        operation_resource,
        'Waiting for operation [{}] to complete'.format(result_operation.name))

    instance_resource = resources.REGISTRY.Parse(
        None,
        collection='stream.projects.locations.streamInstances',
        api_version='v1alpha1',
        params={
            'projectsId': properties.VALUES.core.project.Get(required=True),
            'locationsId': 'global',
            'streamInstancesId': instance_name
        })

    log.UpdatedResource(instance_resource)
    return updated_instance