Updated on 2024-02-05 GMT+08:00

Creating Scripts in Agent Images

Precautions

  • You need to prepare scripts based on the OS of the servers to be migrated.
  • You need to prepare required scripts on your own. If you need help, contact the Huawei Cloud migration team.
  • The script examples below are only for reference.
  • You can download test scripts from the Huawei Support website for reference.

Windows

  1. In the C:\ directory, create a folder and name it smsWindowesAgent. In this folder, create three folders and name them bin, Python, and smsAgent respectively.

    Folder

    Function

    Location

    bin

    Stores the startup scripts and the peagent folder.

    C:\smsWiondowesAgent\bin

    python

    Installs Python.

    C:\smsWiondowesAgent\python

    smsAgent

    Stores Python scripts for obtaining metadata.

    C:\smsWiondowesAgent\smsAgent

    peagent

    Stores migration components transferred from source servers.

    C:\smsWiondowesAgent\bin\peagnet

  2. In the smsAgent folder, store the scripts used for obtaining certificates and keys.

    SMS-Agent uploads SSH public and private keys to metadata of target servers. The scripts you prepared here will be used to obtain the keys from the metadata. The table below shows the three types of metadata.

    Script

    Function

    Destination File

    sms_rsa_part (to be deprecated)

    Obtains SSH public keys (for server and identity authentication).

    C:\Users\Administrator\.ssh\authorized_keys,C:\ProgramData\ssh\ssh_host_rsa_key.pub

    sms_rsa_pri_part (to be deprecated)

    Obtains SSH private keys (for server and identity authentication).

    C:\ProgramData\ssh\ssh_host_rsa_key

    sms_rsa_host_old

    Obtains new SSH public keys (for server authentication).

    C:\ProgramData\ssh\ssh_host_rsa_key.pub

    sms_rsa_host_old_pri

    Obtains new SSH private keys (for server authentication).

    C:\ProgramData\ssh\ssh_host_rsa_key

    sms_rsa_identity

    Obtains SSH public key certificates (for identity authentication).

    C:\Users\Administrator.ssh\authorized_keys

    cert_part (to be deprecated)

    Obtains TSL 1.2 authentication public keys.

    C:\smsWindowesAgent\bin\peAgent\config\cert.pem

    prikey_part (to be deprecated)

    Obtains TSL 1.2 authentication private keys.

    C:\smsWindowesAgent\bin\peAgent\config\prikey.pem

    sms_rsa_part and sms_rsa_pri_part obtain the SSH public keys and private keys from metadata and write them to the destination files listed in the table above.

  3. In the bin directory, add a script to check whether peagent.exe is running.

    'tasklist /nh /fi "imagename eq peAgent.exe'

    • If it is not running, add the following command to start it.

      start cmd /k "C:\smsWindowesAgent\bin\peAgent\peAgent.exe"

    • If it is running, end the script.

    This script should be executed after the scripts in the smsAgent folder are executed.

Linux

  1. In the ~ directory, create a folder and name it smsMetadataAgent. In this folder, create three folders and name them bin, Python, and smsAgent respectively.

    Folder

    Function

    Location

    bin

    Stores the startup scripts and the peagent folder.

    ~\smsMetadataAgent\bin

    smsAgent

    Stores Python scripts for obtaining metadata.

    ~\smsMetadataAgent\smsAgent

  2. Prepare scripts for obtaining public and private keys from metadata by referring to the Windows section.

    Script

    Function

    Destination File

    sms_rsa_part (to be deprecated)

    Obtains SSH public keys (for server and identity authentication).

    root/.ssh/authorized_keys, /etc/ssh/ssh_host_rsa_key.pub

    sms_rsa_pri_part (to be deprecated)

    Obtains SSH private keys (for server and identity authentication).

    /etc/ssh/ssh_host_rsa_key

    sms_rsa_host_old

    Obtains new SSH public keys (for server authentication).

    /etc/ssh/ssh_host_rsa_key.pub

    sms_rsa_host_old_pri

    Obtains new SSH private keys (for server authentication).

    /etc/ssh/ssh_host_rsa_key

    sms_rsa_identity

    Obtains SSH public key certificates (for identity authentication).

    /root/.ssh/authorized_keys

    cert_part (to be deprecated)

    Obtains TSL 1.2 authentication public keys.

    /home/config/cert.pem

    prikey_part (to be deprecated)

    Obtains TSL 1.2 authentication private keys.

    /home/config/prikey.pem

    Prepare startup scripts by referring to the Windows section.