Obtaining Metadata

Scenarios

ECS metadata includes basic information of an ECS on the cloud platform, such as the ECS ID, hostname, and network information. ECS metadata can be obtained using either OpenStack or EC2 compatible APIs, as shown in Table 1. The following describes the URI and methods of using the supported ECS metadata.

Notes

If the metadata contains sensitive data, take appropriate measures to protect the sensitive data, for example, controlling access permissions and encrypting the data.

Perform the following configuration on the firewall:

ECS Metadata Types

Table 1 does not contain metadata items ami-id, ami-launch-index, ami-manifest-path, block-device-mapping/, instance-action, instance-id and reservation-id. These metadata items are not compatible with EC2 and are not recommended.

Table 1 ECS metadata types

Metadata Type

Metadata Item

Description

OpenStack

/meta_data.json

Displays ECS metadata.

For the key fields in the ECS metadata, see Table 2.

OpenStack

/password

Displays the password for logging in to an ECS.

This metadata is used by Cloudbase-Init to store ciphertext passwords during initialization of key-pair-authenticated Windows ECSs.

OpenStack

/user_data

Displays ECS user data.

This metadata allows you to specify scripts and configuration files for initializing ECSs. For details, see Passing User Data to ECSs.

For password-authenticated Linux ECSs, this metadata is used to save password injection scripts.

OpenStack

/network_data.json

Displays ECS network information.

OpenStack

/securitykey

Obtains temporary AKs and SKs.

Before enabling an ECS to obtain a temporary AK and SK, make sure that the op_svc_ecs account has been authorized on IAM and that the desired ECS resources have been authorized for management.

EC2

/meta-data/hostname

Displays the name of the host accommodating an ECS.

To remove the suffix .novalocal from an ECS, see:

Is an ECS Hostname with Suffix .novalocal Normal?

EC2

/meta-data/local-hostname

The meaning of this field is the same as that of hostname.

EC2

/meta-data/public-hostname

The meaning of this field is the same as that of hostname.

EC2

/meta-data/instance-type

Displays an ECS flavor.

EC2

/meta-data/local-ipv4

Displays the fixed IP address of an ECS.

If there are multiple NICs, only the IP address of the primary NIC is displayed.

EC2

/meta-data/placement/availability-zone

Displays the AZ accommodating an ECS.

EC2

/meta-data/public-ipv4

Displays the EIP bound to an ECS.

If there are multiple NICs, only the EIP of the primary NIC is displayed.

EC2

/meta-data/public-keys/0/openssh-key

Displays the public key of an ECS.

EC2

/user-data

Displays ECS user data.

EC2

/meta-data/security-groups

Displays the security group to which an ECS belongs.

Table 2 Metadata key fields

Parameter

Type

Description

uuid

String

Specifies an ECS ID.

availability_zone

String

Specifies the AZ where an ECS locates.

meta

Dict

Specifies the metadata information, including the image name, image ID, and VPC ID.

hostname

String

Specifies the name of the host accommodating an ECS.

To remove the suffix .novalocal from an ECS, see:

Is an ECS Hostname with Suffix .novalocal Normal?

Prerequisites

Metadata (OpenStack Metadata API)

Displays ECS metadata.

User Data (OpenStack Metadata API)

Displays ECS user data. The value is configured only when you create an ECS. It cannot be changed after the configuration.

Network Data (OpenStack Metadata API)

Displays information about all NICs attached to an ECS, including their DNS server addresses, network bandwidth, IDs, private IP addresses, EIPs, and MAC addresses.

Security Key (OpenStack Metadata API)

Obtains temporary AKs and SKs.

  • If an ECS needs to obtain a temporary AK and SK, go to the ECS details page, and configure Agency for the ECS in the Management Information area so that the ECS is authorized on IAM.
  • The validity period of a temporary AK and SK is one hour. The temporary AK and SK are updated 10 minutes ahead of the expiration time. During the 10 minutes, both the new and old temporary AKs and SKs can be used.
  • When using temporary AKs and SKs, add 'X-Security-Token':{securitytoken} in the message header. securitytoken is the value returned when a call is made to the API.

User Data (EC2 Compatible API)

Displays ECS user data. The value is configured only when you create an ECS. It cannot be changed after the configuration.

Hostname (EC2 Compatible API)

Displays the name of the host accommodating an ECS. The .novalocal suffix will be added later.

Instance Type (EC2 Compatible API)

Displays an ECS flavor.

Local IPv4 (EC2 Compatible API)

Displays the fixed IP address of an ECS. If there are multiple NICs, only the IP address of the primary NIC is displayed.

Availability Zone (EC2 Compatible API)

Displays the AZ accommodating an ECS.

Public IPv4 (EC2 Compatible API)

Displays the EIP bound to an ECS. If there are multiple NICs, only the EIP of the primary NIC is displayed.

Public Keys (EC2 Compatible API)

Displays the public key of an ECS.

Helpful Links

Why Can't My Linux ECS Obtain Metadata?