# 更新浮动IP - NeutronUpdateFloatingIp
#### 功能介绍
更新浮动IP。
更新时需在URL中给出浮动IP地址的ID。
port_id 为空，则表示浮动IP从端口解绑。
**说明：**
该接口有以下使用约束限制：
- 绑定浮动IP过程中，如果浮动IP处于"error"状态，请先尝试执行浮动IP解绑定动作。
  
- 不支持直接把已经绑定浮动IP的端口重新绑定到另外一个浮动IP上，必须先解绑再绑定。
  
 
#### 接口约束
绑定浮动IP过程中，如果浮动IP处于"error"状态，请先尝试执行浮动IP解绑定动作。不支持直接把已经绑定端口的浮动ip重新绑定到另外一个端口上，必须先解绑定再绑定
#### 调试
您可以在[API Explorer](https://console.huaweicloud.com/apiexplorer/#/openapi/EIP/doc?api=NeutronUpdateFloatingIp&version=v2)中调试该接口，支持自动认证鉴权。
#### 授权信息
账号具备所有API的调用权限，如果使用账号下的IAM用户调用当前API，该IAM用户需具备调用API所需的权限。
- 如果使用角色与策略授权，具体权限要求请参见[权限和授权项](https://support.huaweicloud.com/api-eip/eip_apipermission_0000.html)。
- 如果使用身份策略授权，当前API调用无需身份策略权限。
 
#### URI
PUT /v2.0/floatingips/{floatingip_id}
表1路径参数 
| 参数            | 是否必选 | 参数类型   | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
|:---|:---|:---|:---|
| floatingip_id | 是    | String | **参数解释：** 浮动IP地址的id。 **约束限制：** 创建浮动IP时不选，查询、更新、删除时是必选。 **取值范围：** 0-36个字符。 **默认取值：** 不涉及。 |
   
#### 请求参数
表2请求Body参数 
| 参数         | 是否必选 | 参数类型                                                                                                                 | 描述             |
|:---|:---|:---|:---|
| floatingip | 是    | [UpdateFloatingIpOption] object | 更新floatingip对象 |
   
 表3UpdateFloatingIpOption 
| 参数      | 是否必选 | 参数类型   | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
|:---|:---|:---|:---|
| port_id | 否    | String | **参数解释：** 端口id。 **约束限制：** 不涉及。 **取值范围：** 0-36个字符。 **默认取值：** 不涉及。 |
   
#### 响应参数
**状态码：200**
表4响应Body参数 
| 参数         | 参数类型                                                                                                                      | 描述           |
|:---|:---|:---|
| floatingip | [PostAndPutFloatingIpResp] object | floatingip对象 |
   
 表5PostAndPutFloatingIpResp 
| 参数                  | 参数类型   | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
|:---|:---|:---|
| fixed_ip_address    | String | **参数解释：** 关联端口的私有IP地址。 **取值范围：** 0-64个字符。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| floating_ip_address | String | **参数解释：** 浮动IP地址。 **取值范围：** 0-64个字符。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| floating_network_id | String | **参数解释：** 外部网络的id。 **取值范围：** 0-36个字符。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| id                  | String | **参数解释：** 浮动IP地址的id。 **取值范围：** 0-36个字符。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| port_id             | String | **参数解释：** 端口id。 **取值范围：** 0-36个字符。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| router_id           | String | **参数解释：** 所属路由器id。 **取值范围：** 0-36个字符。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| status              | String | **参数解释：** 网络状态。 **取值范围：** - DOWN：未绑定。   - ACTIVE：绑定。   - ERROR：异常。    |
| tenant_id           | String | **参数解释：** 项目id。 **取值范围：** 0-36个字符。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| dns_name            | String | **参数解释：** DNS名称。该参数当前仅在"华南-广州"开放。 **取值范围：** 0-255个字符。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| dns_domain          | String | **参数解释：** DNS域地址。该参数当前仅在"华南-广州"开放。 **取值范围：** 0-255个字符。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
   
#### 请求示例
- 解绑实例。
  ```
  {
    "floatingip" : {
      "port_id" : null
    }
  }
  ```
  
- 绑定实例，port id为f91f5763-c5a2-4458-979d-61e48b3c3fac。
  ```
  {
    "floatingip" : {
      "port_id" : "f91f5763-c5a2-4458-979d-61e48b3c3fac"
    }
  }
  ```
  
 
#### 响应示例
**状态码：200**
```
{
  "floatingip" : {
    "id" : "b997e0d4-3359-4c74-8f88-bc0af81cd5a2",
    "status" : "DOWN",
    "router_id" : null,
    "tenant_id" : "bbfe8c41dd034a07bebd592bf03b4b0c",
    "floating_network_id" : "0a2228f2-7f8a-45f1-8e09-9039e1d09975",
    "fixed_ip_address" : null,
    "floating_ip_address" : "88.88.215.205",
    "port_id" : null,
    "dns_name" : "ecs-88-99-103-61",
    "dns_domain" : "compute.myclouds-dns.com."
  }
}
```
#### SDK代码示例
SDK代码示例如下。
- [Java]
  - 解绑实例。
    ```
    package com.huaweicloud.sdk.test;
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.eip.v2.region.EipRegion;
    import com.huaweicloud.sdk.eip.v2.*;
    import com.huaweicloud.sdk.eip.v2.model.*;
    public class NeutronUpdateFloatingIpSolution {
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
            ICredential auth = new BasicCredentials()
                    .withAk(ak)
                    .withSk(sk);
            EipClient client = EipClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(EipRegion.valueOf("<YOUR REGION>"))
                    .build();
            NeutronUpdateFloatingIpRequest request = new NeutronUpdateFloatingIpRequest();
            request.withFloatingipId("{floatingip_id}");
            try {
                NeutronUpdateFloatingIpResponse response = client.neutronUpdateFloatingIp(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    ```
    
  
  - 绑定实例，port id为f91f5763-c5a2-4458-979d-61e48b3c3fac。
    ```
    package com.huaweicloud.sdk.test;
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.eip.v2.region.EipRegion;
    import com.huaweicloud.sdk.eip.v2.*;
    import com.huaweicloud.sdk.eip.v2.model.*;
    public class NeutronUpdateFloatingIpSolution {
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
            ICredential auth = new BasicCredentials()
                    .withAk(ak)
                    .withSk(sk);
            EipClient client = EipClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(EipRegion.valueOf("<YOUR REGION>"))
                    .build();
            NeutronUpdateFloatingIpRequest request = new NeutronUpdateFloatingIpRequest();
            request.withFloatingipId("{floatingip_id}");
            NeutronUpdateFloatingIpRequestBody body = new NeutronUpdateFloatingIpRequestBody();
            UpdateFloatingIpOption floatingipbody = new UpdateFloatingIpOption();
            floatingipbody.withPortId("f91f5763-c5a2-4458-979d-61e48b3c3fac");
            body.withFloatingip(floatingipbody);
            request.withBody(body);
            try {
                NeutronUpdateFloatingIpResponse response = client.neutronUpdateFloatingIp(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    ```
    
   
- [Python]
  - 解绑实例。
    ```
    # coding: utf-8
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkeip.v2.region.eip_region import EipRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkeip.v2 import *
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.environ["CLOUD_SDK_AK"]
        sk = os.environ["CLOUD_SDK_SK"]
        credentials = BasicCredentials(ak, sk)
        client = EipClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(EipRegion.value_of("<YOUR REGION>")) \
            .build()
        try:
            request = NeutronUpdateFloatingIpRequest()
            request.floatingip_id = "{floatingip_id}"
            response = client.neutron_update_floating_ip(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    ```
    
  
  - 绑定实例，port id为f91f5763-c5a2-4458-979d-61e48b3c3fac。
    ```
    # coding: utf-8
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkeip.v2.region.eip_region import EipRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkeip.v2 import *
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.environ["CLOUD_SDK_AK"]
        sk = os.environ["CLOUD_SDK_SK"]
        credentials = BasicCredentials(ak, sk)
        client = EipClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(EipRegion.value_of("<YOUR REGION>")) \
            .build()
        try:
            request = NeutronUpdateFloatingIpRequest()
            request.floatingip_id = "{floatingip_id}"
            floatingipbody = UpdateFloatingIpOption(
                port_id="f91f5763-c5a2-4458-979d-61e48b3c3fac"
            )
            request.body = NeutronUpdateFloatingIpRequestBody(
                floatingip=floatingipbody
            )
            response = client.neutron_update_floating_ip(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    ```
    
   
- [Go]
  - 解绑实例。
    ```
    package main
    import (
    "fmt"
    "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        eip "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/eip/v2"
    "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/eip/v2/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/eip/v2/region"
    )
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
        auth, err := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            SafeBuild()
        if err != nil {
            fmt.Println(err)
            return
        }
        hcClient, err := eip.EipClientBuilder().
             WithRegion(region.ValueOf("<YOUR REGION>")).
             WithCredential(auth).
             SafeBuild()
        if err != nil {
            fmt.Println(err)
            return
        }
        client := eip.NewEipClient(hcClient)
        request := &model.NeutronUpdateFloatingIpRequest{}
    request.FloatingipId = "{floatingip_id}"
    response, err := client.NeutronUpdateFloatingIp(request)
    if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    ```
    
  
  - 绑定实例，port id为f91f5763-c5a2-4458-979d-61e48b3c3fac。
    ```
    package main
    import (
    "fmt"
    "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        eip "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/eip/v2"
    "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/eip/v2/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/eip/v2/region"
    )
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
        auth, err := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            SafeBuild()
        if err != nil {
            fmt.Println(err)
            return
        }
        hcClient, err := eip.EipClientBuilder().
             WithRegion(region.ValueOf("<YOUR REGION>")).
             WithCredential(auth).
             SafeBuild()
        if err != nil {
            fmt.Println(err)
            return
        }
        client := eip.NewEipClient(hcClient)
        request := &model.NeutronUpdateFloatingIpRequest{}
    request.FloatingipId = "{floatingip_id}"
    portIdFloatingip:= "f91f5763-c5a2-4458-979d-61e48b3c3fac"
    floatingipbody := &model.UpdateFloatingIpOption{
    PortId: &portIdFloatingip,
    }
    request.Body = &model.NeutronUpdateFloatingIpRequestBody{
    Floatingip: floatingipbody,
    }
    response, err := client.NeutronUpdateFloatingIp(request)
    if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    ```
    
   
- [更多]
  更多编程语言的SDK代码示例，请参见[API Explorer](https://console.huaweicloud.com/apiexplorer/#/openapi/EIP/sdk?api=NeutronUpdateFloatingIp&version=v2)的代码示例页签，可生成自动对应的SDK代码示例。
#### 状态码
| 状态码 | 描述            |
|:---|:---|
| 200 | GET和PUT操作正常返回 |
   
#### 错误码
请参见[错误码](https://support.huaweicloud.com/api-eip/ErrorCode.html)。
