Nama template
ACS-SMC-CreateAndVerifyInstance
Deskripsi template
Membuat instance sebagai instance tujuan dan menjalankan perintah untuk memverifikasi instance tersebut di Server Migration Center (SMC).
Tipe template
Otomatis
Pemilik
Alibaba Cloud
Parameter input
Parameter | Deskripsi | Tipe | Diperlukan | Nilai default | Batasan |
zoneId | ID zona. | String | Ya | ||
hostName | Nama host tempat instance akan dibuat. | String | Ya | Ekspresi reguler untuk verifikasi string: ^(?!. | |
imageId | ID gambar dari mana instance akan dibuat. | String | Ya | ||
instanceType | Tipe instance dari instance yang akan dibuat. | String | Ya | ||
privateIp | Alamat IP internal dari instance yang akan dibuat. | String | Ya | ||
regionId | ID wilayah. | String | Tidak | {{ ACS::RegionId }} | |
systemDiskSize | Ukuran disk sistem. | Angka | Tidak | 19 | |
instancesCount | Jumlah instance yang akan dibuat. | Angka | Tidak | 1 | |
isDeleteInstance | Menentukan apakah instance akan dihapus setelah diverifikasi. | Boolean | Tidak | True | |
commandType | Tipe perintah Cloud Assistant yang digunakan untuk memverifikasi instance. | String | Tidak | RunShellScript | |
commandContent | Konten perintah Cloud Assistant yang digunakan untuk memverifikasi instance. | String | Tidak | "" | |
timeout | Periode timeout perintah. | Angka | Tidak | 600 | |
workingDir | Direktori tempat perintah dijalankan. | String | Tidak | /root | |
passwordInherit | Menentukan apakah menggunakan kata sandi yang telah ditetapkan dalam gambar. | Boolean | Tidak | False | |
rateControl | Pengaturan kontrol laju. | Json | Tidak | {'Mode': 'Concurrency', 'MaxErrors': 0, 'Concurrency': 10} | |
OOSAssumeRole | Peran Resource Access Management (RAM) yang diasumsikan oleh CloudOps Orchestration Service (OOS). | String | Tidak | "" |
Parameter output
Parameter | Deskripsi | Tipe |
instanceCheckResults | List |
Kebijakan izin yang diperlukan untuk mengeksekusi template
{
"Version": "1",
"Statement": [
{
"Action": [
"ecs:DeleteInstance",
"ecs:DeleteSecurityGroup",
"ecs:DescribeCloudAssistantStatus",
"ecs:DescribeImages",
"ecs:DescribeInstances",
"ecs:DescribeInvocationResults",
"ecs:DescribeInvocations",
"ecs:InstallCloudAssistant",
"ecs:RebootInstance",
"ecs:RunCommand"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"ros:CreateStack",
"ros:DeleteStack",
"ros:GetStack"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"vpc:DeleteVSwitch",
"vpc:DeleteVpc",
"vpc:DescribeVSwitches",
"vpc:DescribeVpcs"
],
"Resource": "*",
"Effect": "Allow"
}
]
}
Referensi
Untuk informasi lebih lanjut, lihat ACS-SMC-CreateAndVerifyInstance di GitHub.
Konten Template
FormatVersion: OOS-2019-06-01
Description:
en: Buat dan verifikasi instance dengan perintah
name-en: ACS-SMC-CreateAndVerifyInstance
Parameters:
regionId:
Type: String
Label:
en: RegionId
AssociationProperty: RegionId
Default: '{{ ACS::RegionId }}'
zoneId:
Label:
en: ZoneId
Description:
en: ID zona target VSwitch untuk dibuat
AssociationProperty: 'ALIYUN::ECS::Instance::ZoneId'
Type: String
AssociationPropertyMetadata:
RegionId: regionId
hostName:
Label:
en: HostName
Type: String
AllowedPattern: '^(?!\.|\-)(?!.*\.\.|.*\-\-)(?!.*_).*(?<!\.|\-)$'
MinLength: 2
imageId:
Label:
en: ImageId
Type: String
AssociationProperty: 'ALIYUN::ECS::Image::ImageId'
AssociationPropertyMetadata:
RegionId: regionId
instanceType:
Label:
en: InstanceType
Type: String
AssociationProperty: 'ALIYUN::ECS::Instance::InstanceType'
privateIp:
Label:
en: PrivateIp
Type: String
systemDiskSize:
Label:
en: SystemDiskSize
Type: Number
Default: 19
MinValue: 19
MaxValue: 500
instancesCount:
Label:
en: InstancesCount
Type: Number
Default: 1
MinValue: 1
MaxValue: 999
isDeleteInstance:
Label:
en: IsDeleteInstance
Type: Boolean
Default: true
commandType:
Label:
en: CommandType
Type: String
AllowedValues:
- RunBatScript
- RunPowerShellScript
- RunShellScript
Default: RunShellScript
commandContent:
Label:
en: CommandContent
Type: String
AssociationProperty: Code
Default: ''
timeout:
Label:
en: Timeout
Type: Number
Default: 600
workingDir:
Label:
en: WorkingDir
Type: String
Default: /root
passwordInherit:
Description:
en: Untuk menggunakan parameter PasswordInherit, parameter Password harus kosong dan Anda harus memastikan bahwa gambar yang dipilih memiliki kata sandi yang dikonfigurasi(default:false)
Label:
en: IsUsePasswordInherit
Type: Boolean
Default: false
rateControl:
Label:
en: RateControl
Type: Json
AssociationProperty: RateControl
Default:
Mode: Concurrency
MaxErrors: 0
Concurrency: 10
OOSAssumeRole:
Label:
en: OOSAssumeRole
Type: String
Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: describeImages
Action: 'ACS::ExecuteAPI'
Description:
en: Query the image ostype by image id
Properties:
Service: ECS
API: DescribeImages
Parameters:
RegionId: '{{ regionId }}'
ImageId: '{{ imageId }}'
Outputs:
osType:
ValueSelector: 'Images.Image[0].OSType'
Type: String
- Name: converConstant
Action: 'ACS::ECS::SMCConversionConstantByJqScript'
Description:
en: Secara otomatis mengonversi ke CidrBlock yang tersedia sesuai dengan PrivateIp
Properties:
parameter: '{{ privateIp }}'
jqScript:
- '.[0] | split(".") as $item | $item | if .[0]=="10" then "10.0.0.0/8" elif .[0]=="172" then "172.16.0.0/12" elif .[0]=="192" then "192.168.0.0/16" else "" end'
- '.[0] | split(".") as $item | $item | if .[0]=="10" then "10."+.[1]+".0.0/16" elif .[0]=="172" then "172."+.[1]+"."+.[2]+".0/24" elif .[0]=="192" then "192.168."+.[2]+".0/24" else "" end'
Outputs:
vswCidrBlock:
Type: String
ValueSelector: secondValue
vpcCidrBlock:
Type: String
ValueSelector: firstValue
- Name: createStack
Action: 'ACS::ExecuteAPI'
Description:
en: Membuat tumpukan sumber daya
Properties:
Service: ROS
API: CreateStack
Parameters:
RegionId: '{{ regionId }}'
StackName: 'OOS-{{ACS::ExecutionId}}'
TimeoutInMinutes: 10
DisableRollback: false
Parameters:
- ParameterKey: hostName
ParameterValue: '{{ hostName }}'
- ParameterKey: privateIp
ParameterValue: '{{ privateIp }}'
- ParameterKey: instanceType
ParameterValue: '{{ instanceType }}'
- ParameterKey: zoneId
ParameterValue: '{{ zoneId }}'
- ParameterKey: regionId
ParameterValue: '{{ regionId }}'
- ParameterKey: imageId
ParameterValue: '{{imageId}}'
- ParameterKey: executionId
ParameterValue: '{{ ACS::ExecutionId }}'
- ParameterKey: instancesCount
ParameterValue: '{{ instancesCount }}'
- ParameterKey: systemDiskSize
ParameterValue: '{{ systemDiskSize }}'
- ParameterKey: passwordInherit
ParameterValue: '{{ passwordInherit }}'
TemplateBody:
'Fn::If':
- 'Fn::Equals':
- windows
- '{{ describeImages.osType }}'
- |
{
"Description": "Buat instance VPC ECS",
"Parameters": {
"imageId": {
"Type": "String"
},
"hostName": {
"Type": "String"
},
"privateIp": {
"Type": "String"
},
"instanceType": {
"Type": "String"
},
"executionId": {
"Type": "String"
},
"instancesCount": {
"Type": "String"
},
"zoneId": {
"Type": "String"
},
"regionId": {
"Type": "String"
},
"systemDiskSize": {
"Type": "Number"
},
"passwordInherit": {
"Type": "Boolean"
},
"resourcePrefix": {
"Type": "String",
"Default": "oos-generated"
}
},
"Conditions":{
"CreateSystemDiskSize":{
"Fn::Equals":[
19,
{
"Ref":"systemDiskSize"
}
]
}
},
"ROSTemplateFormatVersion": "2015-09-01",
"Outputs": {
"ecs_instance_id": {
"Value": {
"Fn::GetAtt": [
"ecs",
"InstanceIds"
]
}
}
},
"Resources": {
"vswitch": {
"Type": "ALIYUN::ECS::VSwitch",
"Properties": {
"VpcId": {
"Ref": "vpc"
},
"Description": {
"Fn::Join": [
" ",
[
"ID eksekusi OOS adalah",
{
"Ref": "executionId"
}
]
]
},
"ZoneId": {
"Ref": "zoneId"
},
"CidrBlock": "{{ converConstant.vswCidrBlock }}"
}
},
"sg": {
"Type": "ALIYUN::ECS::SecurityGroup",
"Properties": {
"Tags": [
{
"Key": "oos-generated",
"Value": {
"Ref": "executionId"
}
},
{
"Key": "region",
"Value": {
"Ref": "regionId"
}
}
],
"VpcId": {
"Ref": "vpc"
},
"SecurityGroupName": {
"Fn::Join": [
"-",
[
{
"Ref": "resourcePrefix"
},
"sg"
]
]
},
"SecurityGroupEgress": [
{
"PortRange": "-1/-1",
"Priority": 1,
"IpProtocol": "all",
"DestCidrIp": "0.0.0.0/0",
"NicType": "intranet"
}
],
"SecurityGroupIngress": [
{
"PortRange": "3389/3389",
"Priority": 1,
"IpProtocol": "tcp",
"SourceCidrIp": "0.0.0.0/0",
"NicType": "intranet"
}
]
}
},
"vpc": {
"Type": "ALIYUN::ECS::VPC",
"Properties": {
"CidrBlock": "{{ converConstant.vpcCidrBlock }}",
"Description": {
"Fn::Join": [
" ",
[
"ID eksekusi OOS adalah",
{
"Ref": "executionId"
}
]
]
},
"VpcName": {
"Fn::Join": [
"-",
[
{
"Ref": "resourcePrefix"
},
"vpc"
]
]
}
}
},
"ecs": {
"Type": "ALIYUN::ECS::InstanceGroup",
"Properties": {
"ImageId": {
"Ref": "imageId"
},
"HostName": {
"Ref": "hostName"
},
"PrivateIpAddress": {
"Ref": "privateIp"
},
"SecurityGroupId": {
"Ref": "sg"
},
"VpcId": {
"Ref": "vpc"
},
"VSwitchId": {
"Ref": "vswitch"
},
"InstanceType": {
"Ref": "instanceType"
},
"PasswordInherit": {
"Ref": "passwordInherit"
},
"SystemDiskSize": {
"Fn::If": [
"CreateSystemDiskSize",
{
"Ref": "ALIYUN::NoValue"
},
{
"Ref": "systemDiskSize"
}
]
},
"MinAmount": {
"Ref": "instancesCount"
},
"MaxAmount": {
"Ref": "instancesCount"
},
"Tags": [
{
"Key": "oos-generated",
"Value": {
"Ref": "executionId"
}
},
{
"Key": "region",
"Value": {
"Ref": "regionId"
}
}
]
}
}
},
"Metadata": {
"ALIYUN::ROS::Interface": {
"TemplateTags": [
"acs:integrate:oos:smc_create_and_verify_instance"
]
}
}
}
- |
{
"Description": "Buat instance VPC ECS",
"Parameters": {
"imageId": {
"Type": "String"
},
"hostName": {
"Type": "String"
},
"privateIp": {
"Type": "String"
},
"instanceType": {
"Type": "String"
},
"passwordInherit": {
"Type": "Boolean"
},
"executionId": {
"Type": "String"
},
"instancesCount": {
"Type": "String"
},
"zoneId": {
"Type": "String"
},
"regionId": {
"Type": "String"
},
"systemDiskSize": {
"Type": "Number"
},
"resourcePrefix": {
"Type": "String",
"Default": "oos-generated"
}
},
"Conditions":{
"CreateSystemDiskSize":{
"Fn::Equals":[
19,
{
"Ref":"systemDiskSize"
}
]
}
},
"ROSTemplateFormatVersion": "2015-09-01",
"Outputs": {
"ecs_instance_id": {
"Value": {
"Fn::GetAtt": [
"ecs",
"InstanceIds"
]
}
}
},
"Resources": {
"vswitch": {
"Type": "ALIYUN::ECS::VSwitch",
"Properties": {
"VpcId": {
"Ref": "vpc"
},
"Description": {
"Fn::Join": [
" ",
[
"ID eksekusi OOS adalah",
{
"Ref": "executionId"
}
]
]
},
"ZoneId": {
"Ref": "zoneId"
},
"CidrBlock": "{{ converConstant.vswCidrBlock }}"
}
},
"sg": {
"Type": "ALIYUN::ECS::SecurityGroup",
"Properties": {
"Tags": [
{
"Key": "oos-generated",
"Value": {
"Ref": "executionId"
}
},
{
"Key": "region",
"Value": {
"Ref": "regionId"
}
}
],
"VpcId": {
"Ref": "vpc"
},
"SecurityGroupName": {
"Fn::Join": [
"-",
[
{
"Ref": "resourcePrefix"
},
"sg"
]
]
},
"SecurityGroupEgress": [
{
"PortRange": "-1/-1",
"Priority": 1,
"IpProtocol": "all",
"DestCidrIp": "0.0.0.0/0",
"NicType": "intranet"
}
],
"SecurityGroupIngress": [
{
"PortRange": "22/22",
"Priority": 1,
"IpProtocol": "tcp",
"SourceCidrIp": "0.0.0.0/0",
"NicType": "intranet"
}
]
}
},
"vpc": {
"Type": "ALIYUN::ECS::VPC",
"Properties": {
"CidrBlock": "{{ converConstant.vpcCidrBlock }}",
"Description": {
"Fn::Join": [
" ",
[
"ID eksekusi OOS adalah",
{
"Ref": "executionId"
}
]
]
},
"VpcName": {
"Fn::Join": [
"-",
[
{
"Ref": "resourcePrefix"
},
"vpc"
]
]
}
}
},
"ecs": {
"Type": "ALIYUN::ECS::InstanceGroup",
"Properties": {
"ImageId": {
"Ref": "imageId"
},
"HostName": {
"Ref": "hostName"
},
"PrivateIpAddress": {
"Ref": "privateIp"
},
"SecurityGroupId": {
"Ref": "sg"
},
"VpcId": {
"Ref": "vpc"
},
"VSwitchId": {
"Ref": "vswitch"
},
"InstanceType": {
"Ref": "instanceType"
},
"PasswordInherit": {
"Ref": "passwordInherit"
},
"SystemDiskSize": {
"Fn::If": [
"CreateSystemDiskSize",
{
"Ref": "ALIYUN::NoValue"
},
{
"Ref": "systemDiskSize"
}
]
},
"MinAmount": {
"Ref": "instancesCount"
},
"MaxAmount": {
"Ref": "instancesCount"
},
"Tags": [
{
"Key": "oos-generated",
"Value": {
"Ref": "executionId"
}
},
{
"Key": "region",
"Value": {
"Ref": "regionId"
}
}
]
}
}
},
"Metadata": {
"ALIYUN::ROS::Interface": {
"TemplateTags": [
"acs:integrate:oos:smc_create_and_verify_instance"
]
}
}
}
Outputs:
StackId:
Type: String
ValueSelector: StackId
- Name: untilStackReady
Action: 'ACS::WaitFor'
Description:
en: Tunggu status tumpukan CREATE_COMPLETE
OnSuccess: doInstanceCheck
OnError: queryStackStatusReason
Properties:
Service: ROS
API: GetStack
Parameters:
RegionId: '{{ regionId }}'
StackId: '{{createStack.StackId}}'
DesiredValues:
- CREATE_COMPLETE
StopRetryValues:
- CREATE_FAILED
- CHECK_FAILED
- ROLLBACK_FAILED
- ROLLBACK_COMPLETE
- CREATE_ROLLBACK_COMPLETE
PropertySelector: Status
Outputs:
instanceIds:
Type: String
ValueSelector: 'Outputs[0].OutputValue'
- Name: doInstanceCheck
Action: 'ACS::ECS::SMCVerifyInstanceByRunCommand'
OnSuccess: 'ACS::END'
OnError: deleteStack
Description:
en: Jalankan perintah asisten cloud untuk memeriksa Instance
Properties:
regionId: '{{ regionId }}'
instanceId: '{{ ACS::TaskLoopItem }}'
isDeleteInstance: '{{ isDeleteInstance }}'
commandContent: '{{ commandContent }}'
commandType: '{{ commandType }}'
workingDir: '{{ workingDir }}'
timeout: '{{ timeout }}'
Outputs:
commandOutput:
Type: String
ValueSelector: invocationOutput
Loop:
RateControl: '{{ rateControl }}'
Items: '{{ untilStackReady.instanceIds }}'
Outputs:
commandOutputs:
AggregateType: 'Fn::ListJoin'
AggregateField: commandOutput
- Name: queryStackStatusReason
Action: 'ACS::ExecuteAPI'
Description:
en: Kueri alasan kegagalan pembuatan tumpukan
OnError: deleteStack
OnSuccess: deleteStack
Properties:
Service: ROS
API: GetStack
Parameters:
RegionId: '{{ regionId }}'
StackId: '{{ createStack.StackId }}'
Outputs:
statusReason:
Type: String
ValueSelector: StatusReason
- Name: deleteStack
Description:
en: Hapus tumpukan
OnSuccess: 'ACS::END'
Action: 'ACS::ExecuteApi'
Properties:
Service: ROS
API: DeleteStack
Parameters:
RegionId: '{{ regionId }}'
StackId: '{{createStack.StackId}}'
Outputs:
instanceCheckResults:
Type: List
Value: '{{ doInstanceCheck.commandOutputs }}'