beginCreateOrUpdateとbeginCreateOrUpdateAndWaitの違い
はじめに
こんにちは、ひであきです。
この記事ではAzure SDKを使うにあたって私自身が分からなかったことをメモとして記述しています。
戻り値の違い
beginCreateOrUpdateとbeginCreateOrUpdateAndWaitの両方とも動く内容は同じようです。
この二つの違いは戻り値の値が違うということです。 (👇にこの二つのメソッドの戻り値を書きました)
beginCreateOrUpdateの戻り値は
Promise <PollerLike <PollOperationState < ManagementGroupsCreateOrUpdateResponse >, ManagementGroupsCreaeOrUupdateResponse >>
beginCreateOrUpdateAndWaitの戻り値は
Promise < ManagementGroupsCreateOrUpdateResponse >
以上のようにbginCreateOrUpdate方がbeginCreateOrUpdateAndWaitより ManagementGroupsCreateOrUpdateResponseの入っている階層が深いです。
(ManagementGroupsCreateOrUpdateResponseはPollerLikeというユーザーが 操作する必要のある最小限のAPIのみを公開しているインターフェースの中に PollOperationStateという長時間実行される操作ポーラーを定義するために必要な プロパティの最小セットの意見リストが含まれたインターフェースの中に入っている)
戻り値詳細
- VirtualNetworkを作成したときの双方の戻り値の詳細
- SubNetworkを作成したときの双方の戻り値の詳細
- VirtualMachineを作成したときの双方の戻り値の詳細
以上の順番で書いています。
VirtualNetworkを作成したときのbeginCreateOrUpdateの時の戻り値詳細
LroEngine { stopped: true, pollProgressCallbacks: [], operation: GenericPollOperation { state: { initialRawResponse: [Object], isStarted: true, pollingURL: '****************************', config: [Object] }, lro: LroImpl { sendOperationFn: [Function: sendOperation], args: [Object], spec: [Object], requestPath: '**********************************************', requestMethod: 'PUT' }, lroResourceLocationConfig: '**********************', processResult: undefined, updateState: undefined, isDone: undefined, pollerConfig: { intervalInMs: 10000 }, getLroStatusFromResponse: [Function (anonymous)], poll: [AsyncFunction (anonymous)] }, resolve: [Function (anonymous)], reject: [Function (anonymous)], promise: Promise { <pending> }, config: { intervalInMs: 10000 }, pollOncePromise: undefined }
VirtualNetworkを作成したときのbeginCreateOrUpdateAndWaitの時の戻り値詳細
{ enableDdosProtection: false, enableVmProtection: false, status: 'Succeeded' }
SubNetworkを作成したときのbeginCreateOrUpdateの時の戻り値詳細
LroEngine { stopped: true, pollProgressCallbacks: [], operation: GenericPollOperation { state: { initialRawResponse: [Object], isStarted: true, pollingURL: '******************************', config: [Object] }, lro: LroImpl { sendOperationFn: [Function: sendOperation], args: [Object], spec: [Object], requestPath: '**********************************************', requestMethod: 'PUT' }, lroResourceLocationConfig: '***********************', processResult: undefined, updateState: undefined, isDone: undefined, pollerConfig: { intervalInMs: 10000 }, getLroStatusFromResponse: [Function (anonymous)], poll: [AsyncFunction (anonymous)] }, resolve: [Function (anonymous)], reject: [Function (anonymous)], promise: Promise { <pending> }, config: { intervalInMs: 10000 }, pollOncePromise: undefined }
SubNetworkを作成したときのbeginCreateOrUpdateAndWaitの時の戻り値詳細
{ privateEndpointNetworkPolicies: 'Enabled', privateLinkServiceNetworkPolicies: 'Enabled', status: 'Succeeded' }
VirtualMachineを作成したときのbeginCreateOrUpdateの時の戻り値詳細
LroEngine { stopped: true, pollProgressCallbacks: [], operation: GenericPollOperation { state: { initialRawResponse: [Object], isStarted: true, pollingURL: '**********************************************', config: [Object], result: [Object], isCompleted: true }, lro: LroImpl { sendOperationFn: [Function: sendOperation], args: [Object], spec: [Object], requestPath: '**********************************************', requestMethod: 'PUT' }, lroResourceLocationConfig: undefined, processResult: undefined, updateState: undefined, isDone: undefined, pollerConfig: { intervalInMs: 2000 }, getLroStatusFromResponse: [Function: processBodyPollingOperationResult], poll: [AsyncFunction (anonymous)] }, resolve: [Function (anonymous)], reject: [Function (anonymous)], promise: Promise { { id: '*************************************' osProfile: [Object], networkProfile: [Object], provisioningState: 'Succeeded', vmId: '*************************', timeCreated: *********************** } }, config: { intervalInMs: 2000 }, pollOncePromise: undefined }
VirtualMachineを作成したときのbeginCreateOrUpdateAndWaitの時の戻り値詳細
{ id: '********************************************************', name: '********************', type: 'Microsoft.Compute/***************', location: '***************', hardwareProfile: { vmSize: '********************' }, storageProfile: { imageReference: { publisher: '****************', offer: '**********************', sku: '**************************', version: '*************', exactVersion: '*********************' }, osDisk: { osType: '************', name: '***************', caching: '*************', createOption: '***********', diskSizeGB: **********, managedDisk: [Object], deleteOption: 'Detach' }, dataDisks: [ [Object], [Object] ] }, osProfile: { computerName: '****************', adminUsername: '*************', windowsConfiguration: { provisionVMAgent: true, enableAutomaticUpdates: true, patchSettings: [Object], enableVMAgentPlatformUpdates: false }, secrets: [], allowExtensionOperations: true, requireGuestProvisionSignal: true }, networkProfile: { networkInterfaces: [ [Object] ] }, provisioningState: 'Succeeded', vmId: '********************************', timeCreated: *********************** }
まとめ
beginCreateOrUpdateとbeginCreateOrUpdateAndWaitでは戻り値の階層が違います。
そのため、戻り値の内容が大幅に違います。
実際に自分が作ったVirtualMachineの名前やIDを戻り値に含みたい場合はbeginCreateOrUpdateAndWaitを使う必要があります。
beginCreateOrUpdateの戻り値の階層の中にあるPollerLikeとPollOperationStateは以下の記事にまとめています。👇
PollerLikeとPollOperationStateとは