1package egoscale 2 3import ( 4 "context" 5 "fmt" 6 "net" 7) 8 9// Healthcheck represents an Healthcheck attached to an IP 10type Healthcheck struct { 11 Interval int64 `json:"interval,omitempty" doc:"healthcheck definition: time in seconds to wait for each check. Default: 10, minimum: 5"` 12 Mode string `json:"mode,omitempty" doc:"healthcheck definition: healthcheck mode can be either 'tcp' or 'http'"` 13 Path string `json:"path,omitempty" doc:"healthcheck definition: the path against which the 'http' healthcheck will be performed. Required if mode is 'http', ignored otherwise."` 14 Port int64 `json:"port,omitempty" doc:"healthcheck definition: the port against which the healthcheck will be performed. Required if a 'mode' is provided."` 15 StrikesFail int64 `json:"strikes-fail,omitempty" doc:"healthcheck definition: number of times to retry before declaring the healthcheck 'dead'. Default: 3"` 16 StrikesOk int64 `json:"strikes-ok,omitempty" doc:"healthcheck definition: number of times to retry before declaring the healthcheck 'alive'. Default: 2"` 17 Timeout int64 `json:"timeout,omitempty" doc:"healthcheck definition: time in seconds to wait for each check. Default: 2, cannot be greater than interval."` 18 TLSSNI string `json:"tls-sni,omitempty" doc:"healthcheck definition: server name to present for HTTPS checks"` 19 TLSSkipVerify bool `json:"tls-skip-verify" doc:"healthcheck definition: bypass certificate chain verification for HTTPS checks"` 20} 21 22// IPAddress represents an IP Address 23type IPAddress struct { 24 Allocated string `json:"allocated,omitempty" doc:"date the public IP address was acquired"` 25 Associated string `json:"associated,omitempty" doc:"date the public IP address was associated"` 26 AssociatedNetworkID *UUID `json:"associatednetworkid,omitempty" doc:"the ID of the Network associated with the IP address"` 27 AssociatedNetworkName string `json:"associatednetworkname,omitempty" doc:"the name of the Network associated with the IP address"` 28 Description string `json:"description,omitempty" doc:"The IP address description."` 29 ForVirtualNetwork bool `json:"forvirtualnetwork,omitempty" doc:"the virtual network for the IP address"` 30 Healthcheck *Healthcheck `json:"healthcheck,omitempty" doc:"The IP healthcheck configuration"` 31 ID *UUID `json:"id,omitempty" doc:"public IP address id"` 32 IPAddress net.IP `json:"ipaddress,omitempty" doc:"public IP address"` 33 IsElastic bool `json:"iselastic,omitempty" doc:"is an elastic ip"` 34 IsPortable bool `json:"isportable,omitempty" doc:"is public IP portable across the zones"` 35 IsSourceNat bool `json:"issourcenat,omitempty" doc:"true if the IP address is a source nat address, false otherwise"` 36 IsStaticNat *bool `json:"isstaticnat,omitempty" doc:"true if this ip is for static nat, false otherwise"` 37 IsSystem bool `json:"issystem,omitempty" doc:"true if this ip is system ip (was allocated as a part of deployVm or createLbRule)"` 38 NetworkID *UUID `json:"networkid,omitempty" doc:"the ID of the Network where ip belongs to"` 39 PhysicalNetworkID *UUID `json:"physicalnetworkid,omitempty" doc:"the physical network this belongs to"` 40 Purpose string `json:"purpose,omitempty" doc:"purpose of the IP address. In Acton this value is not null for Ips with isSystem=true, and can have either StaticNat or LB value"` 41 ReverseDNS []ReverseDNS `json:"reversedns,omitempty" doc:"the list of PTR record(s) associated with the ip address"` 42 State string `json:"state,omitempty" doc:"State of the ip address. Can be: Allocatin, Allocated and Releasing"` 43 Tags []ResourceTag `json:"tags,omitempty" doc:"the list of resource tags associated with ip address"` 44 VirtualMachineDisplayName string `json:"virtualmachinedisplayname,omitempty" doc:"virtual machine display name the ip address is assigned to (not null only for static nat Ip)"` 45 VirtualMachineID *UUID `json:"virtualmachineid,omitempty" doc:"virtual machine id the ip address is assigned to (not null only for static nat Ip)"` 46 VirtualMachineName string `json:"virtualmachinename,omitempty" doc:"virtual machine name the ip address is assigned to (not null only for static nat Ip)"` 47 VlanID *UUID `json:"vlanid,omitempty" doc:"the ID of the VLAN associated with the IP address. This parameter is visible to ROOT admins only"` 48 VlanName string `json:"vlanname,omitempty" doc:"the VLAN associated with the IP address"` 49 VMIPAddress net.IP `json:"vmipaddress,omitempty" doc:"virtual machine (dnat) ip address (not null only for static nat Ip)"` 50 ZoneID *UUID `json:"zoneid,omitempty" doc:"the ID of the zone the public IP address belongs to"` 51 ZoneName string `json:"zonename,omitempty" doc:"the name of the zone the public IP address belongs to"` 52} 53 54// ResourceType returns the type of the resource 55func (IPAddress) ResourceType() string { 56 return "PublicIpAddress" 57} 58 59// ListRequest builds the ListAdresses request 60func (ipaddress IPAddress) ListRequest() (ListCommand, error) { 61 req := &ListPublicIPAddresses{ 62 AssociatedNetworkID: ipaddress.AssociatedNetworkID, 63 ID: ipaddress.ID, 64 IPAddress: ipaddress.IPAddress, 65 PhysicalNetworkID: ipaddress.PhysicalNetworkID, 66 VlanID: ipaddress.VlanID, 67 ZoneID: ipaddress.ZoneID, 68 } 69 if ipaddress.IsElastic { 70 req.IsElastic = &ipaddress.IsElastic 71 } 72 if ipaddress.IsSourceNat { 73 req.IsSourceNat = &ipaddress.IsSourceNat 74 } 75 if ipaddress.ForVirtualNetwork { 76 req.ForVirtualNetwork = &ipaddress.ForVirtualNetwork 77 } 78 79 return req, nil 80} 81 82// Delete removes the resource 83func (ipaddress IPAddress) Delete(ctx context.Context, client *Client) error { 84 if ipaddress.ID == nil { 85 return fmt.Errorf("an IPAddress may only be deleted using ID") 86 } 87 88 return client.BooleanRequestWithContext(ctx, &DisassociateIPAddress{ 89 ID: ipaddress.ID, 90 }) 91} 92 93// AssociateIPAddress (Async) represents the IP creation 94type AssociateIPAddress struct { 95 Description string `json:"description,omitempty" doc:"The IP address description."` 96 HealthcheckInterval int64 `json:"interval,omitempty" doc:"healthcheck definition: time in seconds to wait for each check. Default: 10, minimum: 5"` 97 HealthcheckMode string `json:"mode,omitempty" doc:"healthcheck definition: healthcheck mode can be either 'tcp', 'http', or 'https'"` 98 HealthcheckPath string `json:"path,omitempty" doc:"healthcheck definition: the path against which the 'http' healthcheck will be performed. Required if mode is 'http' or 'https', ignored otherwise."` 99 HealthcheckPort int64 `json:"port,omitempty" doc:"healthcheck definition: the port against which the healthcheck will be performed. Required if a 'mode' is provided."` 100 HealthcheckStrikesFail int64 `json:"strikes-fail,omitempty" doc:"healthcheck definition: number of times to retry before declaring the healthcheck 'dead'. Default: 3"` 101 HealthcheckStrikesOk int64 `json:"strikes-ok,omitempty" doc:"healthcheck definition: number of times to retry before declaring the healthcheck 'alive'. Default: 2"` 102 HealthcheckTimeout int64 `json:"timeout,omitempty" doc:"healthcheck definition: time in seconds to wait for each check. Default: 2, cannot be greater than interval."` 103 HealthcheckTLSSkipVerify bool `json:"tls-skip-verify,omitempty" doc:"healthcheck definition: skip TLS verification for HTTPS checks. Default: false"` 104 HealthcheckTLSSNI string `json:"tls-sni,omitempty" doc:"healthcheck definition: server name to present for HTTPS checks. Default: no server name is presented"` 105 ZoneID *UUID `json:"zoneid,omitempty" doc:"the ID of the availability zone you want to acquire a public IP address from"` 106 _ bool `name:"associateIpAddress" description:"Acquires and associates a public IP to an account."` 107} 108 109// Response returns the struct to unmarshal 110func (AssociateIPAddress) Response() interface{} { 111 return new(AsyncJobResult) 112} 113 114// AsyncResponse returns the struct to unmarshal the async job 115func (AssociateIPAddress) AsyncResponse() interface{} { 116 return new(IPAddress) 117} 118 119// DisassociateIPAddress (Async) represents the IP deletion 120type DisassociateIPAddress struct { 121 ID *UUID `json:"id" doc:"the id of the public ip address to disassociate"` 122 _ bool `name:"disassociateIpAddress" description:"Disassociates an ip address from the account."` 123} 124 125// Response returns the struct to unmarshal 126func (DisassociateIPAddress) Response() interface{} { 127 return new(AsyncJobResult) 128} 129 130// AsyncResponse returns the struct to unmarshal the async job 131func (DisassociateIPAddress) AsyncResponse() interface{} { 132 return new(BooleanResponse) 133} 134 135// UpdateIPAddress (Async) represents the IP modification 136type UpdateIPAddress struct { 137 Description string `json:"description,omitempty" doc:"The IP address description."` 138 HealthcheckInterval int64 `json:"interval,omitempty" doc:"healthcheck definition: time in seconds to wait for each check. Default: 10, minimum: 5"` 139 HealthcheckMode string `json:"mode,omitempty" doc:"healthcheck definition: healthcheck mode can be either 'tcp', 'http', or 'https'"` 140 HealthcheckPath string `json:"path,omitempty" doc:"healthcheck definition: the path against which the 'http' healthcheck will be performed. Required if mode is 'http', ignored otherwise."` 141 HealthcheckPort int64 `json:"port,omitempty" doc:"healthcheck definition: the port against which the healthcheck will be performed. Required if a 'mode' is provided."` 142 HealthcheckStrikesFail int64 `json:"strikes-fail,omitempty" doc:"healthcheck definition: number of times to retry before declaring the healthcheck 'dead'. Default: 3"` 143 HealthcheckStrikesOk int64 `json:"strikes-ok,omitempty" doc:"healthcheck definition: number of times to retry before declaring the healthcheck 'alive'. Default: 2"` 144 HealthcheckTimeout int64 `json:"timeout,omitempty" doc:"healthcheck definition: time in seconds to wait for each check. Default: 2, cannot be greater than interval."` 145 HealthcheckTLSSNI string `json:"tls-sni,omitempty" doc:"healthcheck definition: server name to present for HTTPS checks"` 146 HealthcheckTLSSkipVerify bool `json:"tls-skip-verify,omitempty" doc:"healthcheck definition: bypass certificate chain verification for HTTPS checks"` 147 ID *UUID `json:"id" doc:"the id of the public IP address to update"` 148 _ bool `name:"updateIpAddress" description:"Updates an IP address"` 149} 150 151// Response returns the struct to unmarshal 152func (UpdateIPAddress) Response() interface{} { 153 return new(AsyncJobResult) 154} 155 156// AsyncResponse returns the struct to unmarshal the async job 157func (UpdateIPAddress) AsyncResponse() interface{} { 158 return new(IPAddress) 159} 160 161//go:generate go run generate/main.go -interface=Listable ListPublicIPAddresses 162 163// ListPublicIPAddresses represents a search for public IP addresses 164type ListPublicIPAddresses struct { 165 AllocatedOnly *bool `json:"allocatedonly,omitempty" doc:"limits search results to allocated public IP addresses"` 166 AssociatedNetworkID *UUID `json:"associatednetworkid,omitempty" doc:"lists all public IP addresses associated to the network specified"` 167 ForLoadBalancing *bool `json:"forloadbalancing,omitempty" doc:"list only ips used for load balancing"` 168 ForVirtualNetwork *bool `json:"forvirtualnetwork,omitempty" doc:"the virtual network for the IP address"` 169 ID *UUID `json:"id,omitempty" doc:"lists ip address by id"` 170 IPAddress net.IP `json:"ipaddress,omitempty" doc:"lists the specified IP address"` 171 IsElastic *bool `json:"iselastic,omitempty" doc:"list only elastic ip addresses"` 172 IsSourceNat *bool `json:"issourcenat,omitempty" doc:"list only source nat ip addresses"` 173 IsStaticNat *bool `json:"isstaticnat,omitempty" doc:"list only static nat ip addresses"` 174 Keyword string `json:"keyword,omitempty" doc:"List by keyword"` 175 Page int `json:"page,omitempty"` 176 PageSize int `json:"pagesize,omitempty"` 177 PhysicalNetworkID *UUID `json:"physicalnetworkid,omitempty" doc:"lists all public IP addresses by physical network id"` 178 Tags []ResourceTag `json:"tags,omitempty" doc:"List resources by tags (key/value pairs). Note: multiple tags are OR'ed, not AND'ed."` 179 VlanID *UUID `json:"vlanid,omitempty" doc:"lists all public IP addresses by VLAN ID"` 180 ZoneID *UUID `json:"zoneid,omitempty" doc:"lists all public IP addresses by Zone ID"` 181 _ bool `name:"listPublicIpAddresses" description:"Lists all public ip addresses"` 182} 183 184// ListPublicIPAddressesResponse represents a list of public IP addresses 185type ListPublicIPAddressesResponse struct { 186 Count int `json:"count"` 187 PublicIPAddress []IPAddress `json:"publicipaddress"` 188} 189