David K. Bainbridge | 215e024 | 2017-09-05 23:18:24 -0700 | [diff] [blame] | 1 | // Copyright 2017 the original author or authors. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package main |
| 16 | |
| 17 | import ( |
| 18 | "fmt" |
| 19 | "net/url" |
| 20 | ) |
| 21 | |
| 22 | type ClusterInfo struct { |
| 23 | Expected uint64 |
| 24 | Nodes []string |
| 25 | } |
| 26 | |
| 27 | type OrchestrationClient interface { |
| 28 | Init(url *url.URL) error |
| 29 | GetInfo(labels map[string]string, networkLabels map[string]string) (*ClusterInfo, error) |
| 30 | Close() error |
| 31 | } |
| 32 | |
| 33 | func NewOrchestrationClient(url *url.URL) (OrchestrationClient, error) { |
| 34 | var client OrchestrationClient |
| 35 | |
| 36 | switch url.Scheme { |
| 37 | case "swarm": |
| 38 | client = &SwarmClient{} |
| 39 | case "kubernetes": |
| 40 | return nil, fmt.Errorf("Kubernetes is not yet supported") |
| 41 | default: |
| 42 | return nil, fmt.Errorf("Unknown container orchestrator, '%s' specified", |
| 43 | url.Scheme) |
| 44 | } |
| 45 | |
| 46 | err := client.Init(url) |
| 47 | if err != nil { |
| 48 | return nil, err |
| 49 | } |
| 50 | return client, nil |
| 51 | } |