~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta3

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/apiserver/uniter/uniter.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1705
1705
 
1706
1706
// NetworkConfig returns information about all given relation/unit pairs,
1707
1707
// including their id, key and the local endpoint.
1708
 
func (u *UniterAPIV3) NetworkConfig(args params.RelationUnits) (params.UnitNetworkConfigResults, error) {
 
1708
func (u *UniterAPIV3) NetworkConfig(args params.UnitsNetworkConfig) (params.UnitNetworkConfigResults, error) {
1709
1709
        result := params.UnitNetworkConfigResults{
1710
 
                Results: make([]params.UnitNetworkConfigResult, len(args.RelationUnits)),
 
1710
                Results: make([]params.UnitNetworkConfigResult, len(args.Args)),
1711
1711
        }
1712
1712
 
1713
1713
        canAccess, err := u.accessUnit()
1715
1715
                return params.UnitNetworkConfigResults{}, err
1716
1716
        }
1717
1717
 
1718
 
        for i, rel := range args.RelationUnits {
1719
 
                netConfig, err := u.getOneNetworkConfig(canAccess, rel.Relation, rel.Unit)
 
1718
        for i, arg := range args.Args {
 
1719
                netConfig, err := u.getOneNetworkConfig(canAccess, arg.UnitTag, arg.BindingName)
1720
1720
                if err == nil {
1721
 
                        result.Results[i].Error = nil
1722
1721
                        result.Results[i].Config = netConfig
1723
1722
                } else {
1724
1723
                        result.Results[i].Error = common.ServerError(err)
1727
1726
        return result, nil
1728
1727
}
1729
1728
 
1730
 
func (u *UniterAPIV3) getOneNetworkConfig(canAccess common.AuthFunc, tagRel, tagUnit string) ([]params.NetworkConfig, error) {
1731
 
        unitTag, err := names.ParseUnitTag(tagUnit)
 
1729
func (u *UniterAPIV3) getOneNetworkConfig(canAccess common.AuthFunc, unitTagArg, bindingName string) ([]params.NetworkConfig, error) {
 
1730
        unitTag, err := names.ParseUnitTag(unitTagArg)
1732
1731
        if err != nil {
1733
1732
                return nil, errors.Trace(err)
1734
1733
        }
1735
1734
 
 
1735
        if bindingName == "" {
 
1736
                return nil, errors.Errorf("binding name cannot be empty")
 
1737
        }
 
1738
 
1736
1739
        if !canAccess(unitTag) {
1737
1740
                return nil, common.ErrPerm
1738
1741
        }
1739
1742
 
1740
 
        relTag, err := names.ParseRelationTag(tagRel)
1741
 
        if err != nil {
1742
 
                return nil, errors.Trace(err)
1743
 
        }
1744
 
 
1745
1743
        unit, err := u.getUnit(unitTag)
1746
1744
        if err != nil {
1747
1745
                return nil, errors.Trace(err)
1756
1754
        if err != nil {
1757
1755
                return nil, errors.Trace(err)
1758
1756
        }
1759
 
 
1760
 
        rel, err := u.st.KeyRelation(relTag.Id())
1761
 
        if err != nil {
1762
 
                return nil, errors.Trace(err)
1763
 
        }
1764
 
 
1765
 
        endpoint, err := rel.Endpoint(service.Name())
1766
 
        if err != nil {
1767
 
                return nil, errors.Trace(err)
 
1757
        boundSpace, known := bindings[bindingName]
 
1758
        if !known {
 
1759
                return nil, errors.Errorf("binding name %q not defined by the unit's charm", bindingName)
1768
1760
        }
1769
1761
 
1770
1762
        machineID, err := unit.AssignedMachineId()
1778
1770
        }
1779
1771
 
1780
1772
        var results []params.NetworkConfig
1781
 
 
1782
 
        boundSpace, isBound := bindings[endpoint.Name]
1783
 
        if !isBound || boundSpace == "" {
1784
 
                name := endpoint.Name
1785
 
                logger.Debugf("endpoint %q not explicitly bound to a space, using preferred private address for machine %q", name, machineID)
 
1773
        if boundSpace == "" {
 
1774
                logger.Debugf(
 
1775
                        "endpoint %q not explicitly bound to a space, using preferred private address for machine %q",
 
1776
                        bindingName, machineID,
 
1777
                )
1786
1778
 
1787
1779
                privateAddress, err := machine.PrivateAddress()
1788
1780
                if err != nil && !network.IsNoAddress(err) {
1793
1785
                        Address: privateAddress.Value,
1794
1786
                })
1795
1787
                return results, nil
 
1788
        } else {
 
1789
                logger.Debugf("endpoint %q is explicitly bound to space %q", bindingName, boundSpace)
1796
1790
        }
1797
 
        logger.Debugf("endpoint %q is explicitly bound to space %q", endpoint.Name, boundSpace)
1798
1791
 
1799
1792
        // TODO(dimitern): Use NetworkInterfaces() instead later, this is just for
1800
1793
        // the PoC to enable minimal network-get implementation returning just the
1813
1806
                        logger.Debugf("skipping address %q: want bound to space %q, got space %q", addr.Value, boundSpace, space)
1814
1807
                        continue
1815
1808
                }
1816
 
                logger.Debugf("endpoint %q bound to space %q has address %q", endpoint.Name, boundSpace, addr.Value)
 
1809
                logger.Debugf("endpoint %q bound to space %q has address %q", bindingName, boundSpace, addr.Value)
1817
1810
 
1818
1811
                // TODO(dimitern): Fill in the rest later (see linked LKK card above).
1819
1812
                results = append(results, params.NetworkConfig{