1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Extensions ;
4+ using System . Threading ;
5+ using System . Threading . Tasks ;
6+ using Newtonsoft . Json ;
7+ using Newtonsoft . Json . Linq ;
8+ using OpenStack . Serialization ;
9+
10+ namespace OpenStack . Networking . v2 . Layer3
11+ {
12+ /// <summary>
13+ /// An external IP address that you map to a port in an internal network
14+ /// </summary>
15+ [ JsonConverterWithConstructor ( typeof ( RootWrapperConverter ) , "floatingip" ) ]
16+ public class FloatingIP : IHaveExtraData , IServiceResource
17+ {
18+ /// <summary>
19+ /// The floating IP identifier.
20+ /// </summary>
21+ [ JsonProperty ( "id" ) ]
22+ public Identifier Id { get ; set ; }
23+
24+ /// <summary>
25+ /// The associated router.
26+ /// </summary>
27+ [ JsonProperty ( "router_id" ) ]
28+ public Identifier RouterId { get ; set ; }
29+
30+ /// <summary>
31+ /// The network associated with the floating IP.
32+ /// </summary>
33+ [ JsonProperty ( "floating_network_id" ) ]
34+ public Identifier NetworkId { get ; set ; }
35+
36+ /// <summary>
37+ /// The fixed IP address that is associated with the floating IP address.
38+ /// </summary>
39+ [ JsonProperty ( "fixed_ip_address" ) ]
40+ public string FixedIPAddress { get ; set ; }
41+
42+ /// <summary>
43+ /// The floating IP address.
44+ /// </summary>
45+ [ JsonProperty ( "floating_ip_address" ) ]
46+ public string FloatingIPAddress { get ; set ; }
47+
48+ /// <summary>
49+ /// The associated port.
50+ /// </summary>
51+ [ JsonProperty ( "port_id" ) ]
52+ public Identifier PortId { get ; set ; }
53+
54+ /// <summary>
55+ /// The status of the floating IP address.
56+ /// </summary>
57+ [ JsonProperty ( "status" ) ]
58+ public FloatingIPStatus Status { get ; set ; }
59+
60+ [ JsonExtensionData ]
61+ IDictionary < string , JToken > IHaveExtraData . Data { get ; set ; } = new Dictionary < string , JToken > ( ) ;
62+
63+ object IServiceResource . Owner { get ; set ; }
64+
65+ /// <inheritdoc cref="NetworkingApiBuilder.DeleteFloatingIPAsync"/>
66+ /// <exception cref="InvalidOperationException">Thrown when a resource as not constructed by the SDK.</exception>
67+ public Task DeleteAsync ( CancellationToken cancellationToken = default ( CancellationToken ) )
68+ {
69+ var networking = this . GetOwnerOrThrow < NetworkingApiBuilder > ( ) ;
70+ return networking . DeleteFloatingIPAsync ( Id , cancellationToken ) ;
71+ }
72+
73+ /// <summary>
74+ /// Associates the floating IP withe the specified port.
75+ /// </summary>
76+ /// <param name="portId">The port identifier.</param>
77+ /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
78+ /// <exception cref="InvalidOperationException">Thrown when a resource as not constructed by the SDK.</exception>
79+ public async Task AssociateAsync ( Identifier portId , CancellationToken cancellationToken = default ( CancellationToken ) )
80+ {
81+ var networking = this . GetOwnerOrThrow < NetworkingApiBuilder > ( ) ;
82+ var request = new FloatingIPUpdateDefinition { PortId = portId } ;
83+ var result = await networking . UpdateFloatingIPAsync < FloatingIP > ( Id , request , cancellationToken ) . ConfigureAwait ( false ) ;
84+ result . CopyProperties ( this ) ;
85+ }
86+
87+ /// <summary>
88+ /// Frees the floating IP from any associations.
89+ /// </summary>
90+ /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
91+ /// <exception cref="InvalidOperationException">Thrown when a resource as not constructed by the SDK.</exception>
92+ public async Task DisassociateAsync ( CancellationToken cancellationToken = default ( CancellationToken ) )
93+ {
94+ var networking = this . GetOwnerOrThrow < NetworkingApiBuilder > ( ) ;
95+ var request = new FloatingIPUpdateDefinition { PortId = null } ;
96+ var result = await networking . UpdateFloatingIPAsync < FloatingIP > ( Id , request , cancellationToken ) . ConfigureAwait ( false ) ;
97+ result . CopyProperties ( this ) ;
98+ }
99+ }
100+ }
0 commit comments