def Run(self, args):
        client = BmsClient()
        network = args.CONCEPTS.network.Parse()
        labels_update = None
        labels_diff = labels_util.Diff.FromUpdateArgs(args)
        if labels_diff.MayHaveUpdates():
            orig_resource = client.GetNetwork(network)
            labels_update = labels_diff.Apply(
                client.messages.Network.LabelsValue,
                orig_resource.labels).GetOrNone()

        if not labels_diff.MayHaveUpdates():
            raise exceptions.NoConfigurationChangeError(
                'No configuration change was requested. Did you mean to include the '
                'flags `--update-labels` `--remove-labels` or `--clear-labels`?'
            )

        op_ref = client.UpdateNetwork(network_resource=network,
                                      labels=labels_update)

        if op_ref.done:
            log.UpdatedResource(network.Name(), kind='network')
            return op_ref

        if args.async_:
            log.status.Print(
                'Update request issued for: [{}]\nCheck operation '
                '[{}] for status.'.format(network.Name(), op_ref.name))
            return op_ref

        op_resource = resources.REGISTRY.ParseRelativeName(
            op_ref.name,
            collection='baremetalsolution.operations',
            api_version='v1')
        poller = waiter.CloudOperationPollerNoResources(
            client.operation_service)
        res = waiter.WaitFor(
            poller, op_resource,
            'Waiting for operation [{}] to complete'.format(op_ref.name))
        log.UpdatedResource(network.Name(), kind='network')
        return res
예제 #2
0
 def Run(self, args):
   network = args.CONCEPTS.network.Parse()
   client = BmsClient()
   return client.GetNetwork(network)