github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/apiserver/params/status.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package params
     5  
     6  // TODO(ericsnow) Eliminate the juju-related imports.
     7  
     8  import (
     9  	"time"
    10  
    11  	"github.com/juju/juju/core/instance"
    12  	"github.com/juju/juju/core/relation"
    13  	"github.com/juju/juju/state/multiwatcher"
    14  )
    15  
    16  // StatusParams holds parameters for the Status call.
    17  type StatusParams struct {
    18  	Patterns []string `json:"patterns"`
    19  }
    20  
    21  // TODO(ericsnow) Add FullStatusResult.
    22  
    23  // FullStatus holds information about the status of a juju model.
    24  type FullStatus struct {
    25  	Model               ModelStatusInfo                    `json:"model"`
    26  	Machines            map[string]MachineStatus           `json:"machines"`
    27  	Applications        map[string]ApplicationStatus       `json:"applications"`
    28  	RemoteApplications  map[string]RemoteApplicationStatus `json:"remote-applications"`
    29  	Offers              map[string]ApplicationOfferStatus  `json:"offers"`
    30  	Relations           []RelationStatus                   `json:"relations"`
    31  	ControllerTimestamp *time.Time                         `json:"controller-timestamp"`
    32  }
    33  
    34  // IsEmpty checks all collections on FullStatus to determine if the status is empty.
    35  // Note that only the collections are checked here as Model information will always be populated.
    36  func (fs *FullStatus) IsEmpty() bool {
    37  	return len(fs.Applications) == 0 &&
    38  		len(fs.Machines) == 0 &&
    39  		len(fs.Offers) == 0 &&
    40  		len(fs.RemoteApplications) == 0 &&
    41  		len(fs.Relations) == 0
    42  }
    43  
    44  // ModelStatusInfo holds status information about the model itself.
    45  type ModelStatusInfo struct {
    46  	Name             string         `json:"name"`
    47  	Type             string         `json:"type"`
    48  	CloudTag         string         `json:"cloud-tag"`
    49  	CloudRegion      string         `json:"region,omitempty"`
    50  	Version          string         `json:"version"`
    51  	AvailableVersion string         `json:"available-version"`
    52  	ModelStatus      DetailedStatus `json:"model-status"`
    53  	MeterStatus      MeterStatus    `json:"meter-status"`
    54  	SLA              string         `json:"sla"`
    55  }
    56  
    57  // NetworkInterfaceStatus holds a /etc/network/interfaces-type data and the
    58  // space name for any device with at least one associated IP address.
    59  type NetworkInterface struct {
    60  	// IPAddresses holds the IP addresses bound to this machine.
    61  	IPAddresses    []string `json:"ip-addresses"`
    62  	MACAddress     string   `json:"mac-address"`
    63  	Gateway        string   `json:"gateway,omitempty"`
    64  	DNSNameservers []string `json:"dns-nameservers,omitempty"`
    65  
    66  	// Space holds the name of a space in which this devices IP addr's
    67  	// subnet belongs.
    68  	Space string `json:"space,omitempty"`
    69  
    70  	// Is this interface up?
    71  	IsUp bool `json:"is-up"`
    72  }
    73  
    74  // MachineStatus holds status info about a machine.
    75  type MachineStatus struct {
    76  	AgentStatus    DetailedStatus `json:"agent-status"`
    77  	InstanceStatus DetailedStatus `json:"instance-status"`
    78  	DNSName        string         `json:"dns-name"`
    79  
    80  	// IPAddresses holds the IP addresses known for this machine. It is
    81  	// here for backwards compatibility. It should be similar to its
    82  	// namesakes in NetworkInterfaces, but may also include any
    83  	// public/floating IP addresses not actually bound to the machine but
    84  	// known to the provider.
    85  	IPAddresses []string `json:"ip-addresses,omitempty"`
    86  
    87  	// InstanceId holds the unique identifier for this machine, based on
    88  	// what is supplied by the provider.
    89  	InstanceId instance.Id `json:"instance-id"`
    90  
    91  	// DisplayName is a human-readable name for this machine.
    92  	DisplayName string `json:"display-name"`
    93  
    94  	// Series holds the name of the operating system release installed on
    95  	// this machine.
    96  	Series string `json:"series"`
    97  
    98  	// Id is the Juju identifier for this machine in this model.
    99  	Id string `json:"id"`
   100  
   101  	// NetworkInterfaces holds a map of NetworkInterface for this machine.
   102  	NetworkInterfaces map[string]NetworkInterface `json:"network-interfaces,omitempty"`
   103  
   104  	// Containers holds the MachineStatus of any containers hosted on this
   105  	// machine.
   106  	Containers map[string]MachineStatus `json:"containers"`
   107  
   108  	// Constraints holds a string of space-separated key=value pairs for
   109  	// each constraint datum.
   110  	Constraints string `json:"constraints"`
   111  
   112  	// Hardware holds a string of space-separated key=value pairs for each
   113  	// hardware specification datum.
   114  	Hardware string `json:"hardware"`
   115  
   116  	Jobs      []multiwatcher.MachineJob `json:"jobs"`
   117  	HasVote   bool                      `json:"has-vote"`
   118  	WantsVote bool                      `json:"wants-vote"`
   119  
   120  	// LXDProfiles holds all the machines current LXD profiles that have
   121  	// been applied to the machine
   122  	LXDProfiles map[string]LXDProfile `json:"lxd-profiles,omitempty"`
   123  }
   124  
   125  // LXDProfile holds status info about a LXDProfile
   126  type LXDProfile struct {
   127  	Config      map[string]string            `json:"config"`
   128  	Description string                       `json:"description"`
   129  	Devices     map[string]map[string]string `json:"devices"`
   130  }
   131  
   132  // ApplicationStatus holds status info about an application.
   133  type ApplicationStatus struct {
   134  	Err              error                  `json:"err,omitempty"`
   135  	Charm            string                 `json:"charm"`
   136  	Series           string                 `json:"series"`
   137  	Exposed          bool                   `json:"exposed"`
   138  	Life             string                 `json:"life"`
   139  	Relations        map[string][]string    `json:"relations"`
   140  	CanUpgradeTo     string                 `json:"can-upgrade-to"`
   141  	SubordinateTo    []string               `json:"subordinate-to"`
   142  	Units            map[string]UnitStatus  `json:"units"`
   143  	MeterStatuses    map[string]MeterStatus `json:"meter-statuses"`
   144  	Status           DetailedStatus         `json:"status"`
   145  	WorkloadVersion  string                 `json:"workload-version"`
   146  	CharmVersion     string                 `json:"charm-verion"`
   147  	EndpointBindings map[string]string      `json:"endpoint-bindings"`
   148  
   149  	// The following are for CAAS models.
   150  	Scale         int    `json:"int,omitempty"`
   151  	Placement     string `json:"string,omitempty"`
   152  	ProviderId    string `json:"provider-id,omitempty"`
   153  	PublicAddress string `json:"public-address"`
   154  }
   155  
   156  // RemoteApplicationStatus holds status info about a remote application.
   157  type RemoteApplicationStatus struct {
   158  	Err       error               `json:"err,omitempty"`
   159  	OfferURL  string              `json:"offer-url"`
   160  	OfferName string              `json:"offer-name"`
   161  	Endpoints []RemoteEndpoint    `json:"endpoints"`
   162  	Life      string              `json:"life"`
   163  	Relations map[string][]string `json:"relations"`
   164  	Status    DetailedStatus      `json:"status"`
   165  }
   166  
   167  // ApplicationOfferStatus holds status info about an application offer.
   168  type ApplicationOfferStatus struct {
   169  	Err                  error                     `json:"err,omitempty"`
   170  	OfferName            string                    `json:"offer-name"`
   171  	ApplicationName      string                    `json:"application-name"`
   172  	CharmURL             string                    `json:"charm"`
   173  	Endpoints            map[string]RemoteEndpoint `json:"endpoints"`
   174  	ActiveConnectedCount int                       `json:"active-connected-count"`
   175  	TotalConnectedCount  int                       `json:"total-connected-count"`
   176  }
   177  
   178  // MeterStatus represents the meter status of a unit.
   179  type MeterStatus struct {
   180  	Color   string `json:"color"`
   181  	Message string `json:"message"`
   182  }
   183  
   184  // UnitStatus holds status info about a unit.
   185  type UnitStatus struct {
   186  	// AgentStatus holds the status for a unit's agent.
   187  	AgentStatus DetailedStatus `json:"agent-status"`
   188  
   189  	// WorkloadStatus holds the status for a unit's workload.
   190  	WorkloadStatus  DetailedStatus `json:"workload-status"`
   191  	WorkloadVersion string         `json:"workload-version"`
   192  
   193  	Machine       string                `json:"machine"`
   194  	OpenedPorts   []string              `json:"opened-ports"`
   195  	PublicAddress string                `json:"public-address"`
   196  	Charm         string                `json:"charm"`
   197  	Subordinates  map[string]UnitStatus `json:"subordinates"`
   198  	Leader        bool                  `json:"leader,omitempty"`
   199  
   200  	// The following are for CAAS models.
   201  	ProviderId string `json:"provider-id,omitempty"`
   202  	Address    string `json:"address,omitempty"`
   203  }
   204  
   205  // RelationStatus holds status info about a relation.
   206  type RelationStatus struct {
   207  	Id        int              `json:"id"`
   208  	Key       string           `json:"key"`
   209  	Interface string           `json:"interface"`
   210  	Scope     string           `json:"scope"`
   211  	Endpoints []EndpointStatus `json:"endpoints"`
   212  	Status    DetailedStatus   `json:"status"`
   213  }
   214  
   215  // EndpointStatus holds status info about a single endpoint.
   216  type EndpointStatus struct {
   217  	ApplicationName string `json:"application"`
   218  	Name            string `json:"name"`
   219  	Role            string `json:"role"`
   220  	Subordinate     bool   `json:"subordinate"`
   221  }
   222  
   223  // TODO(ericsnow) Eliminate the String method.
   224  
   225  func (epStatus *EndpointStatus) String() string {
   226  	return epStatus.ApplicationName + ":" + epStatus.Name
   227  }
   228  
   229  // DetailedStatus holds status info about a machine or unit agent.
   230  type DetailedStatus struct {
   231  	Status  string                 `json:"status"`
   232  	Info    string                 `json:"info"`
   233  	Data    map[string]interface{} `json:"data"`
   234  	Since   *time.Time             `json:"since"`
   235  	Kind    string                 `json:"kind"`
   236  	Version string                 `json:"version"`
   237  	Life    string                 `json:"life"`
   238  	Err     error                  `json:"err,omitempty"`
   239  }
   240  
   241  // History holds many DetailedStatus.
   242  type History struct {
   243  	Statuses []DetailedStatus `json:"statuses"`
   244  	Error    *Error           `json:"error,omitempty"`
   245  }
   246  
   247  // StatusHistoryFilter holds arguments that can be use to filter a status history backlog.
   248  type StatusHistoryFilter struct {
   249  	Size    int            `json:"size"`
   250  	Date    *time.Time     `json:"date"`
   251  	Delta   *time.Duration `json:"delta"`
   252  	Exclude []string       `json:"exclude"`
   253  }
   254  
   255  // StatusHistoryRequest holds the parameters to filter a status history query.
   256  type StatusHistoryRequest struct {
   257  	Kind   string              `json:"historyKind"`
   258  	Size   int                 `json:"size"`
   259  	Filter StatusHistoryFilter `json:"filter"`
   260  	Tag    string              `json:"tag"`
   261  }
   262  
   263  // StatusHistoryRequests holds a slice of StatusHistoryArgs.
   264  type StatusHistoryRequests struct {
   265  	Requests []StatusHistoryRequest `json:"requests"`
   266  }
   267  
   268  // StatusHistoryResult holds a slice of statuses.
   269  type StatusHistoryResult struct {
   270  	History History `json:"history"`
   271  	Error   *Error  `json:"error,omitempty"`
   272  }
   273  
   274  // StatusHistoryResults holds a slice of StatusHistoryResult.
   275  type StatusHistoryResults struct {
   276  	Results []StatusHistoryResult `json:"results"`
   277  }
   278  
   279  // StatusHistoryPruneArgs holds arguments for status history
   280  // prunning process.
   281  type StatusHistoryPruneArgs struct {
   282  	MaxHistoryTime time.Duration `json:"max-history-time"`
   283  	MaxHistoryMB   int           `json:"max-history-mb"`
   284  }
   285  
   286  // StatusResult holds an entity status, extra information, or an
   287  // error.
   288  type StatusResult struct {
   289  	Error  *Error                 `json:"error,omitempty"`
   290  	Id     string                 `json:"id"`
   291  	Life   Life                   `json:"life"`
   292  	Status string                 `json:"status"`
   293  	Info   string                 `json:"info"`
   294  	Data   map[string]interface{} `json:"data"`
   295  	Since  *time.Time             `json:"since"`
   296  }
   297  
   298  // StatusResults holds multiple status results.
   299  type StatusResults struct {
   300  	Results []StatusResult `json:"results"`
   301  }
   302  
   303  // ApplicationStatusResult holds results for an application Full Status.
   304  type ApplicationStatusResult struct {
   305  	Application StatusResult            `json:"application"`
   306  	Units       map[string]StatusResult `json:"units"`
   307  	Error       *Error                  `json:"error,omitempty"`
   308  }
   309  
   310  // ApplicationStatusResults holds multiple StatusResult.
   311  type ApplicationStatusResults struct {
   312  	Results []ApplicationStatusResult `json:"results"`
   313  }
   314  
   315  // Life describes the lifecycle state of an entity ("alive", "dying" or "dead").
   316  type Life multiwatcher.Life
   317  
   318  const (
   319  	Alive Life = "alive"
   320  	Dying Life = "dying"
   321  	Dead  Life = "dead"
   322  )
   323  
   324  // RelationStatusValue describes the status of a relation.
   325  type RelationStatusValue relation.Status
   326  
   327  const (
   328  	Joined    RelationStatusValue = "joined"
   329  	Suspended RelationStatusValue = "suspended"
   330  	Broken    RelationStatusValue = "broken"
   331  )