マネージド ノードに拡張機能ペイロードをインストールする
適用先:Windows Admin Center、Windows Admin Center Preview
セットアップ
注意
このガイドのとおりにするには、ビルド 1.2.1904.02001 以上が必要です。 ビルド番号を確認するには、Windows Admin Center を開いて、上部の疑問符をクリックします。
まだ行っていない場合は、Windows Admin Center 用のツール拡張機能を作成します。 これを行った後、拡張機能を作成するときに使った値を記録しておきます。
値 | 説明 | 例 |
---|---|---|
{!Company Name} |
会社名 (スペースを含む) | Contoso |
{!Tool Name} |
ツール名 (スペースを含む) | InstallOnNode |
ツール拡張機能フォルダーの中に、Node
フォルダーを作成します ({!Tool Name}\Node
)。 このフォルダーに配置されたすべてのものが、この API を使うとマネージド ノードにコピーされます。 ユース ケースに必要なすべてのファイルを追加してください。
また、{!Tool Name}\Node\installNode.ps1
スクリプトも作成します。 すべてのファイルが {!Tool Name}\Node
フォルダーからマネージド ノードにコピーされた後、このスクリプトがマネージド ノードで実行されます。 ユース ケースのための追加ロジックをすべて追加してください。 {!Tool Name}\Node\installNode.ps1
ファイルの例:
# Add logic for installing payload on managed node
echo 'Success'
注意
API は、この特定の名前で {!Tool Name}\Node\installNode.ps1
を検索します。 このファイルの名前を変更すると、エラーが発生します。
UI との統合
\src\app\default.component.ts
を次のように更新します。
import { Component } from '@angular/core';
import { AppContextService } from '@microsoft/windows-admin-center-sdk/angular';
import { Observable } from 'rxjs';
@Component({
selector: 'default-component',
templateUrl: './default.component.html',
styleUrls: ['./default.component.css']
})
export class DefaultComponent {
constructor(private appContextService: AppContextService) { }
public response: any;
public loading = false;
public installOnNode() {
this.loading = true;
this.post('{!Company Name}.{!Tool Name}', '1.0.0',
this.appContextService.activeConnection.nodeName).subscribe(
(response: any) => {
console.log(response);
this.response = response;
this.loading = false;
},
(error) => {
console.log(error);
this.response = error;
this.loading = false;
}
);
}
public post(id: string, version: string, targetNode: string): Observable<any> {
return this.appContextService.node.post(targetNode,
`features/extensions/${id}/versions/${version}/install`);
}
}
プレースホルダーを、拡張機能の作成時に使用した値に更新します。
this.post('contoso.install-on-node', '1.0.0',
this.appContextService.activeConnection.nodeName).subscribe(
(response: any) => {
console.log(response);
this.response = response;
this.loading = false;
},
(error) => {
console.log(error);
this.response = error;
this.loading = false;
}
);
また、\src\app\default.component.html
を次のように更新します。
<button (click)="installOnNode()">Click to install</button>
<sme-loading-wheel *ngIf="loading" size="large"></sme-loading-wheel>
<p *ngIf="response">{{response}}</p>
最後は \src\app\default.module.ts
です。
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { LoadingWheelModule } from '@microsoft/windows-admin-center-sdk/angular';
import { DefaultComponent } from './default.component';
import { Routing } from './default.routing';
@NgModule({
imports: [
CommonModule,
LoadingWheelModule,
Routing
],
declarations: [DefaultComponent]
})
export class DefaultModule { }
NuGet パッケージの作成とインストール
最後のステップでは、追加したファイルで NuGet パッケージを作成し、そのパッケージを Windows Admin Center にインストールします。
これまでに拡張機能パッケージを作成したことがない場合は、「拡張機能の公開」ガイドに従ってください。
重要
この拡張機能の .nuspec ファイルでは、<id>
の値がプロジェクトの manifest.json
の名前と一致し、<version>
が \src\app\default.component.ts
に追加したものと一致していることが重要です。 また、<files>
の下にエントリを追加します。
<file src="Node\**\*.*" target="Node" />
] の順にクリックします。
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="https://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>contoso.install-on-node</id>
<version>1.0.0</version>
<authors>Contoso</authors>
<owners>Contoso</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<projectUrl>https://msft-sme.myget.org/feed/windows-admin-center-feed/package/nuget/contoso.sme.install-on-node-extension</projectUrl>
<licenseUrl>http://YourLicenseLink</licenseUrl>
<iconUrl>http://YourLogoLink</iconUrl>
<description>Install on node extension by Contoso</description>
<copyright>(c) Contoso. All rights reserved.</copyright>
</metadata>
<files>
<file src="bundle\**\*.*" target="ux" />
<file src="package\**\*.*" target="gateway" />
<file src="Node\**\*.*" target="Node" />
</files>
</package>
このパッケージを作成したら、そのフィードにパスを追加します。 Windows Admin Center で [設定] > [拡張機能] > [フィード] に移動し、そのパッケージが存在する場所へのパスを追加します。 拡張機能のインストールが完了したら、install
ボタンをクリックすると API が呼び出されるようになるはずです。