github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/apiserver/params/network.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package params 5 6 import ( 7 "github.com/juju/juju/network" 8 ) 9 10 // ----- 11 // Parameters field types. 12 // ----- 13 14 // Subnet describes a single subnet within a network. 15 type Subnet struct { 16 // CIDR of the subnet in IPv4 or IPv6 notation. 17 CIDR string `json:"cidr"` 18 19 // ProviderId is the provider-specific subnet ID (if applicable). 20 ProviderId string `json:"provider-id,omitempty"` 21 22 // VLANTag needs to be between 1 and 4094 for VLANs and 0 for 23 // normal networks. It's defined by IEEE 802.1Q standard. 24 VLANTag int `json:"vlan-tag"` 25 26 // Life is the subnet's life cycle value - Alive means the subnet 27 // is in use by one or more machines, Dying or Dead means the 28 // subnet is about to be removed. 29 Life Life `json:"life"` 30 31 // SpaceTag is the Juju network space this subnet is associated 32 // with. 33 SpaceTag string `json:"space-tag"` 34 35 // Zones contain one or more availability zones this subnet is 36 // associated with. 37 Zones []string `json:"zones"` 38 39 // Status returns the status of the subnet, whether it is in use, not 40 // in use or terminating. 41 Status string `json:"status,omitempty"` 42 } 43 44 // NetworkConfig describes the necessary information to configure 45 // a single network interface on a machine. This mostly duplicates 46 // network.InterfaceInfo type and it's defined here so it can be kept 47 // separate and stable as definition to ensure proper wire-format for 48 // the API. 49 type NetworkConfig struct { 50 // DeviceIndex specifies the order in which the network interface 51 // appears on the host. The primary interface has an index of 0. 52 DeviceIndex int `json:"device-index"` 53 54 // MACAddress is the network interface's hardware MAC address 55 // (e.g. "aa:bb:cc:dd:ee:ff"). 56 MACAddress string `json:"mac-address"` 57 58 // CIDR of the network, in 123.45.67.89/24 format. 59 CIDR string `json:"cidr"` 60 61 // MTU is the Maximum Transmission Unit controlling the maximum size of the 62 // protocol packats that the interface can pass through. It is only used 63 // when > 0. 64 MTU int `json:"mtu"` 65 66 // ProviderId is a provider-specific network interface id. 67 ProviderId string `json:"provider-id"` 68 69 // ProviderSubnetId is a provider-specific subnet id, to which the 70 // interface is attached to. 71 ProviderSubnetId string `json:"provider-subnet-id"` 72 73 // ProviderSpaceId is a provider-specific space id, to which the interface 74 // is attached to, if known and supported. 75 ProviderSpaceId string `json:"provider-space-id"` 76 77 // ProviderAddressId is the provider-specific id of the assigned address, if 78 // supported and known. 79 ProviderAddressId string `json:"provider-address-id"` 80 81 // ProviderVLANId is the provider-specific id of the assigned address's 82 // VLAN, if supported and known. 83 ProviderVLANId string `json:"provider-vlan-id"` 84 85 // VLANTag needs to be between 1 and 4094 for VLANs and 0 for 86 // normal networks. It's defined by IEEE 802.1Q standard. 87 VLANTag int `json:"vlan-tag"` 88 89 // InterfaceName is the raw OS-specific network device name (e.g. 90 // "eth1", even for a VLAN eth1.42 virtual interface). 91 InterfaceName string `json:"interface-name"` 92 93 // ParentInterfaceName is the name of the parent interface to use, if known. 94 ParentInterfaceName string `json:"parent-interface-name"` 95 96 // InterfaceType is the type of the interface. 97 InterfaceType string `json:"interface-type"` 98 99 // Disabled is true when the interface needs to be disabled on the 100 // machine, e.g. not to configure it at all or stop it if running. 101 Disabled bool `json:"disabled"` 102 103 // NoAutoStart is true when the interface should not be configured 104 // to start automatically on boot. By default and for 105 // backwards-compatibility, interfaces are configured to 106 // auto-start. 107 NoAutoStart bool `json:"no-auto-start,omitempty"` 108 109 // ConfigType, if set, defines what type of configuration to use. 110 // See network.InterfaceConfigType for more info. If not set, for 111 // backwards-compatibility, "dhcp" is assumed. 112 ConfigType string `json:"config-type,omitempty"` 113 114 // Address contains an optional static IP address to configure for 115 // this network interface. The subnet mask to set will be inferred 116 // from the CIDR value. 117 Address string `json:"address,omitempty"` 118 119 // DNSServers contains an optional list of IP addresses and/or 120 // hostnames to configure as DNS servers for this network 121 // interface. 122 DNSServers []string `json:"dns-servers,omitempty"` 123 124 // DNSServers contains an optional list of IP addresses and/or 125 // hostnames to configure as DNS servers for this network 126 // interface. 127 DNSSearchDomains []string `json:"dns-search-domains,omitempty"` 128 129 // Gateway address, if set, defines the default gateway to 130 // configure for this network interface. For containers this 131 // usually (one of) the host address(es). 132 GatewayAddress string `json:"gateway-address,omitempty"` 133 } 134 135 // NetworkConfigs holds the network configuration for multiple networks 136 type NetworkConfigs struct { 137 Results []NetworkConfig `json:"results"` 138 Errors []error `json:"errors,omitempty"` 139 } 140 141 // ProviderInterfaceInfoResults holds the results of a 142 // GetProviderInterfaceInfo call. 143 type ProviderInterfaceInfoResults struct { 144 Results []ProviderInterfaceInfoResult `json:"results"` 145 } 146 147 // ProviderInterfaceInfoResult stores the provider interface 148 // information for one machine, or any error that occurred getting the 149 // information for that machine. 150 type ProviderInterfaceInfoResult struct { 151 MachineTag string `json:"machine-tag"` 152 Interfaces []ProviderInterfaceInfo `json:"interfaces"` 153 Error *Error `json:"error,omitempty"` 154 } 155 156 // ProviderInterfaceInfo stores the details needed to identify an 157 // interface to a provider. It's the params equivalent of 158 // network.ProviderInterfaceInfo, defined here separately to ensure 159 // that API structures aren't inadvertently changed by internal 160 // changes. 161 type ProviderInterfaceInfo struct { 162 InterfaceName string `json:"interface-name"` 163 MACAddress string `json:"mac-address"` 164 ProviderId string `json:"provider-id"` 165 } 166 167 // Port encapsulates a protocol and port number. It is used in API 168 // requests/responses. See also network.Port, from/to which this is 169 // transformed. 170 type Port struct { 171 Protocol string `json:"protocol"` 172 Number int `json:"number"` 173 } 174 175 // FromNetworkPort is a convenience helper to create a parameter 176 // out of the network type, here for Port. 177 func FromNetworkPort(p network.Port) Port { 178 return Port{ 179 Protocol: p.Protocol, 180 Number: p.Number, 181 } 182 } 183 184 // NetworkPort is a convenience helper to return the parameter 185 // as network type, here for Port. 186 func (p Port) NetworkPort() network.Port { 187 return network.Port{ 188 Protocol: p.Protocol, 189 Number: p.Number, 190 } 191 } 192 193 // PortRange represents a single range of ports. It is used in API 194 // requests/responses. See also network.PortRange, from/to which this is 195 // transformed. 196 type PortRange struct { 197 FromPort int `json:"from-port"` 198 ToPort int `json:"to-port"` 199 Protocol string `json:"protocol"` 200 } 201 202 // FromNetworkPortRange is a convenience helper to create a parameter 203 // out of the network type, here for PortRange. 204 func FromNetworkPortRange(pr network.PortRange) PortRange { 205 return PortRange{ 206 FromPort: pr.FromPort, 207 ToPort: pr.ToPort, 208 Protocol: pr.Protocol, 209 } 210 } 211 212 // NetworkPortRange is a convenience helper to return the parameter 213 // as network type, here for PortRange. 214 func (pr PortRange) NetworkPortRange() network.PortRange { 215 return network.PortRange{ 216 FromPort: pr.FromPort, 217 ToPort: pr.ToPort, 218 Protocol: pr.Protocol, 219 } 220 } 221 222 // EntityPort holds an entity's tag, a protocol and a port. 223 type EntityPort struct { 224 Tag string `json:"tag"` 225 Protocol string `json:"protocol"` 226 Port int `json:"port"` 227 } 228 229 // EntitiesPorts holds the parameters for making an OpenPort or 230 // ClosePort on some entities. 231 type EntitiesPorts struct { 232 Entities []EntityPort `json:"entities"` 233 } 234 235 // EntityPortRange holds an entity's tag, a protocol and a port range. 236 type EntityPortRange struct { 237 Tag string `json:"tag"` 238 Protocol string `json:"protocol"` 239 FromPort int `json:"from-port"` 240 ToPort int `json:"to-port"` 241 } 242 243 // EntitiesPortRanges holds the parameters for making an OpenPorts or 244 // ClosePorts on some entities. 245 type EntitiesPortRanges struct { 246 Entities []EntityPortRange `json:"entities"` 247 } 248 249 // Address represents the location of a machine, including metadata 250 // about what kind of location the address describes. It's used in 251 // the API requests/responses. See also network.Address, from/to 252 // which this is transformed. 253 type Address struct { 254 Value string `json:"value"` 255 Type string `json:"type"` 256 Scope string `json:"scope"` 257 SpaceName string `json:"space-name,omitempty"` 258 } 259 260 // FromNetworkAddress is a convenience helper to create a parameter 261 // out of the network type, here for Address. 262 func FromNetworkAddress(naddr network.Address) Address { 263 return Address{ 264 Value: naddr.Value, 265 Type: string(naddr.Type), 266 Scope: string(naddr.Scope), 267 SpaceName: string(naddr.SpaceName), 268 } 269 } 270 271 // NetworkAddress is a convenience helper to return the parameter 272 // as network type, here for Address. 273 func (addr Address) NetworkAddress() network.Address { 274 return network.Address{ 275 Value: addr.Value, 276 Type: network.AddressType(addr.Type), 277 Scope: network.Scope(addr.Scope), 278 SpaceName: network.SpaceName(addr.SpaceName), 279 } 280 } 281 282 // FromNetworkAddresses is a convenience helper to create a parameter 283 // out of the network type, here for a slice of Address. 284 func FromNetworkAddresses(naddrs ...network.Address) []Address { 285 addrs := make([]Address, len(naddrs)) 286 for i, naddr := range naddrs { 287 addrs[i] = FromNetworkAddress(naddr) 288 } 289 return addrs 290 } 291 292 // NetworkAddresses is a convenience helper to return the parameter 293 // as network type, here for a slice of Address. 294 func NetworkAddresses(addrs ...Address) []network.Address { 295 naddrs := make([]network.Address, len(addrs)) 296 for i, addr := range addrs { 297 naddrs[i] = addr.NetworkAddress() 298 } 299 return naddrs 300 } 301 302 // HostPort associates an address with a port. It's used in 303 // the API requests/responses. See also network.HostPort, from/to 304 // which this is transformed. 305 type HostPort struct { 306 Address 307 Port int `json:"port"` 308 } 309 310 // FromNetworkHostPort is a convenience helper to create a parameter 311 // out of the network type, here for HostPort. 312 func FromNetworkHostPort(nhp network.HostPort) HostPort { 313 return HostPort{FromNetworkAddress(nhp.Address), nhp.Port} 314 } 315 316 // NetworkHostPort is a convenience helper to return the parameter 317 // as network type, here for HostPort. 318 func (hp HostPort) NetworkHostPort() network.HostPort { 319 return network.HostPort{hp.Address.NetworkAddress(), hp.Port} 320 } 321 322 // FromNetworkHostPorts is a helper to create a parameter 323 // out of the network type, here for a slice of HostPort. 324 func FromNetworkHostPorts(nhps []network.HostPort) []HostPort { 325 hps := make([]HostPort, len(nhps)) 326 for i, nhp := range nhps { 327 hps[i] = FromNetworkHostPort(nhp) 328 } 329 return hps 330 } 331 332 // NetworkHostPorts is a convenience helper to return the parameter 333 // as network type, here for a slice of HostPort. 334 func NetworkHostPorts(hps []HostPort) []network.HostPort { 335 nhps := make([]network.HostPort, len(hps)) 336 for i, hp := range hps { 337 nhps[i] = hp.NetworkHostPort() 338 } 339 return nhps 340 } 341 342 // FromNetworkHostsPorts is a helper to create a parameter 343 // out of the network type, here for a nested slice of HostPort. 344 func FromNetworkHostsPorts(nhpm [][]network.HostPort) [][]HostPort { 345 hpm := make([][]HostPort, len(nhpm)) 346 for i, nhps := range nhpm { 347 hpm[i] = FromNetworkHostPorts(nhps) 348 } 349 return hpm 350 } 351 352 // NetworkHostsPorts is a convenience helper to return the parameter 353 // as network type, here for a nested slice of HostPort. 354 func NetworkHostsPorts(hpm [][]HostPort) [][]network.HostPort { 355 nhpm := make([][]network.HostPort, len(hpm)) 356 for i, hps := range hpm { 357 nhpm[i] = NetworkHostPorts(hps) 358 } 359 return nhpm 360 } 361 362 // UnitsNetworkConfig holds the parameters for calling Uniter.NetworkConfig() 363 // API. 364 type UnitsNetworkConfig struct { 365 Args []UnitNetworkConfig `json:"args"` 366 } 367 368 // UnitNetworkConfig holds a unit tag and an endpoint binding name. 369 type UnitNetworkConfig struct { 370 UnitTag string `json:"unit-tag"` 371 BindingName string `json:"binding-name"` 372 } 373 374 // MachineAddresses holds an machine tag and addresses. 375 type MachineAddresses struct { 376 Tag string `json:"tag"` 377 Addresses []Address `json:"addresses"` 378 } 379 380 // SetMachinesAddresses holds the parameters for making an 381 // API call to update machine addresses. 382 type SetMachinesAddresses struct { 383 MachineAddresses []MachineAddresses `json:"machine-addresses"` 384 } 385 386 // SetMachineNetworkConfig holds the parameters for making an API call to update 387 // machine network config. 388 type SetMachineNetworkConfig struct { 389 Tag string `json:"tag"` 390 Config []NetworkConfig `json:"config"` 391 } 392 393 // MachineAddressesResult holds a list of machine addresses or an 394 // error. 395 type MachineAddressesResult struct { 396 Error *Error `json:"error,omitempty"` 397 Addresses []Address `json:"addresses"` 398 } 399 400 // MachineAddressesResults holds the results of calling an API method 401 // returning a list of addresses per machine. 402 type MachineAddressesResults struct { 403 Results []MachineAddressesResult `json:"results"` 404 } 405 406 // MachinePortRange holds a single port range open on a machine for 407 // the given unit and relation tags. 408 type MachinePortRange struct { 409 UnitTag string `json:"unit-tag"` 410 RelationTag string `json:"relation-tag"` 411 PortRange PortRange `json:"port-range"` 412 } 413 414 // MachinePorts holds a machine and subnet tags. It's used when referring to 415 // opened ports on the machine for a subnet. 416 type MachinePorts struct { 417 MachineTag string `json:"machine-tag"` 418 SubnetTag string `json:"subnet-tag"` 419 } 420 421 // ----- 422 // API request / response types. 423 // ----- 424 425 // PortsResults holds the bulk operation result of an API call 426 // that returns a slice of Port. 427 type PortsResults struct { 428 Results []PortsResult `json:"results"` 429 } 430 431 // PortsResult holds the result of an API call that returns a slice 432 // of Port or an error. 433 type PortsResult struct { 434 Error *Error `json:"error,omitempty"` 435 Ports []Port `json:"ports"` 436 } 437 438 // UnitNetworkConfigResult holds network configuration for a single unit. 439 type UnitNetworkConfigResult struct { 440 Error *Error `json:"error,omitempty"` 441 442 // Tagged to Info due to compatibility reasons. 443 Config []NetworkConfig `json:"info"` 444 } 445 446 // UnitNetworkConfigResults holds network configuration for multiple machines. 447 type UnitNetworkConfigResults struct { 448 Results []UnitNetworkConfigResult `json:"results"` 449 } 450 451 // MachineNetworkConfigResult holds network configuration for a single machine. 452 type MachineNetworkConfigResult struct { 453 Error *Error `json:"error,omitempty"` 454 455 // Tagged to Info due to compatibility reasons. 456 Config []NetworkConfig `json:"info"` 457 } 458 459 // MachineNetworkConfigResults holds network configuration for multiple machines. 460 type MachineNetworkConfigResults struct { 461 Results []MachineNetworkConfigResult `json:"results"` 462 } 463 464 // MachinePortsParams holds the arguments for making a 465 // FirewallerAPIV1.GetMachinePorts() API call. 466 type MachinePortsParams struct { 467 Params []MachinePorts `json:"params"` 468 } 469 470 // MachinePortsResult holds a single result of the 471 // FirewallerAPIV1.GetMachinePorts() and UniterAPI.AllMachinePorts() 472 // API calls. 473 type MachinePortsResult struct { 474 Error *Error `json:"error,omitempty"` 475 Ports []MachinePortRange `json:"ports"` 476 } 477 478 // MachinePortsResults holds all the results of the 479 // FirewallerAPIV1.GetMachinePorts() and UniterAPI.AllMachinePorts() 480 // API calls. 481 type MachinePortsResults struct { 482 Results []MachinePortsResult `json:"results"` 483 } 484 485 // APIHostPortsResult holds the result of an APIHostPorts 486 // call. Each element in the top level slice holds 487 // the addresses for one API server. 488 type APIHostPortsResult struct { 489 Servers [][]HostPort `json:"servers"` 490 } 491 492 // NetworkHostsPorts is a convenience helper to return the contained 493 // result servers as network type. 494 func (r APIHostPortsResult) NetworkHostsPorts() [][]network.HostPort { 495 return NetworkHostsPorts(r.Servers) 496 } 497 498 // ZoneResult holds the result of an API call that returns an 499 // availability zone name and whether it's available for use. 500 type ZoneResult struct { 501 Error *Error `json:"error,omitempty"` 502 Name string `json:"name"` 503 Available bool `json:"available"` 504 } 505 506 // ZoneResults holds multiple ZoneResult results 507 type ZoneResults struct { 508 Results []ZoneResult `json:"results"` 509 } 510 511 // SpaceResult holds a single space tag or an error. 512 type SpaceResult struct { 513 Error *Error `json:"error,omitempty"` 514 Tag string `json:"tag"` 515 } 516 517 // SpaceResults holds the bulk operation result of an API call 518 // that returns space tags or an errors. 519 type SpaceResults struct { 520 Results []SpaceResult `json:"results"` 521 } 522 523 // ListSubnetsResults holds the result of a ListSubnets API call. 524 type ListSubnetsResults struct { 525 Results []Subnet `json:"results"` 526 } 527 528 // SubnetsFilters holds an optional SpaceTag and Zone for filtering 529 // the subnets returned by a ListSubnets call. 530 type SubnetsFilters struct { 531 SpaceTag string `json:"space-tag,omitempty"` 532 Zone string `json:"zone,omitempty"` 533 } 534 535 // AddSubnetsParams holds the arguments of AddSubnets API call. 536 type AddSubnetsParams struct { 537 Subnets []AddSubnetParams `json:"subnets"` 538 } 539 540 // AddSubnetParams holds a subnet and space tags, subnet provider ID, 541 // and a list of zones to associate the subnet to. Either SubnetTag or 542 // SubnetProviderId must be set, but not both. Zones can be empty if 543 // they can be discovered 544 type AddSubnetParams struct { 545 SubnetTag string `json:"subnet-tag,omitempty"` 546 SubnetProviderId string `json:"subnet-provider-id,omitempty"` 547 SpaceTag string `json:"space-tag"` 548 Zones []string `json:"zones,omitempty"` 549 } 550 551 // CreateSubnetsParams holds the arguments of CreateSubnets API call. 552 type CreateSubnetsParams struct { 553 Subnets []CreateSubnetParams `json:"subnets"` 554 } 555 556 // CreateSubnetParams holds a subnet and space tags, vlan tag, 557 // and a list of zones to associate the subnet to. 558 type CreateSubnetParams struct { 559 SubnetTag string `json:"subnet-tag,omitempty"` 560 SpaceTag string `json:"space-tag"` 561 Zones []string `json:"zones,omitempty"` 562 VLANTag int `json:"vlan-tag,omitempty"` 563 IsPublic bool `json:"is-public"` 564 } 565 566 // CreateSpacesParams olds the arguments of the AddSpaces API call. 567 type CreateSpacesParams struct { 568 Spaces []CreateSpaceParams `json:"spaces"` 569 } 570 571 // CreateSpaceParams holds the space tag and at least one subnet 572 // tag required to create a new space. 573 type CreateSpaceParams struct { 574 SubnetTags []string `json:"subnet-tags"` 575 SpaceTag string `json:"space-tag"` 576 Public bool `json:"public"` 577 ProviderId string `json:"provider-id,omitempty"` 578 } 579 580 // ListSpacesResults holds the list of all available spaces. 581 type ListSpacesResults struct { 582 Results []Space `json:"results"` 583 } 584 585 // Space holds the information about a single space and its associated subnets. 586 type Space struct { 587 Name string `json:"name"` 588 Subnets []Subnet `json:"subnets"` 589 Error *Error `json:"error,omitempty"` 590 } 591 592 // DiscoverSpacesResults holds the list of all provider spaces. 593 type DiscoverSpacesResults struct { 594 Results []ProviderSpace `json:"results"` 595 } 596 597 // ProviderSpace holds the information about a single space and its associated subnets. 598 type ProviderSpace struct { 599 Name string `json:"name"` 600 ProviderId string `json:"provider-id"` 601 Subnets []Subnet `json:"subnets"` 602 Error *Error `json:"error,omitempty"` 603 } 604 605 type ProxyConfig struct { 606 HTTP string `json:"http"` 607 HTTPS string `json:"https"` 608 FTP string `json:"ftp"` 609 NoProxy string `json:"no-proxy"` 610 } 611 612 // ProxyConfigResult contains information needed to configure a clients proxy settings 613 type ProxyConfigResult struct { 614 ProxySettings ProxyConfig `json:"proxy-settings"` 615 APTProxySettings ProxyConfig `json:"apt-proxy-settings"` 616 Error *Error `json:"error,omitempty"` 617 } 618 619 // ProxyConfigResults contains information needed to configure multiple clients proxy settings 620 type ProxyConfigResults struct { 621 Results []ProxyConfigResult `json:"results"` 622 }