Estos contenidos se han traducido de forma automática para su comodidad, pero Huawei Cloud no garantiza la exactitud de estos. Para consultar los contenidos originales, acceda a la versión en inglés.
Centro de ayuda> Elastic IP> Referencia de la API> Ejemplos de aplicación> Asignación de un EIP con un ancho de banda compartido específico
Actualización más reciente 2022-11-08 GMT+08:00

Asignación de un EIP con un ancho de banda compartido específico

Escenarios

Esta sección describe cómo asignar un EIP con un ancho de banda compartido específico llamando a las API.

Prerrequisitos

Ha planificado la región a la que desea asignar el EIP y ha obtenido el endpoint necesario para llamar a las API. Para más detalles, consulte Endpoint de EIP.

Si utiliza un token para la autenticación, debe obtener el token y agregar X-Auth-Token al encabezado de solicitud cuando realice una llamada a la API.

El token obtenido de IAM es válido por solo 24 horas. Si desea utilizar un token para la autenticación, puede almacenarlo en caché para evitar llamadas frecuentes.

Procedimiento

  1. Assign a shared bandwidth.
    1. Enviar POST https://Endpoint/v2.0/project_id/bandwidths. El parámetro project_id indica el ID del proyecto.
    2. Agregue X-Auth-Token al encabezado de solicitud.
    3. Specify the following parameters in the request body:
      { 
           "bandwidth": { 
               "name": "bandwidth123", 
               "size": 10
           } 
       }
    4. Check the response message.
      • The request is successful if the following response is displayed. In the response, indicates the bandwidth ID.id
        { 
           "bandwidth": { 
             "id": "1bffc5f2-ff19-45a6-96d2-dfdca49cc387", 
             "name": "bandwidth123", 
             "size": 10, 
             "share_type": "WHOLE", 
             "publicip_info": [], 
             "tenant_id": "26ae5181a416420998eb2093aaed84d9", 
             "bandwidth_type": "share", 
             "charge_mode": "bandwidth", 
             "enterprise_project_id": "0", 
             "status": "NORMAL", 
             "created_at": "2020-04-21T07:58:02Z",  
             "updated_at": "2020-04-21T07:58:02Z"  
           } 
         }
      • Para obtener más información sobre los códigos de error cuando la solicitud es anormal, consulte Códigos de error.
  2. Query the shared bandwidth details.
    1. Enviar Get https://Endpoint//v1/project_id/bandwidths/bandwidth_id. El parámetro project_id indica el ID del proyecto.
    2. Agregue X-Auth-Token al encabezado de solicitud.
    3. Check the response message.
      • The request is successful if the following response is displayed. In the response, indicates the bandwidth ID.id
        { 
             "bandwidth": { 
                 "id": "1bffc5f2-ff19-45a6-96d2-dfdca49cc387", 
                 "name": "bandwidth123", 
                 "size": 10, 
                 "share_type": "WHOLE", 
                 "publicip_info": [ 
                     { 
                         "publicip_id": "ff156c26-bcc9-4541-a75c-42baf8b9748f", 
                         "publicip_address": "114.xx.xx.244", 
                         "ip_version": 4, 
                         "publicip_type": "5_sbgp" 
                     } 
                 ], 
                 "tenant_id": "b3292dde618e40408e30cd87455a0652", 
                 "bandwidth_type": "sbgp", 
                 "charge_mode": "bandwidth", 
                 "enterprise_project_id": "0", 
                 "status": "NORMAL", 
                 "created_at": "2020-04-21T07:58:02Z", 
                 "updated_at": "2020-04-21T07:58:02Z" 
             } 
         }
      • Para obtener más información sobre los códigos de error cuando la solicitud es anormal, consulte Códigos de error.
  3. Assign an EIP using the shared bandwidth.
    1. Enviar POST https://Endpoint/v1/project_id/publicips. El parámetro project_id indica el ID del proyecto.
    2. Agregue X-Auth-Token al encabezado de solicitud.
    3. Specify the following parameters in the request body:
      {     
           "publicip": {         
               "type": "5_bgp",         
               "ip_version": 6        
        },    
           "bandwidth": {        
               "name": "bandwidth123",        
               "size": 10,         
               "share_type": "WHOLE", 
               "id":"1bffc5f2-ff19-45a6-96d2-dfdca49cc387" 
           },          
           "enterprise_project_id":"0"   
       }
    4. Check the response message.
      • The request is successful if the following response is displayed.
        { 
             "publicip": { 
                 "id": "f588ccfa-8750-4d7c-bf5d-2ede24414706", 
                 "status": "PENDING_CREATE", 
                 "type": "5_bgp", 
                 "public_ip_address": "161.xx.xx.7", 
                 "tenant_id": "8b7e35ad379141fc9df3e178bd64f55c", 
                 "ip_version": 4, 
                 "create_time": "2015-07-16 04:10:52", 
                 "bandwidth_size": 0, 
                 "enterprise_project_id":"b261ac1f-2489-4bc7-b31b-c33c3346a439" 
             } 
         }
      • Para obtener más información sobre los códigos de error cuando la solicitud es anormal, consulte Códigos de error.
  4. Query EIP details.
    1. Enviar GET /v1/project_id/publicips/publicip_id. El parámetro project_id indica el ID del proyecto.
    2. Agregue X-Auth-Token al encabezado de solicitud.
    3. Check the response message.
      { 
           "publicip": {
                  "id": "3ec9fea0-2d4c-49e2-8aca-ce883eae547d",
                  "type": "5_bgp",
                  "public_ip_address": "10.246.164.87",
                  "status": "DOWN",
                  "tenant_id": "060576782980d5762f9ec014dd2f1148",
                  "create_time": "2020-08-13 12:55:27",
                  "bandwidth_id": "1bffc5f2-ff19-45a6-96d2-dfdca49cc387",
                  "bandwidth_name": "bandwidth123",
                  "bandwidth_share_type": "WHOLE",
                  "bandwidth_size": 10,
                  "profile": {},
                  "enterprise_project_id": "a380829c-db6f-4db3-b5b6-cc377f7a3ff8",
                  "ip_version": 4
              }
       }