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