[英]Android Management API change Policy for device
I created 2 policies in my enterprise.我在我的企业中创建了 2 个策略。
I would like to switch one device to the other policy without re-enroling it.我想在不重新注册的情况下将一台设备切换到另一项策略。
I tried to use android management enterprises devices.patch with following JSON我尝试使用 android management enterprises devices.patch 与以下 JSON
{ "policyName": "policy2" }
When i execute this command i always get follwoing error Message:当我执行此命令时,我总是收到以下错误消息:
{
"error": {
"code": 400,
"message": "Illegal state transition from ACTIVE to DEVICE_STATE_UNSPECIFIED",
"status": "INVALID_ARGUMENT"
}
}
Does anybody know how to change policy for a device without wiping it?有谁知道如何在不擦除设备的情况下更改设备的策略?
It is indeed possible to change the policy of a device without re-enrolling it, and you're not far from the solution. 确实可以在不重新注册的情况下更改设备的策略,并且您距离解决方案不远。
You get this error because you implicitly attempt to change other fields of the Device
resource (in particular the state
field) by not setting them in the resource that you send in devices.patch
. 您收到此错误是因为您隐式尝试更改
Device
资源的其他字段(特别是state
字段),方法是不在您在devices.patch
发送的资源中设置它们。
You have two options: 您有两种选择:
Set the updateMask
in devices.patch
to "policyName"
, to tell the API that you only want to change the policyName
field. 将
devices.patch
的updateMask
设置为"policyName"
,告诉API您只想更改policyName
字段。
Call devices.get
to get the current Device
resource, and then send back the entire resource with only the policyName
field changed in to devices.patch
. 调用
devices.get
来获取当前的Device
资源,然后发送回整个资源,只将policyName
字段更改为devices.patch
。
Using updateMask
is preferable because it does an atomic read-modify-write. 使用
updateMask
是首选,因为它执行原子读 - 修改 - 写。
As Fred mentioned, updateMask is the preferred way to go. 正如弗雷德所说, updateMask是首选方式。 Here's an example of how to use the updateMask approach in the Google colab
以下是如何在Google colab中使用updateMask方法的示例
swap_result = androidmanagement.enterprises().devices().patch(
name='enterprises/ENTERPRISE_NAME/devices/DEVICE_ID', updateMask='policyName', body={ "policyName": "enterprises/ENTERPRISE_NAME/policies/NEW_POLICY_NAME"}).execute()
i foudn a solution for my problem: 我为我的问题找到了解决方案:
{ "policyName": "policy2" , "state":"active"} {“policyName”:“policy2”,“state”:“active”}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.