├── .gitignore ├── .golangci.yml ├── .travis.yml ├── CONTRIBUTING.md ├── COPYING ├── Gopkg.lock ├── Gopkg.toml ├── README.md ├── ccvm ├── api.go ├── api_test.go ├── ccvm.go ├── ccvm_test.go ├── download.go ├── download_test.go ├── instance.go ├── mock_test.go ├── name.go ├── name_test.go ├── prepare.go ├── server.go ├── server_test.go ├── vm.go ├── workload.go ├── workload_test.go └── workloads │ ├── artful.yaml │ ├── bionic.yaml │ ├── buster.yaml │ ├── centos7.yaml │ ├── centos8-stream.yaml │ ├── ciao.yaml │ ├── clearcontainers-2.x.yaml │ ├── clearcontainers-3.x.yaml │ ├── devstack-xenial.yaml │ ├── docker-bionic.yaml │ ├── docker-xenial.yaml │ ├── fedora27.yaml │ ├── fedora28.yaml │ ├── fedora29.yaml │ ├── fedora30.yaml │ ├── fedora31.yaml │ ├── fedora32.yaml │ ├── fedora33.yaml │ ├── focal.yaml │ ├── semaphore.yaml │ ├── sid.yaml │ └── xenial.yaml ├── client ├── client.go └── deps.go ├── cmd ├── connect.go ├── copy.go ├── create.go ├── delete.go ├── instances.go ├── quit.go ├── root.go ├── run.go ├── setup.go ├── start.go ├── status.go ├── stop.go ├── teardown.go └── vm.go ├── go.mod ├── go.sum ├── main.go ├── osprepare ├── distro.go ├── distro_test.go ├── doc.go ├── os_release.go ├── os_release_test.go └── osprepare.go ├── scripts └── ccloudvm_bashcomplete ├── semaphore.sh ├── types ├── api.go └── types.go └── vendor ├── github.com ├── ciao-project │ └── ciao │ │ ├── COPYING │ │ ├── clogger │ │ └── logger.go │ │ ├── deviceinfo │ │ └── deviceinfo.go │ │ └── uuid │ │ └── uuid.go ├── coreos │ └── go-systemd │ │ ├── LICENSE │ │ └── activation │ │ ├── files.go │ │ ├── listeners.go │ │ └── packetconns.go ├── inconshreveable │ └── mousetrap │ │ ├── LICENSE │ │ ├── README.md │ │ ├── trap_others.go │ │ ├── trap_windows.go │ │ └── trap_windows_1.4.go ├── intel │ └── govmm │ │ ├── COPYING │ │ └── qemu │ │ ├── image.go │ │ ├── qemu.go │ │ └── qmp.go ├── pkg │ └── errors │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── LICENSE │ │ ├── README.md │ │ ├── appveyor.yml │ │ ├── errors.go │ │ └── stack.go ├── pmezard │ └── go-difflib │ │ ├── LICENSE │ │ └── difflib │ │ └── difflib.go └── spf13 │ ├── cobra │ ├── .gitignore │ ├── .mailmap │ ├── .travis.yml │ ├── LICENSE.txt │ ├── README.md │ ├── args.go │ ├── bash_completions.go │ ├── bash_completions.md │ ├── cobra.go │ ├── command.go │ ├── command_notwin.go │ ├── command_win.go │ └── zsh_completions.go │ └── pflag │ ├── .gitignore │ ├── .travis.yml │ ├── LICENSE │ ├── README.md │ ├── bool.go │ ├── bool_slice.go │ ├── count.go │ ├── duration.go │ ├── flag.go │ ├── float32.go │ ├── float64.go │ ├── golangflag.go │ ├── int.go │ ├── int32.go │ ├── int64.go │ ├── int8.go │ ├── int_slice.go │ ├── ip.go │ ├── ip_slice.go │ ├── ipmask.go │ ├── ipnet.go │ ├── string.go │ ├── string_array.go │ ├── string_slice.go │ ├── uint.go │ ├── uint16.go │ ├── uint32.go │ ├── uint64.go │ ├── uint8.go │ └── uint_slice.go ├── golang.org └── x │ ├── net │ ├── AUTHORS │ ├── CONTRIBUTORS │ ├── LICENSE │ ├── PATENTS │ ├── http │ │ └── httpproxy │ │ │ └── proxy.go │ └── idna │ │ ├── idna10.0.0.go │ │ ├── idna9.0.0.go │ │ ├── punycode.go │ │ ├── tables10.0.0.go │ │ ├── tables11.0.0.go │ │ ├── tables12.00.go │ │ ├── tables9.0.0.go │ │ ├── trie.go │ │ └── trieval.go │ └── text │ ├── AUTHORS │ ├── CONTRIBUTORS │ ├── LICENSE │ ├── PATENTS │ ├── secure │ └── bidirule │ │ ├── bidirule.go │ │ ├── bidirule10.0.0.go │ │ └── bidirule9.0.0.go │ ├── transform │ └── transform.go │ └── unicode │ ├── bidi │ ├── bidi.go │ ├── bracket.go │ ├── core.go │ ├── prop.go │ ├── tables10.0.0.go │ ├── tables9.0.0.go │ └── trieval.go │ └── norm │ ├── composition.go │ ├── forminfo.go │ ├── input.go │ ├── iter.go │ ├── normalize.go │ ├── readwriter.go │ ├── tables10.0.0.go │ ├── tables9.0.0.go │ ├── transform.go │ └── trie.go ├── gopkg.in └── yaml.v2 │ ├── .travis.yml │ ├── LICENSE │ ├── LICENSE.libyaml │ ├── README.md │ ├── apic.go │ ├── decode.go │ ├── emitterc.go │ ├── encode.go │ ├── parserc.go │ ├── readerc.go │ ├── resolve.go │ ├── scannerc.go │ ├── sorter.go │ ├── writerc.go │ ├── yaml.go │ ├── yamlh.go │ └── yamlprivateh.go └── modules.txt /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | ccloudvm 3 | ccvm/ccvm 4 | -------------------------------------------------------------------------------- /.golangci.yml: -------------------------------------------------------------------------------- 1 | linters: 2 | enable: 3 | - gofmt 4 | - gocyclo 5 | - misspell 6 | linters-settings: 7 | gocyclo: 8 | min-complexity: 15 9 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - "1.16" 5 | - tip 6 | 7 | env: 8 | - GOLANGCILINT="v1.39.0" 9 | 10 | go_import_path: github.com/intel/ccloudvm 11 | 12 | matrix: 13 | allow_failures: 14 | - go: tip 15 | 16 | before_install: 17 | - curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCILINT} 18 | 19 | script: 20 | - go env 21 | - golangci-lint run -c ./.golangci.yml ./... 22 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Configurable Cloud VM 2 | 3 | Configurable Cloud VM is an open source project licensed under the [Apache v2 License] (https://opensource.org/licenses/Apache-2.0) 4 | 5 | ## Coding Style 6 | 7 | Configurable Cloud VM follows the standard formatting recommendations and language idioms set out 8 | in [Effective Go](https://golang.org/doc/effective_go.html) and in the 9 | [Go Code Review Comments wiki](https://github.com/golang/go/wiki/CodeReviewComments). 10 | 11 | ## Certificate of Origin 12 | 13 | In order to get a clear contribution chain of trust we use the [signed-off-by language] (https://01.org/community/signed-process) 14 | used by the Linux kernel project. 15 | 16 | ## Patch format 17 | 18 | Beside the signed-off-by footer, we expect each patch to comply with the following format: 19 | 20 | ``` 21 | Change summary 22 | 23 | More detailed explanation of your changes: Why and how. 24 | Wrap it to 72 characters. 25 | See [here] (http://chris.beams.io/posts/git-commit/) 26 | for some more good advices. 27 | 28 | Fixes #NUMBER (or URL to the issue) 29 | 30 | Signed-off-by: 31 | ``` 32 | 33 | For example: 34 | 35 | ``` 36 | Fix poorly named identifiers 37 | 38 | One identifier, fnname, in func.go was poorly named. It has been renamed 39 | to fnName. Another identifier retval was not needed and has been removed 40 | entirely. 41 | 42 | Fixes #1 43 | 44 | Signed-off-by: Mark Ryan 45 | ``` 46 | 47 | ## Pull requests 48 | 49 | We accept github pull requests. 50 | 51 | ## Quality Controls 52 | 53 | We request you give quality assurance some consideration by: 54 | 55 | * Adding go unit tests for changes where it makes sense. 56 | * Enabling [Travis CI](https://travis-ci.org/intel/ccloudvm) on your github fork of Configurable Cloud VM to get continuous integration feedback on your dev/test branches. 57 | 58 | ## Issue tracking 59 | 60 | If you have a problem, please let us know. If it's a bug not already documented, by all means please [open an 61 | issue in github](https://github.com/intel/ccloudvm/issues/new) so we all get visibility 62 | the problem and work toward resolution. 63 | -------------------------------------------------------------------------------- /Gopkg.toml: -------------------------------------------------------------------------------- 1 | 2 | # Gopkg.toml example 3 | # 4 | # Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md 5 | # for detailed Gopkg.toml documentation. 6 | # 7 | # required = ["github.com/user/thing/cmd/thing"] 8 | # ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] 9 | # 10 | # [[constraint]] 11 | # name = "github.com/user/project" 12 | # version = "1.0.0" 13 | # 14 | # [[constraint]] 15 | # name = "github.com/user/project2" 16 | # branch = "dev" 17 | # source = "github.com/myfork/project2" 18 | # 19 | # [[override]] 20 | # name = "github.com/x/y" 21 | # version = "2.4.0" 22 | 23 | 24 | [[constraint]] 25 | name = "github.com/ciao-project/ciao" 26 | revision = "194264adc5835bca8bb6fa70cf61330a8ed64764" 27 | 28 | [[constraint]] 29 | name = "github.com/coreos/go-systemd" 30 | version = "v15" 31 | 32 | [[constraint]] 33 | name = "github.com/pmezard/go-difflib" 34 | version = "1.0.0" 35 | 36 | [[constraint]] 37 | name = "golang.org/x/net" 38 | revision = "309822c5b9b9f80db67f016069a12628d94fad34" 39 | 40 | [[constraint]] 41 | name = "golang.org/x/text" 42 | revision = "e19ae1496984b1c655b8044a65c0300a3c878dd3" 43 | 44 | [[constraint]] 45 | branch = "v2" 46 | name = "gopkg.in/yaml.v2" 47 | 48 | [[constraint]] 49 | name = "github.com/spf13/cobra" 50 | revision = "b95ab734e27d33e0d8fbabf71ca990568d4e2020" 51 | 52 | [[constraint]] 53 | name = "github.com/pkg/errors" 54 | revision = "645ef00459ed84a119197bfb8d8205042c6df63d" 55 | -------------------------------------------------------------------------------- /ccvm/instance.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2017 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | package main 18 | 19 | import ( 20 | "bytes" 21 | "fmt" 22 | "net/url" 23 | "strings" 24 | "text/template" 25 | 26 | "github.com/intel/ccloudvm/types" 27 | "github.com/pkg/errors" 28 | yaml "gopkg.in/yaml.v2" 29 | ) 30 | 31 | const defaultRootFSSize = 60 32 | 33 | // Constants for the Guest image used by ccloudvm 34 | 35 | const ( 36 | guestDownloadURL = "https://cloud-images.ubuntu.com/xenial/current/xenial-server-cloudimg-amd64-disk1.img" 37 | guestImageFriendlyName = "Ubuntu 16.04" 38 | ) 39 | 40 | type workloadSpec struct { 41 | BaseImageURL string `yaml:"base_image_url"` 42 | BaseImageName string `yaml:"base_image_name"` 43 | WorkloadName string `yaml:"workload"` 44 | NeedsNestedVM bool `yaml:"needs_nested_vm"` 45 | BIOS string `yaml:"bios"` 46 | VM types.VMSpec `yaml:"vm"` 47 | Inherits string `yaml:"inherits"` 48 | } 49 | 50 | func defaultVMSpec() types.VMSpec { 51 | memDef, cpuDef := 1024, 1 52 | 53 | return types.VMSpec{ 54 | MemMiB: memDef, 55 | CPUs: cpuDef, 56 | DiskGiB: defaultRootFSSize, 57 | } 58 | } 59 | 60 | func defaultWorkload() *workload { 61 | return &workload{ 62 | spec: workloadSpec{ 63 | BaseImageName: guestImageFriendlyName, 64 | BaseImageURL: guestDownloadURL, 65 | VM: defaultVMSpec(), 66 | }, 67 | } 68 | } 69 | 70 | func (ins *workloadSpec) unmarshal(data []byte) error { 71 | err := yaml.Unmarshal(data, ins) 72 | if err != nil { 73 | return errors.Wrap(err, "Unable to unmarshal instance specification") 74 | } 75 | 76 | url, err := url.Parse(ins.BaseImageURL) 77 | if err != nil { 78 | return fmt.Errorf("Unable to parse url %s : %v", 79 | ins.BaseImageURL, err) 80 | } 81 | if ins.BaseImageName == "" { 82 | lastSlash := strings.LastIndex(url.Path, "/") 83 | if lastSlash == -1 { 84 | ins.BaseImageName = url.Path 85 | } else { 86 | ins.BaseImageName = url.Path[lastSlash+1:] 87 | } 88 | } 89 | 90 | return nil 91 | } 92 | 93 | func (ins *workloadSpec) unmarshalWithTemplate(ws *workspace, data string) error { 94 | tmpl, err := template.New("instance-spec").Parse(string(data)) 95 | if err != nil { 96 | return errors.Wrap(err, "Unable to parse instance data template") 97 | } 98 | var buf bytes.Buffer 99 | err = tmpl.Execute(&buf, ws) 100 | if err != nil { 101 | return errors.Wrap(err, "Unable to execute instance data template") 102 | } 103 | return ins.unmarshal(buf.Bytes()) 104 | } 105 | -------------------------------------------------------------------------------- /ccvm/mock_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2017 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | package main 18 | 19 | import ( 20 | "io/ioutil" 21 | "os" 22 | "path" 23 | "path/filepath" 24 | 25 | "github.com/intel/ccloudvm/types" 26 | "github.com/pkg/errors" 27 | ) 28 | 29 | const xenialWorkloadSpec = ` 30 | base_image_url: ` + guestDownloadURL + ` 31 | base_image_name: ` + guestImageFriendlyName + ` 32 | vm: 33 | mem_mib: 3072 34 | cpus: 2 35 | ports: 36 | - host: 10022 37 | guest: 22 38 | mounts: [] 39 | disk_gib: 60 40 | ` 41 | 42 | var mockVMSpec = types.VMSpec{ 43 | MemMiB: 3072, 44 | CPUs: 2, 45 | DiskGiB: defaultRootFSSize, 46 | PortMappings: []types.PortMapping{{Host: 10022, Guest: 22}}, 47 | Mounts: []types.Mount{}, 48 | } 49 | 50 | const sampleCloudInit = ` 51 | ` 52 | 53 | const sampleWorkload = "---\n" + xenialWorkloadSpec + "...\n---\n" + sampleCloudInit + "...\n" 54 | 55 | func createMockWorkSpaceWithWorkload(workload, workloadName, ccvmDir string) (*workspace, error) { 56 | workloadDir := filepath.Join(ccvmDir, "workloads") 57 | err := os.MkdirAll(workloadDir, 0750) 58 | if err != nil { 59 | return nil, errors.Wrapf(err, "Failed to create directory %s", workloadDir) 60 | } 61 | 62 | ws := &workspace{ 63 | ccvmDir: ccvmDir, 64 | } 65 | 66 | workloadFile := path.Join(workloadDir, workloadName+".yaml") 67 | err = ioutil.WriteFile(workloadFile, []byte(workload), 0640) 68 | if err != nil { 69 | return nil, errors.Wrapf(err, "Failed to write workload file %s", workloadFile) 70 | } 71 | 72 | return ws, nil 73 | } 74 | 75 | func createMockWorkSpaceWithInstance(workload, ccvmDir string) (*workspace, error) { 76 | instanceDir, err := ioutil.TempDir(ccvmDir, "wkl-") 77 | if err != nil { 78 | return nil, errors.Wrapf(err, "Failed to create directory %s", instanceDir) 79 | } 80 | 81 | ws := &workspace{ 82 | ccvmDir: ccvmDir, 83 | instanceDir: instanceDir, 84 | } 85 | 86 | workloadFile := path.Join(ws.instanceDir, "state.yaml") 87 | err = ioutil.WriteFile(workloadFile, []byte(workload), 0640) 88 | if err != nil { 89 | return nil, errors.Wrapf(err, "Failed to write workload file %s", workloadFile) 90 | } 91 | 92 | return ws, nil 93 | } 94 | -------------------------------------------------------------------------------- /ccvm/name.go: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2018 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | package main 18 | 19 | import ( 20 | "fmt" 21 | "math/rand" 22 | "sync" 23 | "time" 24 | ) 25 | 26 | var randomAdjectives = []string{ 27 | "alarmed", 28 | "amused", 29 | "angry", 30 | "astonished", 31 | "bored", 32 | "concerned", 33 | "considerate", 34 | "depressed", 35 | "distracted", 36 | "glad", 37 | "gloomy", 38 | "happy", 39 | "incensed", 40 | "sad", 41 | "serene", 42 | "sleepy", 43 | "tense", 44 | "thoughtful", 45 | "tired", 46 | "vague", 47 | "worried", 48 | } 49 | 50 | var randomNames = []string{ 51 | "agravain", 52 | "arthur", 53 | "balin", 54 | "balan", 55 | "bedivere", 56 | "bors", 57 | "dagonet", 58 | "elaine", 59 | "gaheris", 60 | "galahad", 61 | "gareth", 62 | "gawain", 63 | "glatisant", 64 | "guinevere", 65 | "hector", 66 | "igraine", 67 | "isolde", 68 | "kay", 69 | "lancelot", 70 | "leodegrance", 71 | "lot", 72 | "lynette", 73 | "malegant", 74 | "margawse", 75 | "mark", 76 | "merlin", 77 | "mordred", 78 | "morgan", 79 | "nimue", 80 | "owain", 81 | "palomides", 82 | "parcival", 83 | "peles", 84 | "pelinor", 85 | "tristram", 86 | "uther", 87 | } 88 | 89 | type nameIndex struct { 90 | n int 91 | a int 92 | } 93 | 94 | var nameGenerator = struct { 95 | sync.Mutex 96 | rand *rand.Rand 97 | counter int 98 | indicies []nameIndex 99 | }{} 100 | 101 | func init() { 102 | nameGenerator.rand = rand.New(rand.NewSource(time.Now().Unix())) 103 | nameGenerator.indicies = make([]nameIndex, maxNames()) 104 | for i := range randomAdjectives { 105 | for j := range randomNames { 106 | nameGenerator.indicies[(i*len(randomNames))+j] = nameIndex{j, i} 107 | } 108 | } 109 | for i := 0; i < len(nameGenerator.indicies); i++ { 110 | r1 := nameGenerator.rand.Int() % len(nameGenerator.indicies) 111 | nameGenerator.indicies[r1], nameGenerator.indicies[i] = nameGenerator.indicies[i], nameGenerator.indicies[r1] 112 | } 113 | } 114 | 115 | func maxNames() int { 116 | return len(randomAdjectives) * len(randomNames) 117 | } 118 | 119 | func makeRandomName() string { 120 | nameGenerator.Lock() 121 | ni := nameGenerator.indicies[nameGenerator.counter] 122 | nameGenerator.counter++ 123 | if nameGenerator.counter == maxNames() { 124 | nameGenerator.counter = 0 125 | } 126 | nameGenerator.Unlock() 127 | return fmt.Sprintf("%s-%s", randomAdjectives[ni.a], randomNames[ni.n]) 128 | } 129 | -------------------------------------------------------------------------------- /ccvm/name_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2018 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | package main 18 | 19 | import ( 20 | "testing" 21 | ) 22 | 23 | func TestNames(t *testing.T) { 24 | allNames := make(map[string]struct{}) 25 | 26 | for i := 0; i < maxNames(); i++ { 27 | name := makeRandomName() 28 | allNames[name] = struct{}{} 29 | } 30 | 31 | if len(allNames) != maxNames() { 32 | t.Errorf("Not all names generated") 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /ccvm/workloads/artful.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | base_image_url: https://cloud-images.ubuntu.com/artful/current/artful-server-cloudimg-amd64.img 3 | base_image_name: Ubuntu 17.10 4 | vm: 5 | disk_gib: 16 6 | ... 7 | --- 8 | {{- define "ENV" -}} 9 | {{proxyVars .}} 10 | {{- print " DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true " -}} 11 | {{end}} 12 | #cloud-config 13 | write_files: 14 | {{- if len $.HTTPProxy }} 15 | - content: | 16 | [Service] 17 | Environment="HTTP_PROXY={{$.HTTPProxy}}"{{if len .HTTPSProxy}} "HTTPS_PROXY={{.HTTPSProxy}}{{end}}"{{if len .NoProxy}} "NO_PROXY={{.NoProxy}},{{.Hostname}}{{end}}" 18 | path: /etc/systemd/system/docker.service.d/http-proxy.conf 19 | {{- end}} 20 | {{with proxyEnv . 5}} 21 | - content: | 22 | {{.}} 23 | path: /etc/environment 24 | {{end}} 25 | 26 | apt: 27 | {{- if len $.HTTPProxy }} 28 | proxy: "{{$.HTTPProxy}}" 29 | {{- end}} 30 | {{- if len $.HTTPSProxy }} 31 | https_proxy: "{{$.HTTPSProxy}}" 32 | {{- end}} 33 | package_upgrade: {{with .PackageUpgrade}}{{.}}{{else}}false{{end}} 34 | 35 | runcmd: 36 | - {{beginTask . "Booting VM"}} 37 | - {{endTaskOk . }} 38 | 39 | - {{beginTask . (printf "Adding %s to /etc/hosts" .Hostname) }} 40 | - echo "127.0.0.1 {{.Hostname}}" >> /etc/hosts 41 | - {{endTaskCheck .}} 42 | 43 | {{range .Mounts}} 44 | - mkdir -p {{.Path}} 45 | - sudo chown {{$.User}}:{{$.User}} {{.Tag}} 46 | - echo "{{.Tag}} {{.Path}} 9p x-systemd.automount,x-systemd.device-timeout=10,nofail,trans=virtio,version=9p2000.L 0 0" >> /etc/fstab 47 | {{end}} 48 | {{range .Mounts}} 49 | - {{beginTask $ (printf "Mounting %s" .Path) }} 50 | - mount {{.Path}} 51 | - {{endTaskCheck $}} 52 | {{end}} 53 | 54 | 55 | 56 | users: 57 | - name: {{.User}} 58 | uid: "{{.UID}}" 59 | gid: "{{.GID}}" 60 | gecos: CIAO Demo User 61 | lock-passwd: true 62 | shell: /bin/bash 63 | sudo: ALL=(ALL) NOPASSWD:ALL 64 | ssh-authorized-keys: 65 | - {{.PublicKey}} 66 | ... 67 | -------------------------------------------------------------------------------- /ccvm/workloads/bionic.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | base_image_url: https://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-amd64.img 3 | base_image_name: Ubuntu 18.04 4 | vm: 5 | disk_gib: 16 6 | ... 7 | --- 8 | {{- define "ENV" -}} 9 | {{proxyVars .}} 10 | {{- print " DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true " -}} 11 | {{end}} 12 | 13 | #cloud-config 14 | write_files: 15 | {{with proxyEnv . 5}} 16 | - content: | 17 | {{.}} 18 | path: /etc/environment 19 | {{end}} 20 | 21 | apt: 22 | {{- if len $.HTTPProxy }} 23 | proxy: "{{$.HTTPProxy}}" 24 | {{- end}} 25 | {{- if len $.HTTPSProxy }} 26 | https_proxy: "{{$.HTTPSProxy}}" 27 | {{- end}} 28 | package_upgrade: {{with .PackageUpgrade}}{{.}}{{else}}false{{end}} 29 | 30 | runcmd: 31 | - {{beginTask . "Booting VM"}} 32 | - {{endTaskOk . }} 33 | 34 | - {{beginTask . (printf "Adding %s to /etc/hosts" .Hostname) }} 35 | - echo "127.0.0.1 {{.Hostname}}" >> /etc/hosts 36 | - {{endTaskCheck .}} 37 | 38 | {{range .Mounts}} 39 | - mkdir -p {{.Path}} 40 | - sudo chown {{$.User}}:{{$.User}} {{.Tag}} 41 | - echo "{{.Tag}} {{.Path}} 9p x-systemd.automount,x-systemd.device-timeout=10,nofail,trans=virtio,version=9p2000.L 0 0" >> /etc/fstab 42 | {{end}} 43 | {{range .Mounts}} 44 | - {{beginTask $ (printf "Mounting %s" .Path) }} 45 | - mount {{.Path}} 46 | - {{endTaskCheck $}} 47 | {{end}} 48 | 49 | 50 | 51 | users: 52 | - name: {{.User}} 53 | uid: "{{.UID}}" 54 | gid: "{{.GID}}" 55 | gecos: CIAO Demo User 56 | lock-passwd: true 57 | shell: /bin/bash 58 | sudo: ALL=(ALL) NOPASSWD:ALL 59 | ssh-authorized-keys: 60 | - {{.PublicKey}} 61 | ... 62 | -------------------------------------------------------------------------------- /ccvm/workloads/buster.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | base_image_url: https://cloud.debian.org/images/cloud/buster/20201214-484/debian-10-genericcloud-amd64-20201214-484.qcow2 3 | base_image_name: Debian Buster 4 | vm: 5 | disk_gib: 16 6 | ... 7 | --- 8 | {{- define "ENV" -}} 9 | {{proxyVars .}} 10 | {{- print " DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true " -}} 11 | {{end}} 12 | 13 | #cloud-config 14 | write_files: 15 | {{with proxyEnv . 5}} 16 | - content: | 17 | {{.}} 18 | path: /etc/environment 19 | {{end}} 20 | 21 | apt: 22 | {{- if len $.HTTPProxy }} 23 | proxy: "{{$.HTTPProxy}}" 24 | {{- end}} 25 | {{- if len $.HTTPSProxy }} 26 | https_proxy: "{{$.HTTPSProxy}}" 27 | {{- end}} 28 | package_upgrade: {{with .PackageUpgrade}}{{.}}{{else}}false{{end}} 29 | 30 | runcmd: 31 | - {{beginTask . "Booting VM"}} 32 | - {{endTaskOk . }} 33 | 34 | - {{beginTask . (printf "Adding %s to /etc/hosts" .Hostname) }} 35 | - echo "127.0.0.1 {{.Hostname}}" >> /etc/hosts 36 | - {{endTaskCheck .}} 37 | 38 | {{range .Mounts}} 39 | - mkdir -p {{.Path}} 40 | - sudo chown {{$.User}}:{{$.User}} {{.Tag}} 41 | - echo "{{.Tag}} {{.Path}} 9p x-systemd.automount,x-systemd.device-timeout=10,nofail,trans=virtio,version=9p2000.L 0 0" >> /etc/fstab 42 | {{end}} 43 | {{range .Mounts}} 44 | - {{beginTask $ (printf "Mounting %s" .Path) }} 45 | - mount {{.Path}} 46 | - {{endTaskCheck $}} 47 | {{end}} 48 | 49 | 50 | 51 | users: 52 | - name: {{.User}} 53 | uid: "{{.UID}}" 54 | gid: "{{.GID}}" 55 | gecos: CIAO Demo User 56 | lock-passwd: true 57 | shell: /bin/bash 58 | sudo: ALL=(ALL) NOPASSWD:ALL 59 | ssh-authorized-keys: 60 | - {{.PublicKey}} 61 | ... 62 | -------------------------------------------------------------------------------- /ccvm/workloads/centos7.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | base_image_url: https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud-1804_02.qcow2 3 | base_image_name: Centos 7 4 | vm: 5 | disk_gib: 16 6 | ... 7 | --- 8 | #cloud-config 9 | write_files: 10 | {{- if len $.HTTPProxy }} 11 | - content: | 12 | [Service] 13 | Environment="HTTP_PROXY={{$.HTTPProxy}}"{{if len .HTTPSProxy}} "HTTPS_PROXY={{.HTTPSProxy}}{{end}}"{{if len .NoProxy}} "NO_PROXY={{.NoProxy}},{{.Hostname}}{{end}}" 14 | path: /etc/systemd/system/docker.service.d/http-proxy.conf 15 | {{- end}} 16 | {{with proxyEnv . 5}} 17 | - content: | 18 | {{.}} 19 | path: /etc/environment 20 | {{end -}} 21 | 22 | yum: 23 | {{- if len $.HTTPProxy }} 24 | proxy: "{{$.HTTPProxy}}" 25 | {{- end}} 26 | {{- if len $.HTTPSProxy }} 27 | https_proxy: "{{$.HTTPSProxy}}" 28 | {{- end}} 29 | 30 | package_upgrade: {{with .PackageUpgrade}}{{.}}{{else}}false{{end}} 31 | 32 | runcmd: 33 | - {{beginTask . "Booting VM"}} 34 | - {{endTaskOk . }} 35 | 36 | - hostnamectl set-hostname {{.Hostname}} 37 | 38 | - {{beginTask . (printf "Adding %s to /etc/hosts" .Hostname) }} 39 | - echo "127.0.0.1 {{.Hostname}}" >> /etc/hosts 40 | - {{endTaskCheck .}} 41 | 42 | {{range .Mounts}} 43 | - mkdir -p {{.Path}} 44 | - sudo chown {{$.User}}:{{$.User}} {{.Tag}} 45 | - echo "{{.Tag}} {{.Path}} 9p x-systemd.automount,x-systemd.device-timeout=10,nofail,trans=virtio,version=9p2000.L 0 0" >> /etc/fstab 46 | {{end}} 47 | {{range .Mounts}} 48 | - {{beginTask $ (printf "Mounting %s" .Path) }} 49 | - mount {{.Path}} 50 | - {{endTaskCheck $}} 51 | {{end}} 52 | 53 | users: 54 | - name: {{.User}} 55 | uid: "{{.UID}}" 56 | gid: "{{.GID}}" 57 | gecos: CC Demo User 58 | lock-passwd: true 59 | shell: /bin/bash 60 | sudo: ALL=(ALL) NOPASSWD:ALL 61 | ssh-authorized-keys: 62 | - {{.PublicKey}} 63 | ... 64 | -------------------------------------------------------------------------------- /ccvm/workloads/centos8-stream.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | base_image_url: https://cloud.centos.org/centos/8-stream/x86_64/images/CentOS-Stream-GenericCloud-8-20201217.0.x86_64.qcow2 3 | base_image_name: Centos 8 4 | vm: 5 | disk_gib: 16 6 | ... 7 | --- 8 | #cloud-config 9 | write_files: 10 | {{- if len $.HTTPProxy }} 11 | - content: | 12 | [Service] 13 | Environment="HTTP_PROXY={{$.HTTPProxy}}"{{if len .HTTPSProxy}} "HTTPS_PROXY={{.HTTPSProxy}}{{end}}"{{if len .NoProxy}} "NO_PROXY={{.NoProxy}},{{.Hostname}}{{end}}" 14 | path: /etc/systemd/system/docker.service.d/http-proxy.conf 15 | {{- end}} 16 | {{with proxyEnv . 5}} 17 | - content: | 18 | {{.}} 19 | path: /etc/environment 20 | {{end -}} 21 | 22 | yum: 23 | {{- if len $.HTTPProxy }} 24 | proxy: "{{$.HTTPProxy}}" 25 | {{- end}} 26 | {{- if len $.HTTPSProxy }} 27 | https_proxy: "{{$.HTTPSProxy}}" 28 | {{- end}} 29 | 30 | package_upgrade: {{with .PackageUpgrade}}{{.}}{{else}}false{{end}} 31 | 32 | runcmd: 33 | - {{beginTask . "Booting VM"}} 34 | - {{endTaskOk . }} 35 | 36 | - hostnamectl set-hostname {{.Hostname}} 37 | 38 | - {{beginTask . (printf "Adding %s to /etc/hosts" .Hostname) }} 39 | - echo "127.0.0.1 {{.Hostname}}" >> /etc/hosts 40 | - {{endTaskCheck .}} 41 | 42 | {{range .Mounts}} 43 | - mkdir -p {{.Path}} 44 | - sudo chown {{$.User}}:{{$.User}} {{.Tag}} 45 | - echo "{{.Tag}} {{.Path}} 9p x-systemd.automount,x-systemd.device-timeout=10,nofail,trans=virtio,version=9p2000.L 0 0" >> /etc/fstab 46 | {{end}} 47 | {{range .Mounts}} 48 | - {{beginTask $ (printf "Mounting %s" .Path) }} 49 | - mount {{.Path}} 50 | - {{endTaskCheck $}} 51 | {{end}} 52 | 53 | users: 54 | - name: {{.User}} 55 | uid: "{{.UID}}" 56 | gid: "{{.GID}}" 57 | gecos: CC Demo User 58 | lock-passwd: true 59 | shell: /bin/bash 60 | sudo: ALL=(ALL) NOPASSWD:ALL 61 | ssh-authorized-keys: 62 | - {{.PublicKey}} 63 | ... 64 | -------------------------------------------------------------------------------- /ccvm/workloads/docker-bionic.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | inherits: bionic 3 | ... 4 | --- 5 | {{- define "ENV" -}} 6 | {{proxyVars .}} 7 | {{- print " DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true " -}} 8 | {{end}} 9 | 10 | write_files: 11 | {{- if len $.HTTPProxy }} 12 | - content: | 13 | [Service] 14 | Environment="HTTP_PROXY={{$.HTTPProxy}}"{{if len .HTTPSProxy}} "HTTPS_PROXY={{.HTTPSProxy}}{{end}}"{{if len .NoProxy}} "NO_PROXY={{.NoProxy}},{{.Hostname}}{{end}}" 15 | path: /etc/systemd/system/docker.service.d/http-proxy.conf 16 | {{- end}} 17 | 18 | packages: 19 | - apt-transport-https 20 | - ca-certificates 21 | - curl 22 | - software-properties-common 23 | 24 | runcmd: 25 | - {{beginTask . "Add docker GPG key" }} 26 | - {{template "ENV" .}}curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - 27 | - {{endTaskCheck .}} 28 | 29 | - {{beginTask . "Adding docker repo"}} 30 | - {{template "ENV" .}} sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" 31 | - {{endTaskCheck .}} 32 | 33 | - {{beginTask . "Retrieving updated list of packages"}} 34 | - {{template "ENV" .}}sudo apt-get update 35 | - {{endTaskCheck .}} 36 | 37 | - {{beginTask . "Install docker-ce"}} 38 | - sudo apt-get install -y docker-ce 39 | - {{endTaskCheck .}} 40 | 41 | - {{beginTask . (printf "Adding user %s to the docker group" .User)}} 42 | - sudo gpasswd -a {{.User}} docker 43 | - {{endTaskCheck .}} 44 | 45 | {{- if len $.HTTPProxy }} 46 | - {{beginTask . "Configuring docker proxies" }} 47 | - mkdir /home/{{.User}}/.docker 48 | - echo "{" >> /home/{{.User}}/.docker/config.json 49 | - echo " \"proxies\":" >> /home/{{.User}}/.docker/config.json 50 | - echo " {" >> /home/{{.User}}/.docker/config.json 51 | - echo " \"default\":" >> /home/{{.User}}/.docker/config.json 52 | - echo " {" >> /home/{{.User}}/.docker/config.json 53 | - echo " \"httpProxy\":\"{{.HTTPProxy}}\"," >> /home/{{.User}}/.docker/config.json 54 | - echo " \"httpsProxy\":\"{{.HTTPSProxy}}\"," >> /home/{{.User}}/.docker/config.json 55 | - echo " \"noProxy\":\"{{.NoProxy}}\"" >> /home/{{.User}}/.docker/config.json 56 | - echo " }" >> /home/{{.User}}/.docker/config.json 57 | - echo " }" >> /home/{{.User}}/.docker/config.json 58 | - echo "}" >> /home/{{.User}}/.docker/config.json 59 | - chown {{.User}}:{{.User}} -R /home/{{.User}}/.docker 60 | - {{endTaskCheck .}} 61 | {{end}} 62 | 63 | # Below is a temporary hack to make sure docker containers and the host have networking after installing docker. 64 | # https://github.com/docker/libnetwork/issues/2187 65 | - {{beginTask . "Fixing resolv.conf to counter current bionic networking issue with docker"}} 66 | - sudo rm /etc/resolv.conf 67 | - sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf 68 | - {{endTaskCheck .}} 69 | ... 70 | -------------------------------------------------------------------------------- /ccvm/workloads/docker-xenial.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | inherits: xenial 3 | ... 4 | --- 5 | {{- define "ENV" -}} 6 | {{proxyVars .}} 7 | {{- print " DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true " -}} 8 | {{end}} 9 | #cloud-config 10 | {{- if len $.HTTPProxy }} 11 | write_files: 12 | - content: | 13 | [Service] 14 | Environment="HTTP_PROXY={{$.HTTPProxy}}"{{if len .HTTPSProxy}} "HTTPS_PROXY={{.HTTPSProxy}}{{end}}"{{if len .NoProxy}} "NO_PROXY={{.NoProxy}},{{.Hostname}}{{end}}" 15 | path: /etc/systemd/system/docker.service.d/http-proxy.conf 16 | {{- end}} 17 | packages: 18 | - apt-transport-https 19 | - ca-certificates 20 | - curl 21 | - software-properties-common 22 | 23 | runcmd: 24 | - {{beginTask . "Add docker GPG key" }} 25 | - {{template "ENV" .}}curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - 26 | - {{endTaskCheck .}} 27 | 28 | - {{beginTask . "Adding docker repo"}} 29 | - {{template "ENV" .}} sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" 30 | - {{endTaskCheck .}} 31 | 32 | - {{beginTask . "Retrieving updated list of packages"}} 33 | - {{template "ENV" .}}sudo apt-get update 34 | - {{endTaskCheck .}} 35 | 36 | - {{beginTask . "Install docker-ce"}} 37 | - sudo apt-get install -y docker-ce 38 | - {{endTaskCheck .}} 39 | 40 | - {{beginTask . (printf "Adding user %s to the docker group" .User)}} 41 | - sudo gpasswd -a {{.User}} docker 42 | - {{endTaskCheck .}} 43 | 44 | {{- if len $.HTTPProxy }} 45 | - {{beginTask . "Configuring docker proxies" }} 46 | - mkdir /home/{{.User}}/.docker 47 | - echo "{" >> /home/{{.User}}/.docker/config.json 48 | - echo " \"proxies\":" >> /home/{{.User}}/.docker/config.json 49 | - echo " {" >> /home/{{.User}}/.docker/config.json 50 | - echo " \"default\":" >> /home/{{.User}}/.docker/config.json 51 | - echo " {" >> /home/{{.User}}/.docker/config.json 52 | - echo " \"httpProxy\":\"{{.HTTPProxy}}\"," >> /home/{{.User}}/.docker/config.json 53 | - echo " \"httpsProxy\":\"{{.HTTPSProxy}}\"," >> /home/{{.User}}/.docker/config.json 54 | - echo " \"noProxy\":\"{{.NoProxy}}\"" >> /home/{{.User}}/.docker/config.json 55 | - echo " }" >> /home/{{.User}}/.docker/config.json 56 | - echo " }" >> /home/{{.User}}/.docker/config.json 57 | - echo "}" >> /home/{{.User}}/.docker/config.json 58 | - chown {{.User}}:{{.User}} -R /home/{{.User}}/.docker 59 | - {{endTaskCheck .}} 60 | {{end}} 61 | 62 | ... 63 | -------------------------------------------------------------------------------- /ccvm/workloads/fedora27.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | base_image_url: https://archives.fedoraproject.org/pub/archive/fedora/linux/releases/27/CloudImages/x86_64/images/Fedora-Cloud-Base-27-1.6.x86_64.qcow2 3 | base_image_name: Fedora 27 4 | vm: 5 | disk_gib: 16 6 | ... 7 | --- 8 | #cloud-config 9 | write_files: 10 | {{- if len $.HTTPProxy }} 11 | - content: | 12 | [Service] 13 | Environment="HTTP_PROXY={{$.HTTPProxy}}"{{if len .HTTPSProxy}} "HTTPS_PROXY={{.HTTPSProxy}}{{end}}"{{if len .NoProxy}} "NO_PROXY={{.NoProxy}},{{.Hostname}}{{end}}" 14 | path: /etc/systemd/system/docker.service.d/http-proxy.conf 15 | {{- end}} 16 | {{with proxyEnv . 5}} 17 | - content: | 18 | {{.}} 19 | path: /etc/environment 20 | {{end -}} 21 | 22 | dnf: 23 | {{- if len $.HTTPProxy }} 24 | proxy: "{{$.HTTPProxy}}" 25 | {{- end}} 26 | {{- if len $.HTTPSProxy }} 27 | https_proxy: "{{$.HTTPSProxy}}" 28 | {{- end}} 29 | 30 | package_upgrade: {{with .PackageUpgrade}}{{.}}{{else}}false{{end}} 31 | 32 | runcmd: 33 | - {{beginTask . "Booting VM"}} 34 | - {{endTaskOk . }} 35 | 36 | - hostnamectl set-hostname {{.Hostname}} 37 | 38 | - {{beginTask . (printf "Adding %s to /etc/hosts" .Hostname) }} 39 | - echo "127.0.0.1 {{.Hostname}}" >> /etc/hosts 40 | - {{endTaskCheck .}} 41 | 42 | {{range .Mounts}} 43 | - mkdir -p {{.Path}} 44 | - sudo chown {{$.User}}:{{$.User}} {{.Tag}} 45 | - echo "{{.Tag}} {{.Path}} 9p x-systemd.automount,x-systemd.device-timeout=10,nofail,trans=virtio,version=9p2000.L 0 0" >> /etc/fstab 46 | {{end}} 47 | {{range .Mounts}} 48 | - {{beginTask $ (printf "Mounting %s" .Path) }} 49 | - mount {{.Path}} 50 | - {{endTaskCheck $}} 51 | {{end}} 52 | 53 | users: 54 | - name: {{.User}} 55 | uid: "{{.UID}}" 56 | gid: "{{.GID}}" 57 | gecos: CC Demo User 58 | lock-passwd: true 59 | shell: /bin/bash 60 | sudo: ALL=(ALL) NOPASSWD:ALL 61 | ssh-authorized-keys: 62 | - {{.PublicKey}} 63 | ... 64 | -------------------------------------------------------------------------------- /ccvm/workloads/fedora28.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | base_image_url: https://archives.fedoraproject.org/pub/archive/fedora/linux/releases/28/Cloud/x86_64/images/Fedora-Cloud-Base-28-1.1.x86_64.qcow2 3 | base_image_name: Fedora 28 4 | vm: 5 | disk_gib: 16 6 | ... 7 | --- 8 | #cloud-config 9 | write_files: 10 | {{- if len $.HTTPProxy }} 11 | - content: | 12 | [Service] 13 | Environment="HTTP_PROXY={{$.HTTPProxy}}"{{if len .HTTPSProxy}} "HTTPS_PROXY={{.HTTPSProxy}}{{end}}"{{if len .NoProxy}} "NO_PROXY={{.NoProxy}},{{.Hostname}}{{end}}" 14 | path: /etc/systemd/system/docker.service.d/http-proxy.conf 15 | {{- end}} 16 | {{with proxyEnv . 5}} 17 | - content: | 18 | {{.}} 19 | path: /etc/environment 20 | {{end -}} 21 | 22 | dnf: 23 | {{- if len $.HTTPProxy }} 24 | proxy: "{{$.HTTPProxy}}" 25 | {{- end}} 26 | {{- if len $.HTTPSProxy }} 27 | https_proxy: "{{$.HTTPSProxy}}" 28 | {{- end}} 29 | 30 | package_upgrade: {{with .PackageUpgrade}}{{.}}{{else}}false{{end}} 31 | 32 | runcmd: 33 | - {{beginTask . "Booting VM"}} 34 | - {{endTaskOk . }} 35 | 36 | - hostnamectl set-hostname {{.Hostname}} 37 | 38 | - {{beginTask . (printf "Adding %s to /etc/hosts" .Hostname) }} 39 | - echo "127.0.0.1 {{.Hostname}}" >> /etc/hosts 40 | - {{endTaskCheck .}} 41 | 42 | {{range .Mounts}} 43 | - mkdir -p {{.Path}} 44 | - sudo chown {{$.User}}:{{$.User}} {{.Tag}} 45 | - echo "{{.Tag}} {{.Path}} 9p x-systemd.automount,x-systemd.device-timeout=10,nofail,trans=virtio,version=9p2000.L 0 0" >> /etc/fstab 46 | {{end}} 47 | {{range .Mounts}} 48 | - {{beginTask $ (printf "Mounting %s" .Path) }} 49 | - mount {{.Path}} 50 | - {{endTaskCheck $}} 51 | {{end}} 52 | 53 | users: 54 | - name: {{.User}} 55 | uid: "{{.UID}}" 56 | gid: "{{.GID}}" 57 | gecos: CC Demo User 58 | lock-passwd: true 59 | shell: /bin/bash 60 | sudo: ALL=(ALL) NOPASSWD:ALL 61 | ssh-authorized-keys: 62 | - {{.PublicKey}} 63 | ... 64 | -------------------------------------------------------------------------------- /ccvm/workloads/fedora29.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | base_image_url: https://archives.fedoraproject.org/pub/archive/fedora/linux/releases/29/Cloud/x86_64/images/Fedora-Cloud-Base-29-1.2.x86_64.qcow2 3 | base_image_name: Fedora 29 4 | vm: 5 | disk_gib: 16 6 | ... 7 | --- 8 | #cloud-config 9 | write_files: 10 | {{- if len $.HTTPProxy }} 11 | - content: | 12 | [Service] 13 | Environment="HTTP_PROXY={{$.HTTPProxy}}"{{if len .HTTPSProxy}} "HTTPS_PROXY={{.HTTPSProxy}}{{end}}"{{if len .NoProxy}} "NO_PROXY={{.NoProxy}},{{.Hostname}}{{end}}" 14 | path: /etc/systemd/system/docker.service.d/http-proxy.conf 15 | {{- end}} 16 | {{with proxyEnv . 5}} 17 | - content: | 18 | {{.}} 19 | path: /etc/environment 20 | {{end -}} 21 | 22 | dnf: 23 | {{- if len $.HTTPProxy }} 24 | proxy: "{{$.HTTPProxy}}" 25 | {{- end}} 26 | {{- if len $.HTTPSProxy }} 27 | https_proxy: "{{$.HTTPSProxy}}" 28 | {{- end}} 29 | 30 | package_upgrade: {{with .PackageUpgrade}}{{.}}{{else}}false{{end}} 31 | 32 | runcmd: 33 | - {{beginTask . "Booting VM"}} 34 | - {{endTaskOk . }} 35 | 36 | - hostnamectl set-hostname {{.Hostname}} 37 | 38 | - {{beginTask . (printf "Adding %s to /etc/hosts" .Hostname) }} 39 | - echo "127.0.0.1 {{.Hostname}}" >> /etc/hosts 40 | - {{endTaskCheck .}} 41 | 42 | {{range .Mounts}} 43 | - mkdir -p {{.Path}} 44 | - sudo chown {{$.User}}:{{$.User}} {{.Tag}} 45 | - echo "{{.Tag}} {{.Path}} 9p x-systemd.automount,x-systemd.device-timeout=10,nofail,trans=virtio,version=9p2000.L 0 0" >> /etc/fstab 46 | {{end}} 47 | {{range .Mounts}} 48 | - {{beginTask $ (printf "Mounting %s" .Path) }} 49 | - mount {{.Path}} 50 | - {{endTaskCheck $}} 51 | {{end}} 52 | 53 | users: 54 | - name: {{.User}} 55 | uid: "{{.UID}}" 56 | gid: "{{.GID}}" 57 | gecos: CC Demo User 58 | lock-passwd: true 59 | shell: /bin/bash 60 | sudo: ALL=(ALL) NOPASSWD:ALL 61 | ssh-authorized-keys: 62 | - {{.PublicKey}} 63 | ... 64 | -------------------------------------------------------------------------------- /ccvm/workloads/fedora30.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | base_image_url: https://archives.fedoraproject.org/pub/archive/fedora/linux/releases/30/Cloud/x86_64/images/Fedora-Cloud-Base-30-1.2.x86_64.qcow2 3 | base_image_name: Fedora 30 4 | vm: 5 | disk_gib: 16 6 | ... 7 | --- 8 | #cloud-config 9 | write_files: 10 | {{- if len $.HTTPProxy }} 11 | - content: | 12 | [Service] 13 | Environment="HTTP_PROXY={{$.HTTPProxy}}"{{if len .HTTPSProxy}} "HTTPS_PROXY={{.HTTPSProxy}}{{end}}"{{if len .NoProxy}} "NO_PROXY={{.NoProxy}},{{.Hostname}}{{end}}" 14 | path: /etc/systemd/system/docker.service.d/http-proxy.conf 15 | {{- end}} 16 | {{with proxyEnv . 5}} 17 | - content: | 18 | {{.}} 19 | path: /etc/environment 20 | {{end -}} 21 | 22 | dnf: 23 | {{- if len $.HTTPProxy }} 24 | proxy: "{{$.HTTPProxy}}" 25 | {{- end}} 26 | {{- if len $.HTTPSProxy }} 27 | https_proxy: "{{$.HTTPSProxy}}" 28 | {{- end}} 29 | 30 | package_upgrade: {{with .PackageUpgrade}}{{.}}{{else}}false{{end}} 31 | 32 | runcmd: 33 | - {{beginTask . "Booting VM"}} 34 | - {{endTaskOk . }} 35 | 36 | - hostnamectl set-hostname {{.Hostname}} 37 | 38 | - {{beginTask . (printf "Adding %s to /etc/hosts" .Hostname) }} 39 | - echo "127.0.0.1 {{.Hostname}}" >> /etc/hosts 40 | - {{endTaskCheck .}} 41 | 42 | {{range .Mounts}} 43 | - mkdir -p {{.Path}} 44 | - sudo chown {{$.User}}:{{$.User}} {{.Tag}} 45 | - echo "{{.Tag}} {{.Path}} 9p x-systemd.automount,x-systemd.device-timeout=10,nofail,trans=virtio,version=9p2000.L 0 0" >> /etc/fstab 46 | {{end}} 47 | {{range .Mounts}} 48 | - {{beginTask $ (printf "Mounting %s" .Path) }} 49 | - mount {{.Path}} 50 | - {{endTaskCheck $}} 51 | {{end}} 52 | 53 | users: 54 | - name: {{.User}} 55 | uid: "{{.UID}}" 56 | gid: "{{.GID}}" 57 | gecos: CC Demo User 58 | lock-passwd: true 59 | shell: /bin/bash 60 | sudo: ALL=(ALL) NOPASSWD:ALL 61 | ssh-authorized-keys: 62 | - {{.PublicKey}} 63 | ... 64 | -------------------------------------------------------------------------------- /ccvm/workloads/fedora31.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | base_image_url: https://archives.fedoraproject.org/pub/archive/fedora/linux/releases/31/Cloud/x86_64/images/Fedora-Cloud-Base-31-1.9.x86_64.qcow2 3 | base_image_name: Fedora 31 4 | vm: 5 | disk_gib: 16 6 | ... 7 | --- 8 | #cloud-config 9 | write_files: 10 | {{- if len $.HTTPProxy }} 11 | - content: | 12 | [Service] 13 | Environment="HTTP_PROXY={{$.HTTPProxy}}"{{if len .HTTPSProxy}} "HTTPS_PROXY={{.HTTPSProxy}}{{end}}"{{if len .NoProxy}} "NO_PROXY={{.NoProxy}},{{.Hostname}}{{end}}" 14 | path: /etc/systemd/system/docker.service.d/http-proxy.conf 15 | {{- end}} 16 | {{with proxyEnv . 5}} 17 | - content: | 18 | {{.}} 19 | path: /etc/environment 20 | {{end -}} 21 | 22 | dnf: 23 | {{- if len $.HTTPProxy }} 24 | proxy: "{{$.HTTPProxy}}" 25 | {{- end}} 26 | {{- if len $.HTTPSProxy }} 27 | https_proxy: "{{$.HTTPSProxy}}" 28 | {{- end}} 29 | 30 | package_upgrade: {{with .PackageUpgrade}}{{.}}{{else}}false{{end}} 31 | 32 | runcmd: 33 | - {{beginTask . "Booting VM"}} 34 | - {{endTaskOk . }} 35 | 36 | - hostnamectl set-hostname {{.Hostname}} 37 | 38 | - {{beginTask . (printf "Adding %s to /etc/hosts" .Hostname) }} 39 | - echo "127.0.0.1 {{.Hostname}}" >> /etc/hosts 40 | - {{endTaskCheck .}} 41 | 42 | {{range .Mounts}} 43 | - mkdir -p {{.Path}} 44 | - sudo chown {{$.User}}:{{$.User}} {{.Tag}} 45 | - echo "{{.Tag}} {{.Path}} 9p x-systemd.automount,x-systemd.device-timeout=10,nofail,trans=virtio,version=9p2000.L 0 0" >> /etc/fstab 46 | {{end}} 47 | {{range .Mounts}} 48 | - {{beginTask $ (printf "Mounting %s" .Path) }} 49 | - mount {{.Path}} 50 | - {{endTaskCheck $}} 51 | {{end}} 52 | 53 | users: 54 | - name: {{.User}} 55 | uid: "{{.UID}}" 56 | gid: "{{.GID}}" 57 | gecos: CC Demo User 58 | lock-passwd: true 59 | shell: /bin/bash 60 | sudo: ALL=(ALL) NOPASSWD:ALL 61 | ssh-authorized-keys: 62 | - {{.PublicKey}} 63 | ... 64 | -------------------------------------------------------------------------------- /ccvm/workloads/fedora32.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | base_image_url: https://mirror.lax.genesisadaptive.com/fedora/linux/releases/32/Cloud/x86_64/images/Fedora-Cloud-Base-32-1.6.x86_64.qcow2 3 | base_image_name: Fedora 32 4 | vm: 5 | disk_gib: 16 6 | ... 7 | --- 8 | #cloud-config 9 | write_files: 10 | {{- if len $.HTTPProxy }} 11 | - content: | 12 | [Service] 13 | Environment="HTTP_PROXY={{$.HTTPProxy}}"{{if len .HTTPSProxy}} "HTTPS_PROXY={{.HTTPSProxy}}{{end}}"{{if len .NoProxy}} "NO_PROXY={{.NoProxy}},{{.Hostname}}{{end}}" 14 | path: /etc/systemd/system/docker.service.d/http-proxy.conf 15 | {{- end}} 16 | {{with proxyEnv . 5}} 17 | - content: | 18 | {{.}} 19 | path: /etc/environment 20 | {{end -}} 21 | 22 | dnf: 23 | {{- if len $.HTTPProxy }} 24 | proxy: "{{$.HTTPProxy}}" 25 | {{- end}} 26 | {{- if len $.HTTPSProxy }} 27 | https_proxy: "{{$.HTTPSProxy}}" 28 | {{- end}} 29 | 30 | package_upgrade: {{with .PackageUpgrade}}{{.}}{{else}}false{{end}} 31 | 32 | runcmd: 33 | - {{beginTask . "Booting VM"}} 34 | - {{endTaskOk . }} 35 | 36 | - hostnamectl set-hostname {{.Hostname}} 37 | 38 | - {{beginTask . (printf "Adding %s to /etc/hosts" .Hostname) }} 39 | - echo "127.0.0.1 {{.Hostname}}" >> /etc/hosts 40 | - {{endTaskCheck .}} 41 | 42 | {{range .Mounts}} 43 | - mkdir -p {{.Path}} 44 | - sudo chown {{$.User}}:{{$.User}} {{.Tag}} 45 | - echo "{{.Tag}} {{.Path}} 9p x-systemd.automount,x-systemd.device-timeout=10,nofail,trans=virtio,version=9p2000.L 0 0" >> /etc/fstab 46 | {{end}} 47 | {{range .Mounts}} 48 | - {{beginTask $ (printf "Mounting %s" .Path) }} 49 | - mount {{.Path}} 50 | - {{endTaskCheck $}} 51 | {{end}} 52 | 53 | users: 54 | - name: {{.User}} 55 | uid: "{{.UID}}" 56 | gid: "{{.GID}}" 57 | gecos: CC Demo User 58 | lock-passwd: true 59 | shell: /bin/bash 60 | sudo: ALL=(ALL) NOPASSWD:ALL 61 | ssh-authorized-keys: 62 | - {{.PublicKey}} 63 | ... 64 | -------------------------------------------------------------------------------- /ccvm/workloads/fedora33.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | base_image_url: https://mirror.lax.genesisadaptive.com/fedora/linux/releases/33/Cloud/x86_64/images/Fedora-Cloud-Base-33-1.2.x86_64.qcow2 3 | base_image_name: Fedora 33 4 | vm: 5 | disk_gib: 16 6 | ... 7 | --- 8 | #cloud-config 9 | write_files: 10 | {{- if len $.HTTPProxy }} 11 | - content: | 12 | [Service] 13 | Environment="HTTP_PROXY={{$.HTTPProxy}}"{{if len .HTTPSProxy}} "HTTPS_PROXY={{.HTTPSProxy}}{{end}}"{{if len .NoProxy}} "NO_PROXY={{.NoProxy}},{{.Hostname}}{{end}}" 14 | path: /etc/systemd/system/docker.service.d/http-proxy.conf 15 | {{- end}} 16 | {{with proxyEnv . 5}} 17 | - content: | 18 | {{.}} 19 | path: /etc/environment 20 | {{end -}} 21 | 22 | dnf: 23 | {{- if len $.HTTPProxy }} 24 | proxy: "{{$.HTTPProxy}}" 25 | {{- end}} 26 | {{- if len $.HTTPSProxy }} 27 | https_proxy: "{{$.HTTPSProxy}}" 28 | {{- end}} 29 | 30 | package_upgrade: {{with .PackageUpgrade}}{{.}}{{else}}false{{end}} 31 | 32 | runcmd: 33 | - {{beginTask . "Booting VM"}} 34 | - {{endTaskOk . }} 35 | 36 | - hostnamectl set-hostname {{.Hostname}} 37 | 38 | - {{beginTask . (printf "Adding %s to /etc/hosts" .Hostname) }} 39 | - echo "127.0.0.1 {{.Hostname}}" >> /etc/hosts 40 | - {{endTaskCheck .}} 41 | 42 | {{range .Mounts}} 43 | - mkdir -p {{.Path}} 44 | - sudo chown {{$.User}}:{{$.User}} {{.Tag}} 45 | - echo "{{.Tag}} {{.Path}} 9p x-systemd.automount,x-systemd.device-timeout=10,nofail,trans=virtio,version=9p2000.L 0 0" >> /etc/fstab 46 | {{end}} 47 | {{range .Mounts}} 48 | - {{beginTask $ (printf "Mounting %s" .Path) }} 49 | - mount {{.Path}} 50 | - {{endTaskCheck $}} 51 | {{end}} 52 | 53 | users: 54 | - name: {{.User}} 55 | uid: "{{.UID}}" 56 | gid: "{{.GID}}" 57 | gecos: CC Demo User 58 | lock-passwd: true 59 | shell: /bin/bash 60 | sudo: ALL=(ALL) NOPASSWD:ALL 61 | ssh-authorized-keys: 62 | - {{.PublicKey}} 63 | ... 64 | -------------------------------------------------------------------------------- /ccvm/workloads/focal.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | base_image_url: https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img 3 | base_image_name: Ubuntu 20.04 4 | vm: 5 | disk_gib: 16 6 | ... 7 | --- 8 | {{- define "ENV" -}} 9 | {{proxyVars .}} 10 | {{- print " DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true " -}} 11 | {{end}} 12 | #cloud-config 13 | write_files: 14 | {{- if len $.HTTPProxy }} 15 | - content: | 16 | [Service] 17 | Environment="HTTP_PROXY={{$.HTTPProxy}}"{{if len .HTTPSProxy}} "HTTPS_PROXY={{.HTTPSProxy}}{{end}}"{{if len .NoProxy}} "NO_PROXY={{.NoProxy}},{{.Hostname}}{{end}}" 18 | path: /etc/systemd/system/docker.service.d/http-proxy.conf 19 | {{- end}} 20 | {{with proxyEnv . 5}} 21 | - content: | 22 | {{.}} 23 | path: /etc/environment 24 | {{end}} 25 | 26 | apt: 27 | {{- if len $.HTTPProxy }} 28 | proxy: "{{$.HTTPProxy}}" 29 | {{- end}} 30 | {{- if len $.HTTPSProxy }} 31 | https_proxy: "{{$.HTTPSProxy}}" 32 | {{- end}} 33 | package_upgrade: {{with .PackageUpgrade}}{{.}}{{else}}false{{end}} 34 | 35 | runcmd: 36 | - {{beginTask . "Booting VM"}} 37 | - {{endTaskOk . }} 38 | 39 | - {{beginTask . (printf "Adding %s to /etc/hosts" .Hostname) }} 40 | - echo "127.0.0.1 {{.Hostname}}" >> /etc/hosts 41 | - {{endTaskCheck .}} 42 | 43 | {{range .Mounts}} 44 | - mkdir -p {{.Path}} 45 | - sudo chown {{$.User}}:{{$.User}} {{.Tag}} 46 | - echo "{{.Tag}} {{.Path}} 9p x-systemd.automount,x-systemd.device-timeout=10,nofail,trans=virtio,version=9p2000.L 0 0" >> /etc/fstab 47 | {{end}} 48 | {{range .Mounts}} 49 | - {{beginTask $ (printf "Mounting %s" .Path) }} 50 | - mount {{.Path}} 51 | - {{endTaskCheck $}} 52 | {{end}} 53 | 54 | 55 | 56 | users: 57 | - name: {{.User}} 58 | uid: "{{.UID}}" 59 | gid: "{{.GID}}" 60 | gecos: CIAO Demo User 61 | lock-passwd: true 62 | shell: /bin/bash 63 | sudo: ALL=(ALL) NOPASSWD:ALL 64 | ssh-authorized-keys: 65 | - {{.PublicKey}} 66 | ... 67 | -------------------------------------------------------------------------------- /ccvm/workloads/semaphore.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | inherits: xenial 3 | ... 4 | --- 5 | packages: 6 | - nginx 7 | 8 | runcmd: 9 | {{with .Mounts}} 10 | - {{beginTask $ "Downloading README file" }} 11 | - su -c "{{download $ "https://raw.githubusercontent.com/intel/ccloudvm/master/README.md" (printf "%s/down/README.md" (index . 0).Path)}}" {{$.User}} 12 | - {{endTaskCheck $}} 13 | {{end}} 14 | ... 15 | -------------------------------------------------------------------------------- /ccvm/workloads/sid.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | base_image_url: https://cloud.debian.org/images/cloud/sid/daily/20210109-510/debian-sid-genericcloud-amd64-daily-20210109-510.qcow2 3 | base_image_name: Debian Sid 4 | vm: 5 | disk_gib: 16 6 | ... 7 | --- 8 | {{- define "ENV" -}} 9 | {{proxyVars .}} 10 | {{- print " DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true " -}} 11 | {{end}} 12 | 13 | #cloud-config 14 | write_files: 15 | {{with proxyEnv . 5}} 16 | - content: | 17 | {{.}} 18 | path: /etc/environment 19 | {{end}} 20 | 21 | apt: 22 | {{- if len $.HTTPProxy }} 23 | proxy: "{{$.HTTPProxy}}" 24 | {{- end}} 25 | {{- if len $.HTTPSProxy }} 26 | https_proxy: "{{$.HTTPSProxy}}" 27 | {{- end}} 28 | package_upgrade: {{with .PackageUpgrade}}{{.}}{{else}}false{{end}} 29 | 30 | runcmd: 31 | - {{beginTask . "Booting VM"}} 32 | - {{endTaskOk . }} 33 | 34 | - {{beginTask . (printf "Adding %s to /etc/hosts" .Hostname) }} 35 | - echo "127.0.0.1 {{.Hostname}}" >> /etc/hosts 36 | - {{endTaskCheck .}} 37 | 38 | {{range .Mounts}} 39 | - mkdir -p {{.Path}} 40 | - sudo chown {{$.User}}:{{$.User}} {{.Tag}} 41 | - echo "{{.Tag}} {{.Path}} 9p x-systemd.automount,x-systemd.device-timeout=10,nofail,trans=virtio,version=9p2000.L 0 0" >> /etc/fstab 42 | {{end}} 43 | {{range .Mounts}} 44 | - {{beginTask $ (printf "Mounting %s" .Path) }} 45 | - mount {{.Path}} 46 | - {{endTaskCheck $}} 47 | {{end}} 48 | 49 | 50 | 51 | users: 52 | - name: {{.User}} 53 | uid: "{{.UID}}" 54 | gid: "{{.GID}}" 55 | gecos: CIAO Demo User 56 | lock-passwd: true 57 | shell: /bin/bash 58 | sudo: ALL=(ALL) NOPASSWD:ALL 59 | ssh-authorized-keys: 60 | - {{.PublicKey}} 61 | ... 62 | -------------------------------------------------------------------------------- /ccvm/workloads/xenial.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | base_image_url: https://cloud-images.ubuntu.com/xenial/current/xenial-server-cloudimg-amd64-disk1.img 3 | base_image_name: Ubuntu 16.04 4 | vm: 5 | disk_gib: 16 6 | ... 7 | --- 8 | {{- define "ENV" -}} 9 | {{proxyVars .}} 10 | {{- print " DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true " -}} 11 | {{end}} 12 | #cloud-config 13 | write_files: 14 | {{with proxyEnv . 5}} 15 | - content: | 16 | {{.}} 17 | path: /etc/environment 18 | {{end}} 19 | 20 | apt: 21 | {{- if len $.HTTPProxy }} 22 | proxy: "{{$.HTTPProxy}}" 23 | {{- end}} 24 | {{- if len $.HTTPSProxy }} 25 | https_proxy: "{{$.HTTPSProxy}}" 26 | {{- end}} 27 | package_upgrade: {{with .PackageUpgrade}}{{.}}{{else}}false{{end}} 28 | 29 | runcmd: 30 | - {{beginTask . "Booting VM"}} 31 | - {{endTaskOk . }} 32 | 33 | - {{beginTask . (printf "Adding %s to /etc/hosts" .Hostname) }} 34 | - echo "127.0.0.1 {{.Hostname}}" >> /etc/hosts 35 | - {{endTaskCheck .}} 36 | 37 | {{range .Mounts}} 38 | - mkdir -p {{.Path}} 39 | - sudo chown {{$.User}}:{{$.User}} {{.Tag}} 40 | - echo "{{.Tag}} {{.Path}} 9p x-systemd.automount,x-systemd.device-timeout=10,nofail,trans=virtio,version=9p2000.L 0 0" >> /etc/fstab 41 | {{end}} 42 | {{range .Mounts}} 43 | - {{beginTask $ (printf "Mounting %s" .Path) }} 44 | - mount {{.Path}} 45 | - {{endTaskCheck $}} 46 | {{end}} 47 | 48 | users: 49 | - name: {{.User}} 50 | uid: "{{.UID}}" 51 | gid: "{{.GID}}" 52 | gecos: CIAO Demo User 53 | lock-passwd: true 54 | shell: /bin/bash 55 | sudo: ALL=(ALL) NOPASSWD:ALL 56 | ssh-authorized-keys: 57 | - {{.PublicKey}} 58 | ... 59 | -------------------------------------------------------------------------------- /client/deps.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | package client 18 | 19 | import "github.com/intel/ccloudvm/osprepare" 20 | 21 | var ccloudvmClearDeps = []osprepare.PackageRequirement{ 22 | {BinaryName: "/usr/bin/unxz", PackageName: "os-core-update"}, 23 | {BinaryName: "/usr/bin/qemu-system-x86_64", PackageName: "cloud-control"}, 24 | {BinaryName: "/usr/bin/xorriso", PackageName: "cloud-control"}, 25 | {BinaryName: "/usr/bin/ssh", PackageName: "openssh-server"}, 26 | {BinaryName: "/usr/bin/ssh-keygen", PackageName: "openssh-server"}, 27 | } 28 | 29 | var ccloudvmFedoraDeps = []osprepare.PackageRequirement{ 30 | {BinaryName: "/usr/bin/unxz", PackageName: "xz"}, 31 | {BinaryName: "/usr/bin/qemu-system-x86_64", PackageName: "qemu-system-x86"}, 32 | {BinaryName: "/usr/bin/qemu-img", PackageName: "qemu-img"}, 33 | {BinaryName: "/usr/bin/xorriso", PackageName: "xorriso"}, 34 | {BinaryName: "/usr/bin/ssh", PackageName: "openssh-clients"}, 35 | {BinaryName: "/usr/bin/ssh-keygen", PackageName: "openssh-clients"}, 36 | } 37 | 38 | var ccloudvmUbuntuDeps = []osprepare.PackageRequirement{ 39 | {BinaryName: "/usr/bin/unxz", PackageName: "xz-utils"}, 40 | {BinaryName: "/usr/bin/qemu-system-x86_64", PackageName: "qemu-system-x86"}, 41 | {BinaryName: "/usr/bin/qemu-img", PackageName: "qemu-utils"}, 42 | {BinaryName: "/usr/bin/xorriso", PackageName: "xorriso"}, 43 | {BinaryName: "/usr/bin/ssh", PackageName: "openssh-client"}, 44 | {BinaryName: "/usr/bin/ssh-keygen", PackageName: "openssh-client"}, 45 | } 46 | 47 | var ccloudvmArchDeps = []osprepare.PackageRequirement{ 48 | {BinaryName: "/usr/bin/xz", PackageName: "core/xz"}, 49 | {BinaryName: "/usr/bin/qemu-system-x86_64", PackageName: "extra/qemu"}, 50 | {BinaryName: "/usr/bin/qemu-img", PackageName: "extra/qemu"}, 51 | {BinaryName: "/usr/bin/xorriso", PackageName: "extra/libisoburn"}, 52 | {BinaryName: "/usr/bin/ssh", PackageName: "core/openssh"}, 53 | {BinaryName: "/usr/bin/ssh-keygen", PackageName: "core/openssh"}, 54 | } 55 | 56 | var ccloudvmDeps = map[string][]osprepare.PackageRequirement{ 57 | "clearlinux": ccloudvmClearDeps, 58 | "fedora": ccloudvmFedoraDeps, 59 | "ubuntu": ccloudvmUbuntuDeps, 60 | "arch": ccloudvmArchDeps, 61 | } 62 | -------------------------------------------------------------------------------- /cmd/connect.go: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2018 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | package cmd 18 | 19 | import ( 20 | "github.com/intel/ccloudvm/client" 21 | "github.com/spf13/cobra" 22 | ) 23 | 24 | var connectCmd = &cobra.Command{ 25 | Use: "connect", 26 | Short: "Connects to a VM via SSH", 27 | RunE: func(cmd *cobra.Command, args []string) error { 28 | ctx, cancelFunc := getSignalContext() 29 | defer cancelFunc() 30 | 31 | var instanceName string 32 | if len(args) > 0 { 33 | instanceName = args[0] 34 | } 35 | 36 | return client.Connect(ctx, instanceName) 37 | }, 38 | } 39 | 40 | func init() { 41 | rootCmd.AddCommand(connectCmd) 42 | } 43 | -------------------------------------------------------------------------------- /cmd/copy.go: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2018 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | package cmd 18 | 19 | import ( 20 | "github.com/intel/ccloudvm/client" 21 | "github.com/spf13/cobra" 22 | ) 23 | 24 | var recurse bool 25 | var host bool 26 | 27 | var copyCmd = &cobra.Command{ 28 | Use: "copy", 29 | Short: "Copy files between the host and the guest using scp", 30 | Args: cobra.MinimumNArgs(2), 31 | RunE: func(cmd *cobra.Command, args []string) error { 32 | ctx, cancelFunc := getSignalContext() 33 | defer cancelFunc() 34 | 35 | var instanceName string 36 | if len(args) >= 3 { 37 | instanceName = args[0] 38 | args = args[1:] 39 | } 40 | 41 | return client.Copy(ctx, instanceName, recurse, host, args[0], args[1]) 42 | }, 43 | } 44 | 45 | func init() { 46 | rootCmd.AddCommand(copyCmd) 47 | 48 | copyCmd.Flags().BoolVarP(&recurse, "recurse", "r", false, "Recursively copy contents of a directory") 49 | copyCmd.Flags().BoolVarP(&host, "to-host", "t", false, "Copy files from guest to host") 50 | } 51 | -------------------------------------------------------------------------------- /cmd/create.go: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2018 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | package cmd 18 | 19 | import ( 20 | "flag" 21 | "net" 22 | 23 | "github.com/intel/ccloudvm/client" 24 | "github.com/intel/ccloudvm/types" 25 | "github.com/pkg/errors" 26 | "github.com/spf13/cobra" 27 | ) 28 | 29 | type ipAddr net.IP 30 | 31 | func (ip *ipAddr) String() string { 32 | return (*net.IP)(ip).String() 33 | } 34 | 35 | func (ip *ipAddr) Type() string { 36 | return "string" 37 | } 38 | 39 | func (ip *ipAddr) Set(value string) error { 40 | addr := net.ParseIP(value) 41 | if len(addr) == 0 { 42 | return errors.Errorf("Invalid IP address [%s] specified", value) 43 | } 44 | addr = addr.To4() 45 | if len(addr) == 0 { 46 | return errors.Errorf("[%s] is not an IP4V address", value) 47 | } 48 | *ip = ipAddr(addr) 49 | return nil 50 | } 51 | 52 | var instanceName string 53 | var createSpec types.VMSpec 54 | var createMOptsSpec multiOptions 55 | var createDebug bool 56 | var createPackageUpgrade bool 57 | var createHostIP ipAddr 58 | 59 | var createCmd = &cobra.Command{ 60 | Use: "create", 61 | Short: "Creates a new VM", 62 | Args: cobra.ExactArgs(1), 63 | RunE: func(cmd *cobra.Command, args []string) error { 64 | ctx, cancelFunc := getSignalContext() 65 | defer cancelFunc() 66 | 67 | mergeVMOptions(&createSpec, &createMOptsSpec) 68 | createSpec.HostIP = net.IP(createHostIP) 69 | return client.Create(ctx, instanceName, args[0], createDebug, createPackageUpgrade, &createSpec) 70 | }, 71 | } 72 | 73 | func init() { 74 | rootCmd.AddCommand(createCmd) 75 | 76 | var flags flag.FlagSet 77 | vmFlags(&flags, &createSpec, &createMOptsSpec) 78 | flags.IntVar(&createSpec.DiskGiB, "disk", createSpec.DiskGiB, "Gibibytes of disk space allocated to Rootfs") 79 | 80 | createCmd.Flags().AddGoFlagSet(&flags) 81 | createCmd.Flags().StringVar(&instanceName, "name", "", "Name of new instance") 82 | createCmd.Flags().BoolVar(&createDebug, "debug", false, "Enable debugging mode") 83 | createCmd.Flags().BoolVar(&createPackageUpgrade, "package-upgrade", false, "Hint as to whether to upgrade packages on creation") 84 | createCmd.Flags().Var(&createHostIP, "hostip", "Host IP address on which instance services will be exposed") 85 | } 86 | -------------------------------------------------------------------------------- /cmd/delete.go: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2018 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | package cmd 18 | 19 | import ( 20 | "github.com/intel/ccloudvm/client" 21 | "github.com/spf13/cobra" 22 | ) 23 | 24 | var deleteCmd = &cobra.Command{ 25 | Use: "delete", 26 | Short: "Stops and deletes a VM", 27 | RunE: func(cmd *cobra.Command, args []string) error { 28 | ctx, cancelFunc := getSignalContext() 29 | defer cancelFunc() 30 | 31 | var instanceName string 32 | if len(args) > 0 { 33 | instanceName = args[0] 34 | } 35 | 36 | return client.Delete(ctx, instanceName) 37 | }, 38 | } 39 | 40 | func init() { 41 | rootCmd.AddCommand(deleteCmd) 42 | } 43 | -------------------------------------------------------------------------------- /cmd/instances.go: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2018 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | package cmd 18 | 19 | import ( 20 | "github.com/intel/ccloudvm/client" 21 | "github.com/spf13/cobra" 22 | ) 23 | 24 | var instanceCmd = &cobra.Command{ 25 | Use: "instances", 26 | Short: "Lists the current instances", 27 | RunE: func(cmd *cobra.Command, args []string) error { 28 | ctx, cancelFunc := getSignalContext() 29 | defer cancelFunc() 30 | 31 | return client.Instances(ctx) 32 | }, 33 | } 34 | 35 | func init() { 36 | rootCmd.AddCommand(instanceCmd) 37 | } 38 | -------------------------------------------------------------------------------- /cmd/quit.go: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2018 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | package cmd 18 | 19 | import ( 20 | "github.com/intel/ccloudvm/client" 21 | "github.com/spf13/cobra" 22 | ) 23 | 24 | var quitCmd = &cobra.Command{ 25 | Use: "quit", 26 | Short: "Forceably quits a running VM", 27 | RunE: func(cmd *cobra.Command, args []string) error { 28 | ctx, cancelFunc := getSignalContext() 29 | defer cancelFunc() 30 | 31 | var instanceName string 32 | if len(args) > 0 { 33 | instanceName = args[0] 34 | } 35 | 36 | return client.Quit(ctx, instanceName) 37 | }, 38 | } 39 | 40 | func init() { 41 | rootCmd.AddCommand(quitCmd) 42 | } 43 | -------------------------------------------------------------------------------- /cmd/root.go: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2018 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | package cmd 18 | 19 | import ( 20 | "context" 21 | "os" 22 | "os/signal" 23 | "syscall" 24 | 25 | "github.com/spf13/cobra" 26 | ) 27 | 28 | var rootCmd = &cobra.Command{ 29 | Use: "ccloudvm", 30 | Short: "Configurable Cloud VM (ccloudvm) allows the creation and management of VMs from cloud-init files", 31 | SilenceUsage: true, 32 | } 33 | 34 | // Execute is the entry into the cmd package from the main package. 35 | func Execute() { 36 | if err := rootCmd.Execute(); err != nil { 37 | os.Exit(1) 38 | } 39 | } 40 | 41 | func getSignalContext() (context.Context, context.CancelFunc) { 42 | ctx, cancelFunc := context.WithCancel(context.Background()) 43 | 44 | sigCh := make(chan os.Signal, 1) 45 | go func() { 46 | for { 47 | select { 48 | case <-sigCh: 49 | cancelFunc() 50 | case <-ctx.Done(): 51 | break 52 | } 53 | } 54 | }() 55 | signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM) 56 | return ctx, cancelFunc 57 | } 58 | -------------------------------------------------------------------------------- /cmd/run.go: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2018 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | package cmd 18 | 19 | import ( 20 | "strings" 21 | 22 | "github.com/intel/ccloudvm/client" 23 | "github.com/spf13/cobra" 24 | ) 25 | 26 | var runCmd = &cobra.Command{ 27 | Use: "run", 28 | Short: "Run a command in the VM via SSH", 29 | Args: cobra.MinimumNArgs(2), 30 | RunE: func(cmd *cobra.Command, args []string) error { 31 | ctx, cancelFunc := getSignalContext() 32 | defer cancelFunc() 33 | 34 | command := strings.Join(args[1:], " ") 35 | return client.Run(ctx, args[0], command) 36 | }, 37 | } 38 | 39 | func init() { 40 | rootCmd.AddCommand(runCmd) 41 | } 42 | -------------------------------------------------------------------------------- /cmd/setup.go: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2018 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | package cmd 18 | 19 | import ( 20 | "github.com/intel/ccloudvm/client" 21 | "github.com/spf13/cobra" 22 | ) 23 | 24 | var setupCmd = &cobra.Command{ 25 | Use: "setup", 26 | Short: "Installs dependencies and sets ccloudvm up for use", 27 | Args: cobra.NoArgs, 28 | RunE: func(cmd *cobra.Command, args []string) error { 29 | ctx, cancelFunc := getSignalContext() 30 | defer cancelFunc() 31 | 32 | return client.Setup(ctx) 33 | }, 34 | } 35 | 36 | func init() { 37 | rootCmd.AddCommand(setupCmd) 38 | } 39 | -------------------------------------------------------------------------------- /cmd/start.go: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2018 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | package cmd 18 | 19 | import ( 20 | "flag" 21 | 22 | "github.com/intel/ccloudvm/client" 23 | "github.com/intel/ccloudvm/types" 24 | "github.com/spf13/cobra" 25 | ) 26 | 27 | var startSpec types.VMSpec 28 | var startMOptsSpec multiOptions 29 | 30 | var startCmd = &cobra.Command{ 31 | Use: "start", 32 | Short: "Boots a stopped VM", 33 | RunE: func(cmd *cobra.Command, args []string) error { 34 | ctx, cancelFunc := getSignalContext() 35 | defer cancelFunc() 36 | 37 | var instanceName string 38 | if len(args) > 0 { 39 | instanceName = args[0] 40 | } 41 | 42 | mergeVMOptions(&startSpec, &startMOptsSpec) 43 | return client.Start(ctx, instanceName, &startSpec) 44 | }, 45 | } 46 | 47 | func init() { 48 | rootCmd.AddCommand(startCmd) 49 | 50 | var flags flag.FlagSet 51 | vmFlags(&flags, &startSpec, &startMOptsSpec) 52 | 53 | startCmd.Flags().AddGoFlagSet(&flags) 54 | } 55 | -------------------------------------------------------------------------------- /cmd/status.go: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2018 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | package cmd 18 | 19 | import ( 20 | "github.com/intel/ccloudvm/client" 21 | "github.com/spf13/cobra" 22 | ) 23 | 24 | var statusCmd = &cobra.Command{ 25 | Use: "status", 26 | Short: "Prints status information about a VM", 27 | RunE: func(cmd *cobra.Command, args []string) error { 28 | ctx, cancelFunc := getSignalContext() 29 | defer cancelFunc() 30 | 31 | var instanceName string 32 | if len(args) > 0 { 33 | instanceName = args[0] 34 | } 35 | 36 | return client.Status(ctx, instanceName) 37 | }, 38 | } 39 | 40 | func init() { 41 | rootCmd.AddCommand(statusCmd) 42 | } 43 | -------------------------------------------------------------------------------- /cmd/stop.go: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2018 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | package cmd 18 | 19 | import ( 20 | "github.com/intel/ccloudvm/client" 21 | "github.com/spf13/cobra" 22 | ) 23 | 24 | var stopCmd = &cobra.Command{ 25 | Use: "stop", 26 | Short: "Cleanly powers down a running VM", 27 | RunE: func(cmd *cobra.Command, args []string) error { 28 | ctx, cancelFunc := getSignalContext() 29 | defer cancelFunc() 30 | 31 | var instanceName string 32 | if len(args) > 0 { 33 | instanceName = args[0] 34 | } 35 | 36 | return client.Stop(ctx, instanceName) 37 | }, 38 | } 39 | 40 | func init() { 41 | rootCmd.AddCommand(stopCmd) 42 | } 43 | -------------------------------------------------------------------------------- /cmd/teardown.go: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2018 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | package cmd 18 | 19 | import ( 20 | "github.com/intel/ccloudvm/client" 21 | "github.com/spf13/cobra" 22 | ) 23 | 24 | var teardownCmd = &cobra.Command{ 25 | Use: "teardown", 26 | Short: "Disables the ccloudvm service", 27 | Args: cobra.NoArgs, 28 | RunE: func(cmd *cobra.Command, args []string) error { 29 | ctx, cancelFunc := getSignalContext() 30 | defer cancelFunc() 31 | 32 | return client.Teardown(ctx) 33 | }, 34 | } 35 | 36 | func init() { 37 | rootCmd.AddCommand(teardownCmd) 38 | } 39 | -------------------------------------------------------------------------------- /cmd/vm.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2018 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | package cmd 18 | 19 | import ( 20 | "flag" 21 | "fmt" 22 | "os" 23 | "strconv" 24 | "strings" 25 | 26 | "github.com/intel/ccloudvm/types" 27 | "github.com/pkg/errors" 28 | ) 29 | 30 | type mounts []types.Mount 31 | type ports []types.PortMapping 32 | type drives []types.Drive 33 | 34 | type multiOptions struct { 35 | m mounts 36 | p ports 37 | d drives 38 | } 39 | 40 | func (m *mounts) String() string { 41 | return fmt.Sprint(*m) 42 | } 43 | 44 | func (m *mounts) Set(value string) error { 45 | components := strings.Split(value, ",") 46 | if len(components) != 3 { 47 | return fmt.Errorf("--mount parameter should be of format tag,security_model,path") 48 | } 49 | *m = append(*m, types.Mount{ 50 | Tag: components[0], 51 | SecurityModel: components[1], 52 | Path: components[2], 53 | }) 54 | return nil 55 | } 56 | 57 | func (p *ports) String() string { 58 | return fmt.Sprint(*p) 59 | } 60 | 61 | func (p *ports) Set(value string) error { 62 | components := strings.Split(value, "-") 63 | if len(components) != 2 { 64 | return fmt.Errorf("--port parameter should be of format host-guest") 65 | } 66 | host, err := strconv.Atoi(components[0]) 67 | if err != nil { 68 | return fmt.Errorf("host port must be a number") 69 | } 70 | guest, err := strconv.Atoi(components[1]) 71 | if err != nil { 72 | return fmt.Errorf("guest port must be a number") 73 | } 74 | *p = append(*p, types.PortMapping{ 75 | Host: host, 76 | Guest: guest, 77 | }) 78 | return nil 79 | } 80 | 81 | func (d *drives) String() string { 82 | return fmt.Sprint(*d) 83 | } 84 | 85 | func (d *drives) Set(value string) error { 86 | components := strings.Split(value, ",") 87 | if len(components) < 2 { 88 | return fmt.Errorf("--drive parameter should be of format path,format[,option]*") 89 | } 90 | _, err := os.Stat(components[0]) 91 | if err != nil { 92 | return errors.Wrapf(err, "Unable to access %s", components[1]) 93 | } 94 | *d = append(*d, types.Drive{ 95 | Path: components[0], 96 | Format: components[1], 97 | Options: strings.Join(components[2:], ","), 98 | }) 99 | return nil 100 | } 101 | 102 | func mergeVMOptions(vmSpec *types.VMSpec, mOpts *multiOptions) { 103 | vmSpec.PortMappings = []types.PortMapping(mOpts.p) 104 | vmSpec.Drives = []types.Drive(mOpts.d) 105 | vmSpec.Mounts = []types.Mount(mOpts.m) 106 | } 107 | 108 | func vmFlags(fs *flag.FlagSet, customSpec *types.VMSpec, mOpts *multiOptions) { 109 | fs.IntVar(&customSpec.MemMiB, "mem", customSpec.MemMiB, "Mebibytes of RAM allocated to VM") 110 | fs.IntVar(&customSpec.CPUs, "cpus", customSpec.CPUs, "VCPUs assigned to VM") 111 | fs.Var(&mOpts.m, "mount", "directory to mount in guest VM via 9p. Format is tag,security_model,path") 112 | fs.Var(&mOpts.d, "drive", "Host accessible resource to appear as block device in guest VM. Format is path,format[,option]*") 113 | fs.Var(&mOpts.p, "port", "port mapping. Format is host_port-guest_port, e.g., -port 10022-22") 114 | fs.UintVar(&customSpec.Qemuport, "qemuport", customSpec.Qemuport, "Port to follow qemu logs of the guest machine, eg., --qemuport=9999") 115 | } 116 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/intel/ccloudvm 2 | 3 | go 1.16 4 | 5 | require ( 6 | github.com/ciao-project/ciao v0.0.0-20180108144400-194264adc583 7 | github.com/coreos/go-systemd v0.0.0-20170731111925-d21964639418 8 | github.com/inconshreveable/mousetrap v1.0.0 // indirect 9 | github.com/intel/govmm v0.0.0-20180104200030-22c99930c2f6 10 | github.com/mattn/goveralls v0.0.8 // indirect 11 | github.com/pkg/errors v0.8.0 12 | github.com/pmezard/go-difflib v1.0.0 13 | github.com/spf13/cobra v0.0.2-0.20171231101556-b95ab734e27d 14 | github.com/spf13/pflag v1.0.0 // indirect 15 | golang.org/x/net v0.0.0-20200226121028-0de0cce0169b 16 | golang.org/x/text v0.3.1-0.20171227012246-e19ae1496984 // indirect 17 | gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect 18 | gopkg.in/yaml.v2 v2.0.0-20180108131554-1244d3ce02e3 19 | ) 20 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2018 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | package main 18 | 19 | import "github.com/intel/ccloudvm/cmd" 20 | 21 | func main() { 22 | cmd.Execute() 23 | } 24 | -------------------------------------------------------------------------------- /osprepare/distro_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © 2016 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | package osprepare 18 | 19 | import ( 20 | "context" 21 | "testing" 22 | ) 23 | 24 | func TestGetDistro(t *testing.T) { 25 | if pathExists("/usr/share/clear/bundles") == false { 26 | t.Skip("Unsupported test distro") 27 | } 28 | d := getDistro() 29 | if d == nil { 30 | t.Fatal("Cannot get known distro object") 31 | } 32 | if d.getID() == "" { 33 | t.Fatal("Invalid ID for distro") 34 | } 35 | } 36 | 37 | type ospTestLogger struct{} 38 | 39 | func (l ospTestLogger) V(level int32) bool { 40 | return true 41 | } 42 | 43 | var info []string 44 | var warning []string 45 | var error []string 46 | 47 | func (l ospTestLogger) Infof(format string, v ...interface{}) { 48 | info = append(info, format) 49 | } 50 | 51 | func (l ospTestLogger) Warningf(format string, v ...interface{}) { 52 | warning = append(warning, format) 53 | } 54 | 55 | func (l ospTestLogger) Errorf(format string, v ...interface{}) { 56 | error = append(error, format) 57 | } 58 | 59 | func TestSudoFormatCommandLogging(t *testing.T) { 60 | info = []string{} 61 | if getDistro() == nil { 62 | t.Skip("Unsupported test distro") 63 | } 64 | l := ospTestLogger{} 65 | 66 | sudoFormatCommand(context.Background(), "echo -n foo\nbar", []string{}, l) 67 | 68 | if info[0] != "foo" && info[1] != "bar%!(EXTRA string=)" { 69 | t.Fatal("Incorrect log message received") 70 | } 71 | } 72 | 73 | func TestSudoFormatCommandBadCommandReturn(t *testing.T) { 74 | error = []string{} 75 | if getDistro() == nil { 76 | t.Skip("Unsupported test distro") 77 | } 78 | l := ospTestLogger{} 79 | 80 | if sudoFormatCommand(context.Background(), "false", []string{}, l) { 81 | t.Fatal("Error return code not detected") 82 | } 83 | if len(error) != 1 && error[0] != "Error running command: %s" { 84 | t.Fatal("Incorrect log message received") 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /osprepare/doc.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | /* 18 | 19 | Package osprepare is the Operating System Preparation facility of Ciao, 20 | enabling very simple automated configuration of dependencies between 21 | various Linux distributions in a sane fashion. 22 | 23 | 24 | Expressing Dependencies 25 | 26 | InstallDeps is used to ensure the presence of mandatory dependencies during 27 | the early initialization of Ciao components, and install them via the native 28 | package deployment system when they are absent. 29 | InstallDeps should be invoked with a PackageRequirements map, which is simply 30 | a mapping of operating system IDs to path/package pairs. 31 | The function may not yet support all systems, so it is expected that it should 32 | perform its function without any outside interference, and should never cause 33 | failures or require checking of returns. 34 | 35 | The PackageRequirements map (deps.go) 36 | 37 | Below is an example of a valid PackageRequirements structure. 38 | 39 | var deps = osprepare.PackageRequirements{ 40 | "ubuntu": { 41 | {"/usr/bin/docker", "docker"}, 42 | }, 43 | "clearlinux": { 44 | {"/usr/bin/docker", "containers-basic"}, 45 | }, 46 | } 47 | 48 | As we can see, full paths to the expected locations on the filesystem are given 49 | for each OS, and the name of the native package or bundle to install should those 50 | files be missing. That is to say, if /usr/bin/docker is missing, on a system that 51 | has been identified as Ubuntu, then the 'docker' package would be installed. 52 | 53 | The dependencies for each component should be placed into a `deps.go` file, which 54 | then facilitates easier maintenance and discoverability of the dependencies for 55 | every component. 56 | 57 | Verified lack of dependencies 58 | 59 | Note that it is also valid to state you have *no* dependencies at all, and that 60 | you have verified that each distro requires no additional dependencies to be 61 | installed during startup. Just pass an empty pair to the distro ID: 62 | 63 | var schedDeps = osprepare.PackageRequirements{ 64 | "clearlinux": { 65 | {"", ""}, 66 | }, 67 | "fedora": { 68 | {"", ""}, 69 | }, 70 | "ubuntu": { 71 | {"", ""}, 72 | }, 73 | } 74 | 75 | Operating System Identification 76 | 77 | Operating Systems are identified via their `os-release` file, a standardized 78 | mechanism for identifying Linux distributions. Currently, detection is performed 79 | by comparison the lower-case value of the `ID` field to our known implementations, 80 | which are: 81 | 82 | * clearlinux 83 | * ubuntu 84 | * fedora 85 | 86 | */ 87 | package osprepare 88 | -------------------------------------------------------------------------------- /osprepare/os_release.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © 2016 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | package osprepare 18 | 19 | import ( 20 | "bufio" 21 | "os" 22 | "strings" 23 | ) 24 | 25 | type osRelease struct { 26 | Name string 27 | ID string 28 | PrettyName string 29 | Version string 30 | VersionID string 31 | mapping map[string]string 32 | } 33 | 34 | // Parse the given path and attempt to return a valid 35 | // OsRelease for it 36 | func parseReleaseFile(path string) *osRelease { 37 | fi, err := os.Open(path) 38 | var r osRelease 39 | r.mapping = make(map[string]string) 40 | 41 | if err != nil { 42 | return nil 43 | } 44 | defer fi.Close() 45 | sc := bufio.NewScanner(fi) 46 | for sc.Scan() { 47 | line := sc.Text() 48 | 49 | spl := strings.Split(line, "=") 50 | if len(spl) < 2 { 51 | continue 52 | } 53 | key := strings.ToLower(strings.TrimSpace(spl[0])) 54 | value := strings.TrimSpace(strings.Join(spl[1:], "=")) 55 | 56 | value = strings.Replace(value, "\"", "", -1) 57 | value = strings.Replace(value, "'", "", -1) 58 | 59 | if key == "name" { 60 | r.Name = value 61 | } else if key == "id" { 62 | r.ID = value 63 | } else if key == "pretty_name" { 64 | r.PrettyName = value 65 | } else if key == "version" { 66 | r.Version = value 67 | } else if key == "version_id" { 68 | r.VersionID = value 69 | } 70 | 71 | // Store it for use by Distro 72 | r.mapping[key] = value 73 | } 74 | return &r 75 | } 76 | 77 | // Try all known paths to get the right OsRelease instance 78 | func getOSRelease() *osRelease { 79 | paths := []string{ 80 | "/etc/os-release", 81 | "/usr/lib/os-release", 82 | "/usr/lib64/os-release", 83 | } 84 | 85 | for _, item := range paths { 86 | if r := parseReleaseFile(item); r != nil { 87 | return r 88 | } 89 | } 90 | return nil 91 | } 92 | 93 | func (o *osRelease) GetValue(key string) string { 94 | if val, succ := o.mapping[strings.ToLower(key)]; succ { 95 | return val 96 | } 97 | return "" 98 | } 99 | -------------------------------------------------------------------------------- /osprepare/os_release_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © 2016 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | package osprepare 18 | 19 | import ( 20 | "strings" 21 | "testing" 22 | ) 23 | 24 | const ( 25 | nonExistentFile = "/nonexistentpath/this/file/doesnot/exists" 26 | ) 27 | 28 | func TestGetOsRelease(t *testing.T) { 29 | d := getDistro() 30 | if d == nil { 31 | t.Skip("Unknown distro, cannot test") 32 | } 33 | r := getOSRelease() 34 | if r == nil { 35 | t.Fatal("Could not get os-release file for known distro") 36 | } 37 | if d.getID() == "clearlinux" && !strings.Contains(r.ID, "clear") { 38 | t.Fatal("Invalid os-release for clearlinux") 39 | } else if d.getID() == "ubuntu" && !strings.Contains(r.ID, "ubuntu") { 40 | t.Fatal("Invalid os-release for Ubuntu") 41 | } else if d.getID() == "fedora" && !strings.Contains(r.ID, "fedora") { 42 | t.Fatal("Invalid os-release for Fedora") 43 | } 44 | } 45 | 46 | func TestParseReleaseFileNonExistent(t *testing.T) { 47 | if res := parseReleaseFile(nonExistentFile); res != nil { 48 | t.Fatalf("Expected nil, got %v\n", res) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /scripts/ccloudvm_bashcomplete: -------------------------------------------------------------------------------- 1 | _ccloudvm() 2 | { 3 | local cur prev opts 4 | COMPREPLY=() 5 | cur="${COMP_WORDS[COMP_CWORD]}" 6 | prev="${COMP_WORDS[COMP_CWORD-1]}" 7 | opts="connect copy create delete help instances quit run setup start status stop teardown" 8 | 9 | case "${prev}" in 10 | connect|delete|quit|run|start|status|stop) 11 | local running=$(for x in `ccloudvm instances | grep -v ^Name | awk '{print $1}'`;do echo $x; done) 12 | COMPREPLY=($(compgen -W "${running}" -- ${cur})) 13 | return 0 14 | ;; 15 | *) 16 | ;; 17 | esac 18 | 19 | COMPREPLY=($(compgen -W "${opts}" -- ${cur})) 20 | return 0 21 | 22 | } 23 | complete -F _ccloudvm ccloudvm 24 | -------------------------------------------------------------------------------- /types/api.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2018 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | package types 18 | 19 | // CreateArgs contains all the information necessary to create a new 20 | // ccloudvm instance. 21 | type CreateArgs struct { 22 | Name string 23 | WorkloadName string 24 | Debug bool 25 | Update bool 26 | CustomSpec VMSpec 27 | HTTPProxy string 28 | HTTPSProxy string 29 | NoProxy string 30 | GoPath string 31 | } 32 | 33 | // CreateResult contains information about the status of an instance 34 | // creation request. It has two fields. Finished, if true, indicates 35 | // that the creation request has finished and Line containing a lines 36 | // of output. 37 | type CreateResult struct { 38 | Name string 39 | Finished bool 40 | Line string 41 | } 42 | 43 | // StartArgs contain all the information needed to start a stopped 44 | // instance. 45 | type StartArgs struct { 46 | Name string 47 | VMSpec VMSpec 48 | } 49 | 50 | // SSHDetails contains SSH connection information for an instance 51 | type SSHDetails struct { 52 | KeyPath string 53 | Port int 54 | } 55 | 56 | // InstanceDetails contains information about an instance 57 | type InstanceDetails struct { 58 | Name string 59 | SSH SSHDetails 60 | Workload string 61 | VMSpec VMSpec 62 | } 63 | -------------------------------------------------------------------------------- /vendor/github.com/ciao-project/ciao/clogger/logger.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2016 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // 16 | 17 | package clogger 18 | 19 | // CiaoLog is a logging interface to be used by other packages to log various 20 | // interesting pieces of information. Rather than introduce a dependency 21 | // on a given logging package, ciao-logger presents this interface that allows 22 | // clients to provide their own logging type. 23 | type CiaoLog interface { 24 | // V returns true if the given argument is less than or equal 25 | // to the implementation's defined verbosity level. 26 | V(int32) bool 27 | 28 | // Infof writes informational output to the log. A newline will be 29 | // added to the output if one is not provided. 30 | Infof(string, ...interface{}) 31 | 32 | // Warningf writes warning output to the log. A newline will be 33 | // added to the output if one is not provided. 34 | Warningf(string, ...interface{}) 35 | 36 | // Errorf writes error output to the log. A newline will be 37 | // added to the output if one is not provided. 38 | Errorf(string, ...interface{}) 39 | } 40 | 41 | // CiaoNullLogger is a do nothing implementation of CiaoLog 42 | type CiaoNullLogger struct{} 43 | 44 | // V no message is verbose 45 | func (l CiaoNullLogger) V(level int32) bool { 46 | return false 47 | } 48 | 49 | // Infof no logging done 50 | func (l CiaoNullLogger) Infof(format string, v ...interface{}) { 51 | } 52 | 53 | // Warningf no logging done 54 | func (l CiaoNullLogger) Warningf(format string, v ...interface{}) { 55 | } 56 | 57 | // Errorf no logging done 58 | func (l CiaoNullLogger) Errorf(format string, v ...interface{}) { 59 | } 60 | -------------------------------------------------------------------------------- /vendor/github.com/coreos/go-systemd/activation/files.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 CoreOS, Inc. 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 activation implements primitives for systemd socket activation. 16 | package activation 17 | 18 | import ( 19 | "os" 20 | "strconv" 21 | "syscall" 22 | ) 23 | 24 | // based on: https://gist.github.com/alberts/4640792 25 | const ( 26 | listenFdsStart = 3 27 | ) 28 | 29 | func Files(unsetEnv bool) []*os.File { 30 | if unsetEnv { 31 | defer os.Unsetenv("LISTEN_PID") 32 | defer os.Unsetenv("LISTEN_FDS") 33 | } 34 | 35 | pid, err := strconv.Atoi(os.Getenv("LISTEN_PID")) 36 | if err != nil || pid != os.Getpid() { 37 | return nil 38 | } 39 | 40 | nfds, err := strconv.Atoi(os.Getenv("LISTEN_FDS")) 41 | if err != nil || nfds == 0 { 42 | return nil 43 | } 44 | 45 | files := make([]*os.File, 0, nfds) 46 | for fd := listenFdsStart; fd < listenFdsStart+nfds; fd++ { 47 | syscall.CloseOnExec(fd) 48 | files = append(files, os.NewFile(uintptr(fd), "LISTEN_FD_"+strconv.Itoa(fd))) 49 | } 50 | 51 | return files 52 | } 53 | -------------------------------------------------------------------------------- /vendor/github.com/coreos/go-systemd/activation/listeners.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 CoreOS, Inc. 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 activation 16 | 17 | import ( 18 | "crypto/tls" 19 | "net" 20 | ) 21 | 22 | // Listeners returns a slice containing a net.Listener for each matching socket type 23 | // passed to this process. 24 | // 25 | // The order of the file descriptors is preserved in the returned slice. 26 | // Nil values are used to fill any gaps. For example if systemd were to return file descriptors 27 | // corresponding with "udp, tcp, tcp", then the slice would contain {nil, net.Listener, net.Listener} 28 | func Listeners(unsetEnv bool) ([]net.Listener, error) { 29 | files := Files(unsetEnv) 30 | listeners := make([]net.Listener, len(files)) 31 | 32 | for i, f := range files { 33 | if pc, err := net.FileListener(f); err == nil { 34 | listeners[i] = pc 35 | } 36 | } 37 | return listeners, nil 38 | } 39 | 40 | // TLSListeners returns a slice containing a net.listener for each matching TCP socket type 41 | // passed to this process. 42 | // It uses default Listeners func and forces TCP sockets handlers to use TLS based on tlsConfig. 43 | func TLSListeners(unsetEnv bool, tlsConfig *tls.Config) ([]net.Listener, error) { 44 | listeners, err := Listeners(unsetEnv) 45 | 46 | if listeners == nil || err != nil { 47 | return nil, err 48 | } 49 | 50 | if tlsConfig != nil && err == nil { 51 | for i, l := range listeners { 52 | // Activate TLS only for TCP sockets 53 | if l.Addr().Network() == "tcp" { 54 | listeners[i] = tls.NewListener(l, tlsConfig) 55 | } 56 | } 57 | } 58 | 59 | return listeners, err 60 | } 61 | -------------------------------------------------------------------------------- /vendor/github.com/coreos/go-systemd/activation/packetconns.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 CoreOS, Inc. 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 activation 16 | 17 | import ( 18 | "net" 19 | ) 20 | 21 | // PacketConns returns a slice containing a net.PacketConn for each matching socket type 22 | // passed to this process. 23 | // 24 | // The order of the file descriptors is preserved in the returned slice. 25 | // Nil values are used to fill any gaps. For example if systemd were to return file descriptors 26 | // corresponding with "udp, tcp, udp", then the slice would contain {net.PacketConn, nil, net.PacketConn} 27 | func PacketConns(unsetEnv bool) ([]net.PacketConn, error) { 28 | files := Files(unsetEnv) 29 | conns := make([]net.PacketConn, len(files)) 30 | 31 | for i, f := range files { 32 | if pc, err := net.FilePacketConn(f); err == nil { 33 | conns[i] = pc 34 | } 35 | } 36 | return conns, nil 37 | } 38 | -------------------------------------------------------------------------------- /vendor/github.com/inconshreveable/mousetrap/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2014 Alan Shreve 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 | -------------------------------------------------------------------------------- /vendor/github.com/inconshreveable/mousetrap/README.md: -------------------------------------------------------------------------------- 1 | # mousetrap 2 | 3 | mousetrap is a tiny library that answers a single question. 4 | 5 | On a Windows machine, was the process invoked by someone double clicking on 6 | the executable file while browsing in explorer? 7 | 8 | ### Motivation 9 | 10 | Windows developers unfamiliar with command line tools will often "double-click" 11 | the executable for a tool. Because most CLI tools print the help and then exit 12 | when invoked without arguments, this is often very frustrating for those users. 13 | 14 | mousetrap provides a way to detect these invocations so that you can provide 15 | more helpful behavior and instructions on how to run the CLI tool. To see what 16 | this looks like, both from an organizational and a technical perspective, see 17 | https://inconshreveable.com/09-09-2014/sweat-the-small-stuff/ 18 | 19 | ### The interface 20 | 21 | The library exposes a single interface: 22 | 23 | func StartedByExplorer() (bool) 24 | -------------------------------------------------------------------------------- /vendor/github.com/inconshreveable/mousetrap/trap_others.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package mousetrap 4 | 5 | // StartedByExplorer returns true if the program was invoked by the user 6 | // double-clicking on the executable from explorer.exe 7 | // 8 | // It is conservative and returns false if any of the internal calls fail. 9 | // It does not guarantee that the program was run from a terminal. It only can tell you 10 | // whether it was launched from explorer.exe 11 | // 12 | // On non-Windows platforms, it always returns false. 13 | func StartedByExplorer() bool { 14 | return false 15 | } 16 | -------------------------------------------------------------------------------- /vendor/github.com/inconshreveable/mousetrap/trap_windows.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | // +build !go1.4 3 | 4 | package mousetrap 5 | 6 | import ( 7 | "fmt" 8 | "os" 9 | "syscall" 10 | "unsafe" 11 | ) 12 | 13 | const ( 14 | // defined by the Win32 API 15 | th32cs_snapprocess uintptr = 0x2 16 | ) 17 | 18 | var ( 19 | kernel = syscall.MustLoadDLL("kernel32.dll") 20 | CreateToolhelp32Snapshot = kernel.MustFindProc("CreateToolhelp32Snapshot") 21 | Process32First = kernel.MustFindProc("Process32FirstW") 22 | Process32Next = kernel.MustFindProc("Process32NextW") 23 | ) 24 | 25 | // ProcessEntry32 structure defined by the Win32 API 26 | type processEntry32 struct { 27 | dwSize uint32 28 | cntUsage uint32 29 | th32ProcessID uint32 30 | th32DefaultHeapID int 31 | th32ModuleID uint32 32 | cntThreads uint32 33 | th32ParentProcessID uint32 34 | pcPriClassBase int32 35 | dwFlags uint32 36 | szExeFile [syscall.MAX_PATH]uint16 37 | } 38 | 39 | func getProcessEntry(pid int) (pe *processEntry32, err error) { 40 | snapshot, _, e1 := CreateToolhelp32Snapshot.Call(th32cs_snapprocess, uintptr(0)) 41 | if snapshot == uintptr(syscall.InvalidHandle) { 42 | err = fmt.Errorf("CreateToolhelp32Snapshot: %v", e1) 43 | return 44 | } 45 | defer syscall.CloseHandle(syscall.Handle(snapshot)) 46 | 47 | var processEntry processEntry32 48 | processEntry.dwSize = uint32(unsafe.Sizeof(processEntry)) 49 | ok, _, e1 := Process32First.Call(snapshot, uintptr(unsafe.Pointer(&processEntry))) 50 | if ok == 0 { 51 | err = fmt.Errorf("Process32First: %v", e1) 52 | return 53 | } 54 | 55 | for { 56 | if processEntry.th32ProcessID == uint32(pid) { 57 | pe = &processEntry 58 | return 59 | } 60 | 61 | ok, _, e1 = Process32Next.Call(snapshot, uintptr(unsafe.Pointer(&processEntry))) 62 | if ok == 0 { 63 | err = fmt.Errorf("Process32Next: %v", e1) 64 | return 65 | } 66 | } 67 | } 68 | 69 | func getppid() (pid int, err error) { 70 | pe, err := getProcessEntry(os.Getpid()) 71 | if err != nil { 72 | return 73 | } 74 | 75 | pid = int(pe.th32ParentProcessID) 76 | return 77 | } 78 | 79 | // StartedByExplorer returns true if the program was invoked by the user double-clicking 80 | // on the executable from explorer.exe 81 | // 82 | // It is conservative and returns false if any of the internal calls fail. 83 | // It does not guarantee that the program was run from a terminal. It only can tell you 84 | // whether it was launched from explorer.exe 85 | func StartedByExplorer() bool { 86 | ppid, err := getppid() 87 | if err != nil { 88 | return false 89 | } 90 | 91 | pe, err := getProcessEntry(ppid) 92 | if err != nil { 93 | return false 94 | } 95 | 96 | name := syscall.UTF16ToString(pe.szExeFile[:]) 97 | return name == "explorer.exe" 98 | } 99 | -------------------------------------------------------------------------------- /vendor/github.com/inconshreveable/mousetrap/trap_windows_1.4.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | // +build go1.4 3 | 4 | package mousetrap 5 | 6 | import ( 7 | "os" 8 | "syscall" 9 | "unsafe" 10 | ) 11 | 12 | func getProcessEntry(pid int) (*syscall.ProcessEntry32, error) { 13 | snapshot, err := syscall.CreateToolhelp32Snapshot(syscall.TH32CS_SNAPPROCESS, 0) 14 | if err != nil { 15 | return nil, err 16 | } 17 | defer syscall.CloseHandle(snapshot) 18 | var procEntry syscall.ProcessEntry32 19 | procEntry.Size = uint32(unsafe.Sizeof(procEntry)) 20 | if err = syscall.Process32First(snapshot, &procEntry); err != nil { 21 | return nil, err 22 | } 23 | for { 24 | if procEntry.ProcessID == uint32(pid) { 25 | return &procEntry, nil 26 | } 27 | err = syscall.Process32Next(snapshot, &procEntry) 28 | if err != nil { 29 | return nil, err 30 | } 31 | } 32 | } 33 | 34 | // StartedByExplorer returns true if the program was invoked by the user double-clicking 35 | // on the executable from explorer.exe 36 | // 37 | // It is conservative and returns false if any of the internal calls fail. 38 | // It does not guarantee that the program was run from a terminal. It only can tell you 39 | // whether it was launched from explorer.exe 40 | func StartedByExplorer() bool { 41 | pe, err := getProcessEntry(os.Getppid()) 42 | if err != nil { 43 | return false 44 | } 45 | return "explorer.exe" == syscall.UTF16ToString(pe.ExeFile[:]) 46 | } 47 | -------------------------------------------------------------------------------- /vendor/github.com/intel/govmm/qemu/image.go: -------------------------------------------------------------------------------- 1 | /* 2 | // Copyright (c) 2017 Intel Corporation 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | */ 16 | 17 | package qemu 18 | 19 | import ( 20 | "context" 21 | "fmt" 22 | "io/ioutil" 23 | "os" 24 | "os/exec" 25 | "path" 26 | "syscall" 27 | ) 28 | 29 | // CreateCloudInitISO creates a cloud-init ConfigDrive ISO image. This is 30 | // useful for configuring newly booted VMs. Before it can create the ISO 31 | // image it needs to create a file tree with the various files that will 32 | // make up the image. This directory is created under scratchDir and is 33 | // deleted when when the function returns, successfully or otherwise. ctx is 34 | // a context that can be used to timeout or cancel the image creation. 35 | // isoPath contains the desired path of the ISO image to be created. The 36 | // userdata and metadata parameters are byte slices that contain the 37 | // ConfigDrive userdata and metadata that will be stored with the ISO image. 38 | // The attrs parameter can be used to control aspects of the newly created 39 | // qemu process, such as the user and group under which it runs. It may be nil. 40 | func CreateCloudInitISO(ctx context.Context, scratchDir, isoPath string, 41 | userData, metaData []byte, attr *syscall.SysProcAttr) error { 42 | configDrivePath := path.Join(scratchDir, "clr-cloud-init") 43 | dataDirPath := path.Join(configDrivePath, "openstack", "latest") 44 | metaDataPath := path.Join(dataDirPath, "meta_data.json") 45 | userDataPath := path.Join(dataDirPath, "user_data") 46 | 47 | defer func() { 48 | _ = os.RemoveAll(configDrivePath) 49 | }() 50 | 51 | err := os.MkdirAll(dataDirPath, 0755) 52 | if err != nil { 53 | return fmt.Errorf("Unable to create config drive directory %s : %v", 54 | dataDirPath, err) 55 | } 56 | 57 | err = ioutil.WriteFile(metaDataPath, metaData, 0644) 58 | if err != nil { 59 | return fmt.Errorf("Unable to create %s : %v", metaDataPath, err) 60 | } 61 | 62 | err = ioutil.WriteFile(userDataPath, userData, 0644) 63 | if err != nil { 64 | return fmt.Errorf("Unable to create %s : %v", userDataPath, err) 65 | } 66 | 67 | cmd := exec.CommandContext(ctx, "xorriso", "-as", "mkisofs", "-R", "-V", "config-2", 68 | "-o", isoPath, configDrivePath) 69 | cmd.SysProcAttr = attr 70 | err = cmd.Run() 71 | if err != nil { 72 | return fmt.Errorf("Unable to create cloudinit iso image %v", err) 73 | } 74 | 75 | return nil 76 | } 77 | -------------------------------------------------------------------------------- /vendor/github.com/pkg/errors/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | *.prof 25 | -------------------------------------------------------------------------------- /vendor/github.com/pkg/errors/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go_import_path: github.com/pkg/errors 3 | go: 4 | - 1.4.3 5 | - 1.5.4 6 | - 1.6.2 7 | - 1.7.1 8 | - tip 9 | 10 | script: 11 | - go test -v ./... 12 | -------------------------------------------------------------------------------- /vendor/github.com/pkg/errors/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, Dave Cheney 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | -------------------------------------------------------------------------------- /vendor/github.com/pkg/errors/README.md: -------------------------------------------------------------------------------- 1 | # errors [![Travis-CI](https://travis-ci.org/pkg/errors.svg)](https://travis-ci.org/pkg/errors) [![AppVeyor](https://ci.appveyor.com/api/projects/status/b98mptawhudj53ep/branch/master?svg=true)](https://ci.appveyor.com/project/davecheney/errors/branch/master) [![GoDoc](https://godoc.org/github.com/pkg/errors?status.svg)](http://godoc.org/github.com/pkg/errors) [![Report card](https://goreportcard.com/badge/github.com/pkg/errors)](https://goreportcard.com/report/github.com/pkg/errors) 2 | 3 | Package errors provides simple error handling primitives. 4 | 5 | `go get github.com/pkg/errors` 6 | 7 | The traditional error handling idiom in Go is roughly akin to 8 | ```go 9 | if err != nil { 10 | return err 11 | } 12 | ``` 13 | which applied recursively up the call stack results in error reports without context or debugging information. The errors package allows programmers to add context to the failure path in their code in a way that does not destroy the original value of the error. 14 | 15 | ## Adding context to an error 16 | 17 | The errors.Wrap function returns a new error that adds context to the original error. For example 18 | ```go 19 | _, err := ioutil.ReadAll(r) 20 | if err != nil { 21 | return errors.Wrap(err, "read failed") 22 | } 23 | ``` 24 | ## Retrieving the cause of an error 25 | 26 | Using `errors.Wrap` constructs a stack of errors, adding context to the preceding error. Depending on the nature of the error it may be necessary to reverse the operation of errors.Wrap to retrieve the original error for inspection. Any error value which implements this interface can be inspected by `errors.Cause`. 27 | ```go 28 | type causer interface { 29 | Cause() error 30 | } 31 | ``` 32 | `errors.Cause` will recursively retrieve the topmost error which does not implement `causer`, which is assumed to be the original cause. For example: 33 | ```go 34 | switch err := errors.Cause(err).(type) { 35 | case *MyError: 36 | // handle specifically 37 | default: 38 | // unknown error 39 | } 40 | ``` 41 | 42 | [Read the package documentation for more information](https://godoc.org/github.com/pkg/errors). 43 | 44 | ## Contributing 45 | 46 | We welcome pull requests, bug fixes and issue reports. With that said, the bar for adding new symbols to this package is intentionally set high. 47 | 48 | Before proposing a change, please discuss your change by raising an issue. 49 | 50 | ## Licence 51 | 52 | BSD-2-Clause 53 | -------------------------------------------------------------------------------- /vendor/github.com/pkg/errors/appveyor.yml: -------------------------------------------------------------------------------- 1 | version: build-{build}.{branch} 2 | 3 | clone_folder: C:\gopath\src\github.com\pkg\errors 4 | shallow_clone: true # for startup speed 5 | 6 | environment: 7 | GOPATH: C:\gopath 8 | 9 | platform: 10 | - x64 11 | 12 | # http://www.appveyor.com/docs/installed-software 13 | install: 14 | # some helpful output for debugging builds 15 | - go version 16 | - go env 17 | # pre-installed MinGW at C:\MinGW is 32bit only 18 | # but MSYS2 at C:\msys64 has mingw64 19 | - set PATH=C:\msys64\mingw64\bin;%PATH% 20 | - gcc --version 21 | - g++ --version 22 | 23 | build_script: 24 | - go install -v ./... 25 | 26 | test_script: 27 | - set PATH=C:\gopath\bin;%PATH% 28 | - go test -v ./... 29 | 30 | #artifacts: 31 | # - path: '%GOPATH%\bin\*.exe' 32 | deploy: off 33 | -------------------------------------------------------------------------------- /vendor/github.com/pmezard/go-difflib/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013, Patrick Mezard 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | The names of its contributors may not be used to endorse or promote 14 | products derived from this software without specific prior written 15 | permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 18 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 19 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 20 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 23 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 24 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | # Vim files https://github.com/github/gitignore/blob/master/Global/Vim.gitignore 23 | # swap 24 | [._]*.s[a-w][a-z] 25 | [._]s[a-w][a-z] 26 | # session 27 | Session.vim 28 | # temporary 29 | .netrwhist 30 | *~ 31 | # auto-generated tag files 32 | tags 33 | 34 | *.exe 35 | 36 | cobra.test 37 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/.mailmap: -------------------------------------------------------------------------------- 1 | Steve Francia 2 | Bjørn Erik Pedersen 3 | Fabiano Franz 4 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | matrix: 4 | include: 5 | - go: 1.7.6 6 | - go: 1.8.3 7 | - go: tip 8 | allow_failures: 9 | - go: tip 10 | 11 | before_install: 12 | - mkdir -p bin 13 | - curl -Lso bin/shellcheck https://github.com/caarlos0/shellcheck-docker/releases/download/v0.4.3/shellcheck 14 | - chmod +x bin/shellcheck 15 | script: 16 | - PATH=$PATH:$PWD/bin go test -v ./... 17 | - go build 18 | - diff -u <(echo -n) <(gofmt -d -s .) 19 | - if [ -z $NOVET ]; then 20 | diff -u <(echo -n) <(go tool vet . 2>&1 | grep -vE 'ExampleCommand|bash_completions.*Fprint'); 21 | fi 22 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/args.go: -------------------------------------------------------------------------------- 1 | package cobra 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | type PositionalArgs func(cmd *Command, args []string) error 8 | 9 | // Legacy arg validation has the following behaviour: 10 | // - root commands with no subcommands can take arbitrary arguments 11 | // - root commands with subcommands will do subcommand validity checking 12 | // - subcommands will always accept arbitrary arguments 13 | func legacyArgs(cmd *Command, args []string) error { 14 | // no subcommand, always take args 15 | if !cmd.HasSubCommands() { 16 | return nil 17 | } 18 | 19 | // root command with subcommands, do subcommand checking. 20 | if !cmd.HasParent() && len(args) > 0 { 21 | return fmt.Errorf("unknown command %q for %q%s", args[0], cmd.CommandPath(), cmd.findSuggestions(args[0])) 22 | } 23 | return nil 24 | } 25 | 26 | // NoArgs returns an error if any args are included. 27 | func NoArgs(cmd *Command, args []string) error { 28 | if len(args) > 0 { 29 | return fmt.Errorf("unknown command %q for %q", args[0], cmd.CommandPath()) 30 | } 31 | return nil 32 | } 33 | 34 | // OnlyValidArgs returns an error if any args are not in the list of ValidArgs. 35 | func OnlyValidArgs(cmd *Command, args []string) error { 36 | if len(cmd.ValidArgs) > 0 { 37 | for _, v := range args { 38 | if !stringInSlice(v, cmd.ValidArgs) { 39 | return fmt.Errorf("invalid argument %q for %q%s", v, cmd.CommandPath(), cmd.findSuggestions(args[0])) 40 | } 41 | } 42 | } 43 | return nil 44 | } 45 | 46 | // ArbitraryArgs never returns an error. 47 | func ArbitraryArgs(cmd *Command, args []string) error { 48 | return nil 49 | } 50 | 51 | // MinimumNArgs returns an error if there is not at least N args. 52 | func MinimumNArgs(n int) PositionalArgs { 53 | return func(cmd *Command, args []string) error { 54 | if len(args) < n { 55 | return fmt.Errorf("requires at least %d arg(s), only received %d", n, len(args)) 56 | } 57 | return nil 58 | } 59 | } 60 | 61 | // MaximumNArgs returns an error if there are more than N args. 62 | func MaximumNArgs(n int) PositionalArgs { 63 | return func(cmd *Command, args []string) error { 64 | if len(args) > n { 65 | return fmt.Errorf("accepts at most %d arg(s), received %d", n, len(args)) 66 | } 67 | return nil 68 | } 69 | } 70 | 71 | // ExactArgs returns an error if there are not exactly n args. 72 | func ExactArgs(n int) PositionalArgs { 73 | return func(cmd *Command, args []string) error { 74 | if len(args) != n { 75 | return fmt.Errorf("accepts %d arg(s), received %d", n, len(args)) 76 | } 77 | return nil 78 | } 79 | } 80 | 81 | // RangeArgs returns an error if the number of args is not within the expected range. 82 | func RangeArgs(min int, max int) PositionalArgs { 83 | return func(cmd *Command, args []string) error { 84 | if len(args) < min || len(args) > max { 85 | return fmt.Errorf("accepts between %d and %d arg(s), received %d", min, max, len(args)) 86 | } 87 | return nil 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/command_notwin.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package cobra 4 | 5 | var preExecHookFn func(*Command) 6 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/command_win.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | 3 | package cobra 4 | 5 | import ( 6 | "os" 7 | "time" 8 | 9 | "github.com/inconshreveable/mousetrap" 10 | ) 11 | 12 | var preExecHookFn = preExecHook 13 | 14 | func preExecHook(c *Command) { 15 | if MousetrapHelpText != "" && mousetrap.StartedByExplorer() { 16 | c.Print(MousetrapHelpText) 17 | time.Sleep(5 * time.Second) 18 | os.Exit(1) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/cobra/zsh_completions.go: -------------------------------------------------------------------------------- 1 | package cobra 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "io" 7 | "os" 8 | "strings" 9 | ) 10 | 11 | // GenZshCompletionFile generates zsh completion file. 12 | func (c *Command) GenZshCompletionFile(filename string) error { 13 | outFile, err := os.Create(filename) 14 | if err != nil { 15 | return err 16 | } 17 | defer outFile.Close() 18 | 19 | return c.GenZshCompletion(outFile) 20 | } 21 | 22 | // GenZshCompletion generates a zsh completion file and writes to the passed writer. 23 | func (c *Command) GenZshCompletion(w io.Writer) error { 24 | buf := new(bytes.Buffer) 25 | 26 | writeHeader(buf, c) 27 | maxDepth := maxDepth(c) 28 | writeLevelMapping(buf, maxDepth) 29 | writeLevelCases(buf, maxDepth, c) 30 | 31 | _, err := buf.WriteTo(w) 32 | return err 33 | } 34 | 35 | func writeHeader(w io.Writer, cmd *Command) { 36 | fmt.Fprintf(w, "#compdef %s\n\n", cmd.Name()) 37 | } 38 | 39 | func maxDepth(c *Command) int { 40 | if len(c.Commands()) == 0 { 41 | return 0 42 | } 43 | maxDepthSub := 0 44 | for _, s := range c.Commands() { 45 | subDepth := maxDepth(s) 46 | if subDepth > maxDepthSub { 47 | maxDepthSub = subDepth 48 | } 49 | } 50 | return 1 + maxDepthSub 51 | } 52 | 53 | func writeLevelMapping(w io.Writer, numLevels int) { 54 | fmt.Fprintln(w, `_arguments \`) 55 | for i := 1; i <= numLevels; i++ { 56 | fmt.Fprintf(w, ` '%d: :->level%d' \`, i, i) 57 | fmt.Fprintln(w) 58 | } 59 | fmt.Fprintf(w, ` '%d: :%s'`, numLevels+1, "_files") 60 | fmt.Fprintln(w) 61 | } 62 | 63 | func writeLevelCases(w io.Writer, maxDepth int, root *Command) { 64 | fmt.Fprintln(w, "case $state in") 65 | defer fmt.Fprintln(w, "esac") 66 | 67 | for i := 1; i <= maxDepth; i++ { 68 | fmt.Fprintf(w, " level%d)\n", i) 69 | writeLevel(w, root, i) 70 | fmt.Fprintln(w, " ;;") 71 | } 72 | fmt.Fprintln(w, " *)") 73 | fmt.Fprintln(w, " _arguments '*: :_files'") 74 | fmt.Fprintln(w, " ;;") 75 | } 76 | 77 | func writeLevel(w io.Writer, root *Command, i int) { 78 | fmt.Fprintf(w, " case $words[%d] in\n", i) 79 | defer fmt.Fprintln(w, " esac") 80 | 81 | commands := filterByLevel(root, i) 82 | byParent := groupByParent(commands) 83 | 84 | for p, c := range byParent { 85 | names := names(c) 86 | fmt.Fprintf(w, " %s)\n", p) 87 | fmt.Fprintf(w, " _arguments '%d: :(%s)'\n", i, strings.Join(names, " ")) 88 | fmt.Fprintln(w, " ;;") 89 | } 90 | fmt.Fprintln(w, " *)") 91 | fmt.Fprintln(w, " _arguments '*: :_files'") 92 | fmt.Fprintln(w, " ;;") 93 | 94 | } 95 | 96 | func filterByLevel(c *Command, l int) []*Command { 97 | cs := make([]*Command, 0) 98 | if l == 0 { 99 | cs = append(cs, c) 100 | return cs 101 | } 102 | for _, s := range c.Commands() { 103 | cs = append(cs, filterByLevel(s, l-1)...) 104 | } 105 | return cs 106 | } 107 | 108 | func groupByParent(commands []*Command) map[string][]*Command { 109 | m := make(map[string][]*Command) 110 | for _, c := range commands { 111 | parent := c.Parent() 112 | if parent == nil { 113 | continue 114 | } 115 | m[parent.Name()] = append(m[parent.Name()], c) 116 | } 117 | return m 118 | } 119 | 120 | func names(commands []*Command) []string { 121 | ns := make([]string, len(commands)) 122 | for i, c := range commands { 123 | ns[i] = c.Name() 124 | } 125 | return ns 126 | } 127 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/.gitignore: -------------------------------------------------------------------------------- 1 | .idea/* 2 | 3 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | language: go 4 | 5 | go: 6 | - 1.7.3 7 | - 1.8.1 8 | - tip 9 | 10 | matrix: 11 | allow_failures: 12 | - go: tip 13 | 14 | install: 15 | - go get github.com/golang/lint/golint 16 | - export PATH=$GOPATH/bin:$PATH 17 | - go install ./... 18 | 19 | script: 20 | - verify/all.sh -v 21 | - go test ./... 22 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Alex Ogier. All rights reserved. 2 | Copyright (c) 2012 The Go Authors. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above 11 | copyright notice, this list of conditions and the following disclaimer 12 | in the documentation and/or other materials provided with the 13 | distribution. 14 | * Neither the name of Google Inc. nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/bool.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // optional interface to indicate boolean flags that can be 6 | // supplied without "=value" text 7 | type boolFlag interface { 8 | Value 9 | IsBoolFlag() bool 10 | } 11 | 12 | // -- bool Value 13 | type boolValue bool 14 | 15 | func newBoolValue(val bool, p *bool) *boolValue { 16 | *p = val 17 | return (*boolValue)(p) 18 | } 19 | 20 | func (b *boolValue) Set(s string) error { 21 | v, err := strconv.ParseBool(s) 22 | *b = boolValue(v) 23 | return err 24 | } 25 | 26 | func (b *boolValue) Type() string { 27 | return "bool" 28 | } 29 | 30 | func (b *boolValue) String() string { return strconv.FormatBool(bool(*b)) } 31 | 32 | func (b *boolValue) IsBoolFlag() bool { return true } 33 | 34 | func boolConv(sval string) (interface{}, error) { 35 | return strconv.ParseBool(sval) 36 | } 37 | 38 | // GetBool return the bool value of a flag with the given name 39 | func (f *FlagSet) GetBool(name string) (bool, error) { 40 | val, err := f.getFlagType(name, "bool", boolConv) 41 | if err != nil { 42 | return false, err 43 | } 44 | return val.(bool), nil 45 | } 46 | 47 | // BoolVar defines a bool flag with specified name, default value, and usage string. 48 | // The argument p points to a bool variable in which to store the value of the flag. 49 | func (f *FlagSet) BoolVar(p *bool, name string, value bool, usage string) { 50 | f.BoolVarP(p, name, "", value, usage) 51 | } 52 | 53 | // BoolVarP is like BoolVar, but accepts a shorthand letter that can be used after a single dash. 54 | func (f *FlagSet) BoolVarP(p *bool, name, shorthand string, value bool, usage string) { 55 | flag := f.VarPF(newBoolValue(value, p), name, shorthand, usage) 56 | flag.NoOptDefVal = "true" 57 | } 58 | 59 | // BoolVar defines a bool flag with specified name, default value, and usage string. 60 | // The argument p points to a bool variable in which to store the value of the flag. 61 | func BoolVar(p *bool, name string, value bool, usage string) { 62 | BoolVarP(p, name, "", value, usage) 63 | } 64 | 65 | // BoolVarP is like BoolVar, but accepts a shorthand letter that can be used after a single dash. 66 | func BoolVarP(p *bool, name, shorthand string, value bool, usage string) { 67 | flag := CommandLine.VarPF(newBoolValue(value, p), name, shorthand, usage) 68 | flag.NoOptDefVal = "true" 69 | } 70 | 71 | // Bool defines a bool flag with specified name, default value, and usage string. 72 | // The return value is the address of a bool variable that stores the value of the flag. 73 | func (f *FlagSet) Bool(name string, value bool, usage string) *bool { 74 | return f.BoolP(name, "", value, usage) 75 | } 76 | 77 | // BoolP is like Bool, but accepts a shorthand letter that can be used after a single dash. 78 | func (f *FlagSet) BoolP(name, shorthand string, value bool, usage string) *bool { 79 | p := new(bool) 80 | f.BoolVarP(p, name, shorthand, value, usage) 81 | return p 82 | } 83 | 84 | // Bool defines a bool flag with specified name, default value, and usage string. 85 | // The return value is the address of a bool variable that stores the value of the flag. 86 | func Bool(name string, value bool, usage string) *bool { 87 | return BoolP(name, "", value, usage) 88 | } 89 | 90 | // BoolP is like Bool, but accepts a shorthand letter that can be used after a single dash. 91 | func BoolP(name, shorthand string, value bool, usage string) *bool { 92 | b := CommandLine.BoolP(name, shorthand, value, usage) 93 | return b 94 | } 95 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/count.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- count Value 6 | type countValue int 7 | 8 | func newCountValue(val int, p *int) *countValue { 9 | *p = val 10 | return (*countValue)(p) 11 | } 12 | 13 | func (i *countValue) Set(s string) error { 14 | v, err := strconv.ParseInt(s, 0, 64) 15 | // -1 means that no specific value was passed, so increment 16 | if v == -1 { 17 | *i = countValue(*i + 1) 18 | } else { 19 | *i = countValue(v) 20 | } 21 | return err 22 | } 23 | 24 | func (i *countValue) Type() string { 25 | return "count" 26 | } 27 | 28 | func (i *countValue) String() string { return strconv.Itoa(int(*i)) } 29 | 30 | func countConv(sval string) (interface{}, error) { 31 | i, err := strconv.Atoi(sval) 32 | if err != nil { 33 | return nil, err 34 | } 35 | return i, nil 36 | } 37 | 38 | // GetCount return the int value of a flag with the given name 39 | func (f *FlagSet) GetCount(name string) (int, error) { 40 | val, err := f.getFlagType(name, "count", countConv) 41 | if err != nil { 42 | return 0, err 43 | } 44 | return val.(int), nil 45 | } 46 | 47 | // CountVar defines a count flag with specified name, default value, and usage string. 48 | // The argument p points to an int variable in which to store the value of the flag. 49 | // A count flag will add 1 to its value evey time it is found on the command line 50 | func (f *FlagSet) CountVar(p *int, name string, usage string) { 51 | f.CountVarP(p, name, "", usage) 52 | } 53 | 54 | // CountVarP is like CountVar only take a shorthand for the flag name. 55 | func (f *FlagSet) CountVarP(p *int, name, shorthand string, usage string) { 56 | flag := f.VarPF(newCountValue(0, p), name, shorthand, usage) 57 | flag.NoOptDefVal = "-1" 58 | } 59 | 60 | // CountVar like CountVar only the flag is placed on the CommandLine instead of a given flag set 61 | func CountVar(p *int, name string, usage string) { 62 | CommandLine.CountVar(p, name, usage) 63 | } 64 | 65 | // CountVarP is like CountVar only take a shorthand for the flag name. 66 | func CountVarP(p *int, name, shorthand string, usage string) { 67 | CommandLine.CountVarP(p, name, shorthand, usage) 68 | } 69 | 70 | // Count defines a count flag with specified name, default value, and usage string. 71 | // The return value is the address of an int variable that stores the value of the flag. 72 | // A count flag will add 1 to its value evey time it is found on the command line 73 | func (f *FlagSet) Count(name string, usage string) *int { 74 | p := new(int) 75 | f.CountVarP(p, name, "", usage) 76 | return p 77 | } 78 | 79 | // CountP is like Count only takes a shorthand for the flag name. 80 | func (f *FlagSet) CountP(name, shorthand string, usage string) *int { 81 | p := new(int) 82 | f.CountVarP(p, name, shorthand, usage) 83 | return p 84 | } 85 | 86 | // Count defines a count flag with specified name, default value, and usage string. 87 | // The return value is the address of an int variable that stores the value of the flag. 88 | // A count flag will add 1 to its value evey time it is found on the command line 89 | func Count(name string, usage string) *int { 90 | return CommandLine.CountP(name, "", usage) 91 | } 92 | 93 | // CountP is like Count only takes a shorthand for the flag name. 94 | func CountP(name, shorthand string, usage string) *int { 95 | return CommandLine.CountP(name, shorthand, usage) 96 | } 97 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/duration.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "time" 5 | ) 6 | 7 | // -- time.Duration Value 8 | type durationValue time.Duration 9 | 10 | func newDurationValue(val time.Duration, p *time.Duration) *durationValue { 11 | *p = val 12 | return (*durationValue)(p) 13 | } 14 | 15 | func (d *durationValue) Set(s string) error { 16 | v, err := time.ParseDuration(s) 17 | *d = durationValue(v) 18 | return err 19 | } 20 | 21 | func (d *durationValue) Type() string { 22 | return "duration" 23 | } 24 | 25 | func (d *durationValue) String() string { return (*time.Duration)(d).String() } 26 | 27 | func durationConv(sval string) (interface{}, error) { 28 | return time.ParseDuration(sval) 29 | } 30 | 31 | // GetDuration return the duration value of a flag with the given name 32 | func (f *FlagSet) GetDuration(name string) (time.Duration, error) { 33 | val, err := f.getFlagType(name, "duration", durationConv) 34 | if err != nil { 35 | return 0, err 36 | } 37 | return val.(time.Duration), nil 38 | } 39 | 40 | // DurationVar defines a time.Duration flag with specified name, default value, and usage string. 41 | // The argument p points to a time.Duration variable in which to store the value of the flag. 42 | func (f *FlagSet) DurationVar(p *time.Duration, name string, value time.Duration, usage string) { 43 | f.VarP(newDurationValue(value, p), name, "", usage) 44 | } 45 | 46 | // DurationVarP is like DurationVar, but accepts a shorthand letter that can be used after a single dash. 47 | func (f *FlagSet) DurationVarP(p *time.Duration, name, shorthand string, value time.Duration, usage string) { 48 | f.VarP(newDurationValue(value, p), name, shorthand, usage) 49 | } 50 | 51 | // DurationVar defines a time.Duration flag with specified name, default value, and usage string. 52 | // The argument p points to a time.Duration variable in which to store the value of the flag. 53 | func DurationVar(p *time.Duration, name string, value time.Duration, usage string) { 54 | CommandLine.VarP(newDurationValue(value, p), name, "", usage) 55 | } 56 | 57 | // DurationVarP is like DurationVar, but accepts a shorthand letter that can be used after a single dash. 58 | func DurationVarP(p *time.Duration, name, shorthand string, value time.Duration, usage string) { 59 | CommandLine.VarP(newDurationValue(value, p), name, shorthand, usage) 60 | } 61 | 62 | // Duration defines a time.Duration flag with specified name, default value, and usage string. 63 | // The return value is the address of a time.Duration variable that stores the value of the flag. 64 | func (f *FlagSet) Duration(name string, value time.Duration, usage string) *time.Duration { 65 | p := new(time.Duration) 66 | f.DurationVarP(p, name, "", value, usage) 67 | return p 68 | } 69 | 70 | // DurationP is like Duration, but accepts a shorthand letter that can be used after a single dash. 71 | func (f *FlagSet) DurationP(name, shorthand string, value time.Duration, usage string) *time.Duration { 72 | p := new(time.Duration) 73 | f.DurationVarP(p, name, shorthand, value, usage) 74 | return p 75 | } 76 | 77 | // Duration defines a time.Duration flag with specified name, default value, and usage string. 78 | // The return value is the address of a time.Duration variable that stores the value of the flag. 79 | func Duration(name string, value time.Duration, usage string) *time.Duration { 80 | return CommandLine.DurationP(name, "", value, usage) 81 | } 82 | 83 | // DurationP is like Duration, but accepts a shorthand letter that can be used after a single dash. 84 | func DurationP(name, shorthand string, value time.Duration, usage string) *time.Duration { 85 | return CommandLine.DurationP(name, shorthand, value, usage) 86 | } 87 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/float32.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- float32 Value 6 | type float32Value float32 7 | 8 | func newFloat32Value(val float32, p *float32) *float32Value { 9 | *p = val 10 | return (*float32Value)(p) 11 | } 12 | 13 | func (f *float32Value) Set(s string) error { 14 | v, err := strconv.ParseFloat(s, 32) 15 | *f = float32Value(v) 16 | return err 17 | } 18 | 19 | func (f *float32Value) Type() string { 20 | return "float32" 21 | } 22 | 23 | func (f *float32Value) String() string { return strconv.FormatFloat(float64(*f), 'g', -1, 32) } 24 | 25 | func float32Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseFloat(sval, 32) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return float32(v), nil 31 | } 32 | 33 | // GetFloat32 return the float32 value of a flag with the given name 34 | func (f *FlagSet) GetFloat32(name string) (float32, error) { 35 | val, err := f.getFlagType(name, "float32", float32Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(float32), nil 40 | } 41 | 42 | // Float32Var defines a float32 flag with specified name, default value, and usage string. 43 | // The argument p points to a float32 variable in which to store the value of the flag. 44 | func (f *FlagSet) Float32Var(p *float32, name string, value float32, usage string) { 45 | f.VarP(newFloat32Value(value, p), name, "", usage) 46 | } 47 | 48 | // Float32VarP is like Float32Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Float32VarP(p *float32, name, shorthand string, value float32, usage string) { 50 | f.VarP(newFloat32Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Float32Var defines a float32 flag with specified name, default value, and usage string. 54 | // The argument p points to a float32 variable in which to store the value of the flag. 55 | func Float32Var(p *float32, name string, value float32, usage string) { 56 | CommandLine.VarP(newFloat32Value(value, p), name, "", usage) 57 | } 58 | 59 | // Float32VarP is like Float32Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Float32VarP(p *float32, name, shorthand string, value float32, usage string) { 61 | CommandLine.VarP(newFloat32Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Float32 defines a float32 flag with specified name, default value, and usage string. 65 | // The return value is the address of a float32 variable that stores the value of the flag. 66 | func (f *FlagSet) Float32(name string, value float32, usage string) *float32 { 67 | p := new(float32) 68 | f.Float32VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Float32P is like Float32, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Float32P(name, shorthand string, value float32, usage string) *float32 { 74 | p := new(float32) 75 | f.Float32VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Float32 defines a float32 flag with specified name, default value, and usage string. 80 | // The return value is the address of a float32 variable that stores the value of the flag. 81 | func Float32(name string, value float32, usage string) *float32 { 82 | return CommandLine.Float32P(name, "", value, usage) 83 | } 84 | 85 | // Float32P is like Float32, but accepts a shorthand letter that can be used after a single dash. 86 | func Float32P(name, shorthand string, value float32, usage string) *float32 { 87 | return CommandLine.Float32P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/float64.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- float64 Value 6 | type float64Value float64 7 | 8 | func newFloat64Value(val float64, p *float64) *float64Value { 9 | *p = val 10 | return (*float64Value)(p) 11 | } 12 | 13 | func (f *float64Value) Set(s string) error { 14 | v, err := strconv.ParseFloat(s, 64) 15 | *f = float64Value(v) 16 | return err 17 | } 18 | 19 | func (f *float64Value) Type() string { 20 | return "float64" 21 | } 22 | 23 | func (f *float64Value) String() string { return strconv.FormatFloat(float64(*f), 'g', -1, 64) } 24 | 25 | func float64Conv(sval string) (interface{}, error) { 26 | return strconv.ParseFloat(sval, 64) 27 | } 28 | 29 | // GetFloat64 return the float64 value of a flag with the given name 30 | func (f *FlagSet) GetFloat64(name string) (float64, error) { 31 | val, err := f.getFlagType(name, "float64", float64Conv) 32 | if err != nil { 33 | return 0, err 34 | } 35 | return val.(float64), nil 36 | } 37 | 38 | // Float64Var defines a float64 flag with specified name, default value, and usage string. 39 | // The argument p points to a float64 variable in which to store the value of the flag. 40 | func (f *FlagSet) Float64Var(p *float64, name string, value float64, usage string) { 41 | f.VarP(newFloat64Value(value, p), name, "", usage) 42 | } 43 | 44 | // Float64VarP is like Float64Var, but accepts a shorthand letter that can be used after a single dash. 45 | func (f *FlagSet) Float64VarP(p *float64, name, shorthand string, value float64, usage string) { 46 | f.VarP(newFloat64Value(value, p), name, shorthand, usage) 47 | } 48 | 49 | // Float64Var defines a float64 flag with specified name, default value, and usage string. 50 | // The argument p points to a float64 variable in which to store the value of the flag. 51 | func Float64Var(p *float64, name string, value float64, usage string) { 52 | CommandLine.VarP(newFloat64Value(value, p), name, "", usage) 53 | } 54 | 55 | // Float64VarP is like Float64Var, but accepts a shorthand letter that can be used after a single dash. 56 | func Float64VarP(p *float64, name, shorthand string, value float64, usage string) { 57 | CommandLine.VarP(newFloat64Value(value, p), name, shorthand, usage) 58 | } 59 | 60 | // Float64 defines a float64 flag with specified name, default value, and usage string. 61 | // The return value is the address of a float64 variable that stores the value of the flag. 62 | func (f *FlagSet) Float64(name string, value float64, usage string) *float64 { 63 | p := new(float64) 64 | f.Float64VarP(p, name, "", value, usage) 65 | return p 66 | } 67 | 68 | // Float64P is like Float64, but accepts a shorthand letter that can be used after a single dash. 69 | func (f *FlagSet) Float64P(name, shorthand string, value float64, usage string) *float64 { 70 | p := new(float64) 71 | f.Float64VarP(p, name, shorthand, value, usage) 72 | return p 73 | } 74 | 75 | // Float64 defines a float64 flag with specified name, default value, and usage string. 76 | // The return value is the address of a float64 variable that stores the value of the flag. 77 | func Float64(name string, value float64, usage string) *float64 { 78 | return CommandLine.Float64P(name, "", value, usage) 79 | } 80 | 81 | // Float64P is like Float64, but accepts a shorthand letter that can be used after a single dash. 82 | func Float64P(name, shorthand string, value float64, usage string) *float64 { 83 | return CommandLine.Float64P(name, shorthand, value, usage) 84 | } 85 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/golangflag.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package pflag 6 | 7 | import ( 8 | goflag "flag" 9 | "reflect" 10 | "strings" 11 | ) 12 | 13 | // flagValueWrapper implements pflag.Value around a flag.Value. The main 14 | // difference here is the addition of the Type method that returns a string 15 | // name of the type. As this is generally unknown, we approximate that with 16 | // reflection. 17 | type flagValueWrapper struct { 18 | inner goflag.Value 19 | flagType string 20 | } 21 | 22 | // We are just copying the boolFlag interface out of goflag as that is what 23 | // they use to decide if a flag should get "true" when no arg is given. 24 | type goBoolFlag interface { 25 | goflag.Value 26 | IsBoolFlag() bool 27 | } 28 | 29 | func wrapFlagValue(v goflag.Value) Value { 30 | // If the flag.Value happens to also be a pflag.Value, just use it directly. 31 | if pv, ok := v.(Value); ok { 32 | return pv 33 | } 34 | 35 | pv := &flagValueWrapper{ 36 | inner: v, 37 | } 38 | 39 | t := reflect.TypeOf(v) 40 | if t.Kind() == reflect.Interface || t.Kind() == reflect.Ptr { 41 | t = t.Elem() 42 | } 43 | 44 | pv.flagType = strings.TrimSuffix(t.Name(), "Value") 45 | return pv 46 | } 47 | 48 | func (v *flagValueWrapper) String() string { 49 | return v.inner.String() 50 | } 51 | 52 | func (v *flagValueWrapper) Set(s string) error { 53 | return v.inner.Set(s) 54 | } 55 | 56 | func (v *flagValueWrapper) Type() string { 57 | return v.flagType 58 | } 59 | 60 | // PFlagFromGoFlag will return a *pflag.Flag given a *flag.Flag 61 | // If the *flag.Flag.Name was a single character (ex: `v`) it will be accessiblei 62 | // with both `-v` and `--v` in flags. If the golang flag was more than a single 63 | // character (ex: `verbose`) it will only be accessible via `--verbose` 64 | func PFlagFromGoFlag(goflag *goflag.Flag) *Flag { 65 | // Remember the default value as a string; it won't change. 66 | flag := &Flag{ 67 | Name: goflag.Name, 68 | Usage: goflag.Usage, 69 | Value: wrapFlagValue(goflag.Value), 70 | // Looks like golang flags don't set DefValue correctly :-( 71 | //DefValue: goflag.DefValue, 72 | DefValue: goflag.Value.String(), 73 | } 74 | // Ex: if the golang flag was -v, allow both -v and --v to work 75 | if len(flag.Name) == 1 { 76 | flag.Shorthand = flag.Name 77 | } 78 | if fv, ok := goflag.Value.(goBoolFlag); ok && fv.IsBoolFlag() { 79 | flag.NoOptDefVal = "true" 80 | } 81 | return flag 82 | } 83 | 84 | // AddGoFlag will add the given *flag.Flag to the pflag.FlagSet 85 | func (f *FlagSet) AddGoFlag(goflag *goflag.Flag) { 86 | if f.Lookup(goflag.Name) != nil { 87 | return 88 | } 89 | newflag := PFlagFromGoFlag(goflag) 90 | f.AddFlag(newflag) 91 | } 92 | 93 | // AddGoFlagSet will add the given *flag.FlagSet to the pflag.FlagSet 94 | func (f *FlagSet) AddGoFlagSet(newSet *goflag.FlagSet) { 95 | if newSet == nil { 96 | return 97 | } 98 | newSet.VisitAll(func(goflag *goflag.Flag) { 99 | f.AddGoFlag(goflag) 100 | }) 101 | } 102 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/int.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- int Value 6 | type intValue int 7 | 8 | func newIntValue(val int, p *int) *intValue { 9 | *p = val 10 | return (*intValue)(p) 11 | } 12 | 13 | func (i *intValue) Set(s string) error { 14 | v, err := strconv.ParseInt(s, 0, 64) 15 | *i = intValue(v) 16 | return err 17 | } 18 | 19 | func (i *intValue) Type() string { 20 | return "int" 21 | } 22 | 23 | func (i *intValue) String() string { return strconv.Itoa(int(*i)) } 24 | 25 | func intConv(sval string) (interface{}, error) { 26 | return strconv.Atoi(sval) 27 | } 28 | 29 | // GetInt return the int value of a flag with the given name 30 | func (f *FlagSet) GetInt(name string) (int, error) { 31 | val, err := f.getFlagType(name, "int", intConv) 32 | if err != nil { 33 | return 0, err 34 | } 35 | return val.(int), nil 36 | } 37 | 38 | // IntVar defines an int flag with specified name, default value, and usage string. 39 | // The argument p points to an int variable in which to store the value of the flag. 40 | func (f *FlagSet) IntVar(p *int, name string, value int, usage string) { 41 | f.VarP(newIntValue(value, p), name, "", usage) 42 | } 43 | 44 | // IntVarP is like IntVar, but accepts a shorthand letter that can be used after a single dash. 45 | func (f *FlagSet) IntVarP(p *int, name, shorthand string, value int, usage string) { 46 | f.VarP(newIntValue(value, p), name, shorthand, usage) 47 | } 48 | 49 | // IntVar defines an int flag with specified name, default value, and usage string. 50 | // The argument p points to an int variable in which to store the value of the flag. 51 | func IntVar(p *int, name string, value int, usage string) { 52 | CommandLine.VarP(newIntValue(value, p), name, "", usage) 53 | } 54 | 55 | // IntVarP is like IntVar, but accepts a shorthand letter that can be used after a single dash. 56 | func IntVarP(p *int, name, shorthand string, value int, usage string) { 57 | CommandLine.VarP(newIntValue(value, p), name, shorthand, usage) 58 | } 59 | 60 | // Int defines an int flag with specified name, default value, and usage string. 61 | // The return value is the address of an int variable that stores the value of the flag. 62 | func (f *FlagSet) Int(name string, value int, usage string) *int { 63 | p := new(int) 64 | f.IntVarP(p, name, "", value, usage) 65 | return p 66 | } 67 | 68 | // IntP is like Int, but accepts a shorthand letter that can be used after a single dash. 69 | func (f *FlagSet) IntP(name, shorthand string, value int, usage string) *int { 70 | p := new(int) 71 | f.IntVarP(p, name, shorthand, value, usage) 72 | return p 73 | } 74 | 75 | // Int defines an int flag with specified name, default value, and usage string. 76 | // The return value is the address of an int variable that stores the value of the flag. 77 | func Int(name string, value int, usage string) *int { 78 | return CommandLine.IntP(name, "", value, usage) 79 | } 80 | 81 | // IntP is like Int, but accepts a shorthand letter that can be used after a single dash. 82 | func IntP(name, shorthand string, value int, usage string) *int { 83 | return CommandLine.IntP(name, shorthand, value, usage) 84 | } 85 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/int32.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- int32 Value 6 | type int32Value int32 7 | 8 | func newInt32Value(val int32, p *int32) *int32Value { 9 | *p = val 10 | return (*int32Value)(p) 11 | } 12 | 13 | func (i *int32Value) Set(s string) error { 14 | v, err := strconv.ParseInt(s, 0, 32) 15 | *i = int32Value(v) 16 | return err 17 | } 18 | 19 | func (i *int32Value) Type() string { 20 | return "int32" 21 | } 22 | 23 | func (i *int32Value) String() string { return strconv.FormatInt(int64(*i), 10) } 24 | 25 | func int32Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseInt(sval, 0, 32) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return int32(v), nil 31 | } 32 | 33 | // GetInt32 return the int32 value of a flag with the given name 34 | func (f *FlagSet) GetInt32(name string) (int32, error) { 35 | val, err := f.getFlagType(name, "int32", int32Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(int32), nil 40 | } 41 | 42 | // Int32Var defines an int32 flag with specified name, default value, and usage string. 43 | // The argument p points to an int32 variable in which to store the value of the flag. 44 | func (f *FlagSet) Int32Var(p *int32, name string, value int32, usage string) { 45 | f.VarP(newInt32Value(value, p), name, "", usage) 46 | } 47 | 48 | // Int32VarP is like Int32Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Int32VarP(p *int32, name, shorthand string, value int32, usage string) { 50 | f.VarP(newInt32Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Int32Var defines an int32 flag with specified name, default value, and usage string. 54 | // The argument p points to an int32 variable in which to store the value of the flag. 55 | func Int32Var(p *int32, name string, value int32, usage string) { 56 | CommandLine.VarP(newInt32Value(value, p), name, "", usage) 57 | } 58 | 59 | // Int32VarP is like Int32Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Int32VarP(p *int32, name, shorthand string, value int32, usage string) { 61 | CommandLine.VarP(newInt32Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Int32 defines an int32 flag with specified name, default value, and usage string. 65 | // The return value is the address of an int32 variable that stores the value of the flag. 66 | func (f *FlagSet) Int32(name string, value int32, usage string) *int32 { 67 | p := new(int32) 68 | f.Int32VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Int32P is like Int32, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Int32P(name, shorthand string, value int32, usage string) *int32 { 74 | p := new(int32) 75 | f.Int32VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Int32 defines an int32 flag with specified name, default value, and usage string. 80 | // The return value is the address of an int32 variable that stores the value of the flag. 81 | func Int32(name string, value int32, usage string) *int32 { 82 | return CommandLine.Int32P(name, "", value, usage) 83 | } 84 | 85 | // Int32P is like Int32, but accepts a shorthand letter that can be used after a single dash. 86 | func Int32P(name, shorthand string, value int32, usage string) *int32 { 87 | return CommandLine.Int32P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/int64.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- int64 Value 6 | type int64Value int64 7 | 8 | func newInt64Value(val int64, p *int64) *int64Value { 9 | *p = val 10 | return (*int64Value)(p) 11 | } 12 | 13 | func (i *int64Value) Set(s string) error { 14 | v, err := strconv.ParseInt(s, 0, 64) 15 | *i = int64Value(v) 16 | return err 17 | } 18 | 19 | func (i *int64Value) Type() string { 20 | return "int64" 21 | } 22 | 23 | func (i *int64Value) String() string { return strconv.FormatInt(int64(*i), 10) } 24 | 25 | func int64Conv(sval string) (interface{}, error) { 26 | return strconv.ParseInt(sval, 0, 64) 27 | } 28 | 29 | // GetInt64 return the int64 value of a flag with the given name 30 | func (f *FlagSet) GetInt64(name string) (int64, error) { 31 | val, err := f.getFlagType(name, "int64", int64Conv) 32 | if err != nil { 33 | return 0, err 34 | } 35 | return val.(int64), nil 36 | } 37 | 38 | // Int64Var defines an int64 flag with specified name, default value, and usage string. 39 | // The argument p points to an int64 variable in which to store the value of the flag. 40 | func (f *FlagSet) Int64Var(p *int64, name string, value int64, usage string) { 41 | f.VarP(newInt64Value(value, p), name, "", usage) 42 | } 43 | 44 | // Int64VarP is like Int64Var, but accepts a shorthand letter that can be used after a single dash. 45 | func (f *FlagSet) Int64VarP(p *int64, name, shorthand string, value int64, usage string) { 46 | f.VarP(newInt64Value(value, p), name, shorthand, usage) 47 | } 48 | 49 | // Int64Var defines an int64 flag with specified name, default value, and usage string. 50 | // The argument p points to an int64 variable in which to store the value of the flag. 51 | func Int64Var(p *int64, name string, value int64, usage string) { 52 | CommandLine.VarP(newInt64Value(value, p), name, "", usage) 53 | } 54 | 55 | // Int64VarP is like Int64Var, but accepts a shorthand letter that can be used after a single dash. 56 | func Int64VarP(p *int64, name, shorthand string, value int64, usage string) { 57 | CommandLine.VarP(newInt64Value(value, p), name, shorthand, usage) 58 | } 59 | 60 | // Int64 defines an int64 flag with specified name, default value, and usage string. 61 | // The return value is the address of an int64 variable that stores the value of the flag. 62 | func (f *FlagSet) Int64(name string, value int64, usage string) *int64 { 63 | p := new(int64) 64 | f.Int64VarP(p, name, "", value, usage) 65 | return p 66 | } 67 | 68 | // Int64P is like Int64, but accepts a shorthand letter that can be used after a single dash. 69 | func (f *FlagSet) Int64P(name, shorthand string, value int64, usage string) *int64 { 70 | p := new(int64) 71 | f.Int64VarP(p, name, shorthand, value, usage) 72 | return p 73 | } 74 | 75 | // Int64 defines an int64 flag with specified name, default value, and usage string. 76 | // The return value is the address of an int64 variable that stores the value of the flag. 77 | func Int64(name string, value int64, usage string) *int64 { 78 | return CommandLine.Int64P(name, "", value, usage) 79 | } 80 | 81 | // Int64P is like Int64, but accepts a shorthand letter that can be used after a single dash. 82 | func Int64P(name, shorthand string, value int64, usage string) *int64 { 83 | return CommandLine.Int64P(name, shorthand, value, usage) 84 | } 85 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/int8.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- int8 Value 6 | type int8Value int8 7 | 8 | func newInt8Value(val int8, p *int8) *int8Value { 9 | *p = val 10 | return (*int8Value)(p) 11 | } 12 | 13 | func (i *int8Value) Set(s string) error { 14 | v, err := strconv.ParseInt(s, 0, 8) 15 | *i = int8Value(v) 16 | return err 17 | } 18 | 19 | func (i *int8Value) Type() string { 20 | return "int8" 21 | } 22 | 23 | func (i *int8Value) String() string { return strconv.FormatInt(int64(*i), 10) } 24 | 25 | func int8Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseInt(sval, 0, 8) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return int8(v), nil 31 | } 32 | 33 | // GetInt8 return the int8 value of a flag with the given name 34 | func (f *FlagSet) GetInt8(name string) (int8, error) { 35 | val, err := f.getFlagType(name, "int8", int8Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(int8), nil 40 | } 41 | 42 | // Int8Var defines an int8 flag with specified name, default value, and usage string. 43 | // The argument p points to an int8 variable in which to store the value of the flag. 44 | func (f *FlagSet) Int8Var(p *int8, name string, value int8, usage string) { 45 | f.VarP(newInt8Value(value, p), name, "", usage) 46 | } 47 | 48 | // Int8VarP is like Int8Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Int8VarP(p *int8, name, shorthand string, value int8, usage string) { 50 | f.VarP(newInt8Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Int8Var defines an int8 flag with specified name, default value, and usage string. 54 | // The argument p points to an int8 variable in which to store the value of the flag. 55 | func Int8Var(p *int8, name string, value int8, usage string) { 56 | CommandLine.VarP(newInt8Value(value, p), name, "", usage) 57 | } 58 | 59 | // Int8VarP is like Int8Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Int8VarP(p *int8, name, shorthand string, value int8, usage string) { 61 | CommandLine.VarP(newInt8Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Int8 defines an int8 flag with specified name, default value, and usage string. 65 | // The return value is the address of an int8 variable that stores the value of the flag. 66 | func (f *FlagSet) Int8(name string, value int8, usage string) *int8 { 67 | p := new(int8) 68 | f.Int8VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Int8P is like Int8, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Int8P(name, shorthand string, value int8, usage string) *int8 { 74 | p := new(int8) 75 | f.Int8VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Int8 defines an int8 flag with specified name, default value, and usage string. 80 | // The return value is the address of an int8 variable that stores the value of the flag. 81 | func Int8(name string, value int8, usage string) *int8 { 82 | return CommandLine.Int8P(name, "", value, usage) 83 | } 84 | 85 | // Int8P is like Int8, but accepts a shorthand letter that can be used after a single dash. 86 | func Int8P(name, shorthand string, value int8, usage string) *int8 { 87 | return CommandLine.Int8P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/ip.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | "strings" 7 | ) 8 | 9 | // -- net.IP value 10 | type ipValue net.IP 11 | 12 | func newIPValue(val net.IP, p *net.IP) *ipValue { 13 | *p = val 14 | return (*ipValue)(p) 15 | } 16 | 17 | func (i *ipValue) String() string { return net.IP(*i).String() } 18 | func (i *ipValue) Set(s string) error { 19 | ip := net.ParseIP(strings.TrimSpace(s)) 20 | if ip == nil { 21 | return fmt.Errorf("failed to parse IP: %q", s) 22 | } 23 | *i = ipValue(ip) 24 | return nil 25 | } 26 | 27 | func (i *ipValue) Type() string { 28 | return "ip" 29 | } 30 | 31 | func ipConv(sval string) (interface{}, error) { 32 | ip := net.ParseIP(sval) 33 | if ip != nil { 34 | return ip, nil 35 | } 36 | return nil, fmt.Errorf("invalid string being converted to IP address: %s", sval) 37 | } 38 | 39 | // GetIP return the net.IP value of a flag with the given name 40 | func (f *FlagSet) GetIP(name string) (net.IP, error) { 41 | val, err := f.getFlagType(name, "ip", ipConv) 42 | if err != nil { 43 | return nil, err 44 | } 45 | return val.(net.IP), nil 46 | } 47 | 48 | // IPVar defines an net.IP flag with specified name, default value, and usage string. 49 | // The argument p points to an net.IP variable in which to store the value of the flag. 50 | func (f *FlagSet) IPVar(p *net.IP, name string, value net.IP, usage string) { 51 | f.VarP(newIPValue(value, p), name, "", usage) 52 | } 53 | 54 | // IPVarP is like IPVar, but accepts a shorthand letter that can be used after a single dash. 55 | func (f *FlagSet) IPVarP(p *net.IP, name, shorthand string, value net.IP, usage string) { 56 | f.VarP(newIPValue(value, p), name, shorthand, usage) 57 | } 58 | 59 | // IPVar defines an net.IP flag with specified name, default value, and usage string. 60 | // The argument p points to an net.IP variable in which to store the value of the flag. 61 | func IPVar(p *net.IP, name string, value net.IP, usage string) { 62 | CommandLine.VarP(newIPValue(value, p), name, "", usage) 63 | } 64 | 65 | // IPVarP is like IPVar, but accepts a shorthand letter that can be used after a single dash. 66 | func IPVarP(p *net.IP, name, shorthand string, value net.IP, usage string) { 67 | CommandLine.VarP(newIPValue(value, p), name, shorthand, usage) 68 | } 69 | 70 | // IP defines an net.IP flag with specified name, default value, and usage string. 71 | // The return value is the address of an net.IP variable that stores the value of the flag. 72 | func (f *FlagSet) IP(name string, value net.IP, usage string) *net.IP { 73 | p := new(net.IP) 74 | f.IPVarP(p, name, "", value, usage) 75 | return p 76 | } 77 | 78 | // IPP is like IP, but accepts a shorthand letter that can be used after a single dash. 79 | func (f *FlagSet) IPP(name, shorthand string, value net.IP, usage string) *net.IP { 80 | p := new(net.IP) 81 | f.IPVarP(p, name, shorthand, value, usage) 82 | return p 83 | } 84 | 85 | // IP defines an net.IP flag with specified name, default value, and usage string. 86 | // The return value is the address of an net.IP variable that stores the value of the flag. 87 | func IP(name string, value net.IP, usage string) *net.IP { 88 | return CommandLine.IPP(name, "", value, usage) 89 | } 90 | 91 | // IPP is like IP, but accepts a shorthand letter that can be used after a single dash. 92 | func IPP(name, shorthand string, value net.IP, usage string) *net.IP { 93 | return CommandLine.IPP(name, shorthand, value, usage) 94 | } 95 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/ipnet.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | "strings" 7 | ) 8 | 9 | // IPNet adapts net.IPNet for use as a flag. 10 | type ipNetValue net.IPNet 11 | 12 | func (ipnet ipNetValue) String() string { 13 | n := net.IPNet(ipnet) 14 | return n.String() 15 | } 16 | 17 | func (ipnet *ipNetValue) Set(value string) error { 18 | _, n, err := net.ParseCIDR(strings.TrimSpace(value)) 19 | if err != nil { 20 | return err 21 | } 22 | *ipnet = ipNetValue(*n) 23 | return nil 24 | } 25 | 26 | func (*ipNetValue) Type() string { 27 | return "ipNet" 28 | } 29 | 30 | func newIPNetValue(val net.IPNet, p *net.IPNet) *ipNetValue { 31 | *p = val 32 | return (*ipNetValue)(p) 33 | } 34 | 35 | func ipNetConv(sval string) (interface{}, error) { 36 | _, n, err := net.ParseCIDR(strings.TrimSpace(sval)) 37 | if err == nil { 38 | return *n, nil 39 | } 40 | return nil, fmt.Errorf("invalid string being converted to IPNet: %s", sval) 41 | } 42 | 43 | // GetIPNet return the net.IPNet value of a flag with the given name 44 | func (f *FlagSet) GetIPNet(name string) (net.IPNet, error) { 45 | val, err := f.getFlagType(name, "ipNet", ipNetConv) 46 | if err != nil { 47 | return net.IPNet{}, err 48 | } 49 | return val.(net.IPNet), nil 50 | } 51 | 52 | // IPNetVar defines an net.IPNet flag with specified name, default value, and usage string. 53 | // The argument p points to an net.IPNet variable in which to store the value of the flag. 54 | func (f *FlagSet) IPNetVar(p *net.IPNet, name string, value net.IPNet, usage string) { 55 | f.VarP(newIPNetValue(value, p), name, "", usage) 56 | } 57 | 58 | // IPNetVarP is like IPNetVar, but accepts a shorthand letter that can be used after a single dash. 59 | func (f *FlagSet) IPNetVarP(p *net.IPNet, name, shorthand string, value net.IPNet, usage string) { 60 | f.VarP(newIPNetValue(value, p), name, shorthand, usage) 61 | } 62 | 63 | // IPNetVar defines an net.IPNet flag with specified name, default value, and usage string. 64 | // The argument p points to an net.IPNet variable in which to store the value of the flag. 65 | func IPNetVar(p *net.IPNet, name string, value net.IPNet, usage string) { 66 | CommandLine.VarP(newIPNetValue(value, p), name, "", usage) 67 | } 68 | 69 | // IPNetVarP is like IPNetVar, but accepts a shorthand letter that can be used after a single dash. 70 | func IPNetVarP(p *net.IPNet, name, shorthand string, value net.IPNet, usage string) { 71 | CommandLine.VarP(newIPNetValue(value, p), name, shorthand, usage) 72 | } 73 | 74 | // IPNet defines an net.IPNet flag with specified name, default value, and usage string. 75 | // The return value is the address of an net.IPNet variable that stores the value of the flag. 76 | func (f *FlagSet) IPNet(name string, value net.IPNet, usage string) *net.IPNet { 77 | p := new(net.IPNet) 78 | f.IPNetVarP(p, name, "", value, usage) 79 | return p 80 | } 81 | 82 | // IPNetP is like IPNet, but accepts a shorthand letter that can be used after a single dash. 83 | func (f *FlagSet) IPNetP(name, shorthand string, value net.IPNet, usage string) *net.IPNet { 84 | p := new(net.IPNet) 85 | f.IPNetVarP(p, name, shorthand, value, usage) 86 | return p 87 | } 88 | 89 | // IPNet defines an net.IPNet flag with specified name, default value, and usage string. 90 | // The return value is the address of an net.IPNet variable that stores the value of the flag. 91 | func IPNet(name string, value net.IPNet, usage string) *net.IPNet { 92 | return CommandLine.IPNetP(name, "", value, usage) 93 | } 94 | 95 | // IPNetP is like IPNet, but accepts a shorthand letter that can be used after a single dash. 96 | func IPNetP(name, shorthand string, value net.IPNet, usage string) *net.IPNet { 97 | return CommandLine.IPNetP(name, shorthand, value, usage) 98 | } 99 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/string.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | // -- string Value 4 | type stringValue string 5 | 6 | func newStringValue(val string, p *string) *stringValue { 7 | *p = val 8 | return (*stringValue)(p) 9 | } 10 | 11 | func (s *stringValue) Set(val string) error { 12 | *s = stringValue(val) 13 | return nil 14 | } 15 | func (s *stringValue) Type() string { 16 | return "string" 17 | } 18 | 19 | func (s *stringValue) String() string { return string(*s) } 20 | 21 | func stringConv(sval string) (interface{}, error) { 22 | return sval, nil 23 | } 24 | 25 | // GetString return the string value of a flag with the given name 26 | func (f *FlagSet) GetString(name string) (string, error) { 27 | val, err := f.getFlagType(name, "string", stringConv) 28 | if err != nil { 29 | return "", err 30 | } 31 | return val.(string), nil 32 | } 33 | 34 | // StringVar defines a string flag with specified name, default value, and usage string. 35 | // The argument p points to a string variable in which to store the value of the flag. 36 | func (f *FlagSet) StringVar(p *string, name string, value string, usage string) { 37 | f.VarP(newStringValue(value, p), name, "", usage) 38 | } 39 | 40 | // StringVarP is like StringVar, but accepts a shorthand letter that can be used after a single dash. 41 | func (f *FlagSet) StringVarP(p *string, name, shorthand string, value string, usage string) { 42 | f.VarP(newStringValue(value, p), name, shorthand, usage) 43 | } 44 | 45 | // StringVar defines a string flag with specified name, default value, and usage string. 46 | // The argument p points to a string variable in which to store the value of the flag. 47 | func StringVar(p *string, name string, value string, usage string) { 48 | CommandLine.VarP(newStringValue(value, p), name, "", usage) 49 | } 50 | 51 | // StringVarP is like StringVar, but accepts a shorthand letter that can be used after a single dash. 52 | func StringVarP(p *string, name, shorthand string, value string, usage string) { 53 | CommandLine.VarP(newStringValue(value, p), name, shorthand, usage) 54 | } 55 | 56 | // String defines a string flag with specified name, default value, and usage string. 57 | // The return value is the address of a string variable that stores the value of the flag. 58 | func (f *FlagSet) String(name string, value string, usage string) *string { 59 | p := new(string) 60 | f.StringVarP(p, name, "", value, usage) 61 | return p 62 | } 63 | 64 | // StringP is like String, but accepts a shorthand letter that can be used after a single dash. 65 | func (f *FlagSet) StringP(name, shorthand string, value string, usage string) *string { 66 | p := new(string) 67 | f.StringVarP(p, name, shorthand, value, usage) 68 | return p 69 | } 70 | 71 | // String defines a string flag with specified name, default value, and usage string. 72 | // The return value is the address of a string variable that stores the value of the flag. 73 | func String(name string, value string, usage string) *string { 74 | return CommandLine.StringP(name, "", value, usage) 75 | } 76 | 77 | // StringP is like String, but accepts a shorthand letter that can be used after a single dash. 78 | func StringP(name, shorthand string, value string, usage string) *string { 79 | return CommandLine.StringP(name, shorthand, value, usage) 80 | } 81 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/uint.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- uint Value 6 | type uintValue uint 7 | 8 | func newUintValue(val uint, p *uint) *uintValue { 9 | *p = val 10 | return (*uintValue)(p) 11 | } 12 | 13 | func (i *uintValue) Set(s string) error { 14 | v, err := strconv.ParseUint(s, 0, 64) 15 | *i = uintValue(v) 16 | return err 17 | } 18 | 19 | func (i *uintValue) Type() string { 20 | return "uint" 21 | } 22 | 23 | func (i *uintValue) String() string { return strconv.FormatUint(uint64(*i), 10) } 24 | 25 | func uintConv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseUint(sval, 0, 0) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return uint(v), nil 31 | } 32 | 33 | // GetUint return the uint value of a flag with the given name 34 | func (f *FlagSet) GetUint(name string) (uint, error) { 35 | val, err := f.getFlagType(name, "uint", uintConv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(uint), nil 40 | } 41 | 42 | // UintVar defines a uint flag with specified name, default value, and usage string. 43 | // The argument p points to a uint variable in which to store the value of the flag. 44 | func (f *FlagSet) UintVar(p *uint, name string, value uint, usage string) { 45 | f.VarP(newUintValue(value, p), name, "", usage) 46 | } 47 | 48 | // UintVarP is like UintVar, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) UintVarP(p *uint, name, shorthand string, value uint, usage string) { 50 | f.VarP(newUintValue(value, p), name, shorthand, usage) 51 | } 52 | 53 | // UintVar defines a uint flag with specified name, default value, and usage string. 54 | // The argument p points to a uint variable in which to store the value of the flag. 55 | func UintVar(p *uint, name string, value uint, usage string) { 56 | CommandLine.VarP(newUintValue(value, p), name, "", usage) 57 | } 58 | 59 | // UintVarP is like UintVar, but accepts a shorthand letter that can be used after a single dash. 60 | func UintVarP(p *uint, name, shorthand string, value uint, usage string) { 61 | CommandLine.VarP(newUintValue(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Uint defines a uint flag with specified name, default value, and usage string. 65 | // The return value is the address of a uint variable that stores the value of the flag. 66 | func (f *FlagSet) Uint(name string, value uint, usage string) *uint { 67 | p := new(uint) 68 | f.UintVarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // UintP is like Uint, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) UintP(name, shorthand string, value uint, usage string) *uint { 74 | p := new(uint) 75 | f.UintVarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Uint defines a uint flag with specified name, default value, and usage string. 80 | // The return value is the address of a uint variable that stores the value of the flag. 81 | func Uint(name string, value uint, usage string) *uint { 82 | return CommandLine.UintP(name, "", value, usage) 83 | } 84 | 85 | // UintP is like Uint, but accepts a shorthand letter that can be used after a single dash. 86 | func UintP(name, shorthand string, value uint, usage string) *uint { 87 | return CommandLine.UintP(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/uint16.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- uint16 value 6 | type uint16Value uint16 7 | 8 | func newUint16Value(val uint16, p *uint16) *uint16Value { 9 | *p = val 10 | return (*uint16Value)(p) 11 | } 12 | 13 | func (i *uint16Value) Set(s string) error { 14 | v, err := strconv.ParseUint(s, 0, 16) 15 | *i = uint16Value(v) 16 | return err 17 | } 18 | 19 | func (i *uint16Value) Type() string { 20 | return "uint16" 21 | } 22 | 23 | func (i *uint16Value) String() string { return strconv.FormatUint(uint64(*i), 10) } 24 | 25 | func uint16Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseUint(sval, 0, 16) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return uint16(v), nil 31 | } 32 | 33 | // GetUint16 return the uint16 value of a flag with the given name 34 | func (f *FlagSet) GetUint16(name string) (uint16, error) { 35 | val, err := f.getFlagType(name, "uint16", uint16Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(uint16), nil 40 | } 41 | 42 | // Uint16Var defines a uint flag with specified name, default value, and usage string. 43 | // The argument p points to a uint variable in which to store the value of the flag. 44 | func (f *FlagSet) Uint16Var(p *uint16, name string, value uint16, usage string) { 45 | f.VarP(newUint16Value(value, p), name, "", usage) 46 | } 47 | 48 | // Uint16VarP is like Uint16Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Uint16VarP(p *uint16, name, shorthand string, value uint16, usage string) { 50 | f.VarP(newUint16Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Uint16Var defines a uint flag with specified name, default value, and usage string. 54 | // The argument p points to a uint variable in which to store the value of the flag. 55 | func Uint16Var(p *uint16, name string, value uint16, usage string) { 56 | CommandLine.VarP(newUint16Value(value, p), name, "", usage) 57 | } 58 | 59 | // Uint16VarP is like Uint16Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Uint16VarP(p *uint16, name, shorthand string, value uint16, usage string) { 61 | CommandLine.VarP(newUint16Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Uint16 defines a uint flag with specified name, default value, and usage string. 65 | // The return value is the address of a uint variable that stores the value of the flag. 66 | func (f *FlagSet) Uint16(name string, value uint16, usage string) *uint16 { 67 | p := new(uint16) 68 | f.Uint16VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Uint16P is like Uint16, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Uint16P(name, shorthand string, value uint16, usage string) *uint16 { 74 | p := new(uint16) 75 | f.Uint16VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Uint16 defines a uint flag with specified name, default value, and usage string. 80 | // The return value is the address of a uint variable that stores the value of the flag. 81 | func Uint16(name string, value uint16, usage string) *uint16 { 82 | return CommandLine.Uint16P(name, "", value, usage) 83 | } 84 | 85 | // Uint16P is like Uint16, but accepts a shorthand letter that can be used after a single dash. 86 | func Uint16P(name, shorthand string, value uint16, usage string) *uint16 { 87 | return CommandLine.Uint16P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/uint32.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- uint32 value 6 | type uint32Value uint32 7 | 8 | func newUint32Value(val uint32, p *uint32) *uint32Value { 9 | *p = val 10 | return (*uint32Value)(p) 11 | } 12 | 13 | func (i *uint32Value) Set(s string) error { 14 | v, err := strconv.ParseUint(s, 0, 32) 15 | *i = uint32Value(v) 16 | return err 17 | } 18 | 19 | func (i *uint32Value) Type() string { 20 | return "uint32" 21 | } 22 | 23 | func (i *uint32Value) String() string { return strconv.FormatUint(uint64(*i), 10) } 24 | 25 | func uint32Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseUint(sval, 0, 32) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return uint32(v), nil 31 | } 32 | 33 | // GetUint32 return the uint32 value of a flag with the given name 34 | func (f *FlagSet) GetUint32(name string) (uint32, error) { 35 | val, err := f.getFlagType(name, "uint32", uint32Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(uint32), nil 40 | } 41 | 42 | // Uint32Var defines a uint32 flag with specified name, default value, and usage string. 43 | // The argument p points to a uint32 variable in which to store the value of the flag. 44 | func (f *FlagSet) Uint32Var(p *uint32, name string, value uint32, usage string) { 45 | f.VarP(newUint32Value(value, p), name, "", usage) 46 | } 47 | 48 | // Uint32VarP is like Uint32Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Uint32VarP(p *uint32, name, shorthand string, value uint32, usage string) { 50 | f.VarP(newUint32Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Uint32Var defines a uint32 flag with specified name, default value, and usage string. 54 | // The argument p points to a uint32 variable in which to store the value of the flag. 55 | func Uint32Var(p *uint32, name string, value uint32, usage string) { 56 | CommandLine.VarP(newUint32Value(value, p), name, "", usage) 57 | } 58 | 59 | // Uint32VarP is like Uint32Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Uint32VarP(p *uint32, name, shorthand string, value uint32, usage string) { 61 | CommandLine.VarP(newUint32Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Uint32 defines a uint32 flag with specified name, default value, and usage string. 65 | // The return value is the address of a uint32 variable that stores the value of the flag. 66 | func (f *FlagSet) Uint32(name string, value uint32, usage string) *uint32 { 67 | p := new(uint32) 68 | f.Uint32VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Uint32P is like Uint32, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Uint32P(name, shorthand string, value uint32, usage string) *uint32 { 74 | p := new(uint32) 75 | f.Uint32VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Uint32 defines a uint32 flag with specified name, default value, and usage string. 80 | // The return value is the address of a uint32 variable that stores the value of the flag. 81 | func Uint32(name string, value uint32, usage string) *uint32 { 82 | return CommandLine.Uint32P(name, "", value, usage) 83 | } 84 | 85 | // Uint32P is like Uint32, but accepts a shorthand letter that can be used after a single dash. 86 | func Uint32P(name, shorthand string, value uint32, usage string) *uint32 { 87 | return CommandLine.Uint32P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/uint64.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- uint64 Value 6 | type uint64Value uint64 7 | 8 | func newUint64Value(val uint64, p *uint64) *uint64Value { 9 | *p = val 10 | return (*uint64Value)(p) 11 | } 12 | 13 | func (i *uint64Value) Set(s string) error { 14 | v, err := strconv.ParseUint(s, 0, 64) 15 | *i = uint64Value(v) 16 | return err 17 | } 18 | 19 | func (i *uint64Value) Type() string { 20 | return "uint64" 21 | } 22 | 23 | func (i *uint64Value) String() string { return strconv.FormatUint(uint64(*i), 10) } 24 | 25 | func uint64Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseUint(sval, 0, 64) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return uint64(v), nil 31 | } 32 | 33 | // GetUint64 return the uint64 value of a flag with the given name 34 | func (f *FlagSet) GetUint64(name string) (uint64, error) { 35 | val, err := f.getFlagType(name, "uint64", uint64Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(uint64), nil 40 | } 41 | 42 | // Uint64Var defines a uint64 flag with specified name, default value, and usage string. 43 | // The argument p points to a uint64 variable in which to store the value of the flag. 44 | func (f *FlagSet) Uint64Var(p *uint64, name string, value uint64, usage string) { 45 | f.VarP(newUint64Value(value, p), name, "", usage) 46 | } 47 | 48 | // Uint64VarP is like Uint64Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Uint64VarP(p *uint64, name, shorthand string, value uint64, usage string) { 50 | f.VarP(newUint64Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Uint64Var defines a uint64 flag with specified name, default value, and usage string. 54 | // The argument p points to a uint64 variable in which to store the value of the flag. 55 | func Uint64Var(p *uint64, name string, value uint64, usage string) { 56 | CommandLine.VarP(newUint64Value(value, p), name, "", usage) 57 | } 58 | 59 | // Uint64VarP is like Uint64Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Uint64VarP(p *uint64, name, shorthand string, value uint64, usage string) { 61 | CommandLine.VarP(newUint64Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Uint64 defines a uint64 flag with specified name, default value, and usage string. 65 | // The return value is the address of a uint64 variable that stores the value of the flag. 66 | func (f *FlagSet) Uint64(name string, value uint64, usage string) *uint64 { 67 | p := new(uint64) 68 | f.Uint64VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Uint64P is like Uint64, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Uint64P(name, shorthand string, value uint64, usage string) *uint64 { 74 | p := new(uint64) 75 | f.Uint64VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Uint64 defines a uint64 flag with specified name, default value, and usage string. 80 | // The return value is the address of a uint64 variable that stores the value of the flag. 81 | func Uint64(name string, value uint64, usage string) *uint64 { 82 | return CommandLine.Uint64P(name, "", value, usage) 83 | } 84 | 85 | // Uint64P is like Uint64, but accepts a shorthand letter that can be used after a single dash. 86 | func Uint64P(name, shorthand string, value uint64, usage string) *uint64 { 87 | return CommandLine.Uint64P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/uint8.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- uint8 Value 6 | type uint8Value uint8 7 | 8 | func newUint8Value(val uint8, p *uint8) *uint8Value { 9 | *p = val 10 | return (*uint8Value)(p) 11 | } 12 | 13 | func (i *uint8Value) Set(s string) error { 14 | v, err := strconv.ParseUint(s, 0, 8) 15 | *i = uint8Value(v) 16 | return err 17 | } 18 | 19 | func (i *uint8Value) Type() string { 20 | return "uint8" 21 | } 22 | 23 | func (i *uint8Value) String() string { return strconv.FormatUint(uint64(*i), 10) } 24 | 25 | func uint8Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseUint(sval, 0, 8) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return uint8(v), nil 31 | } 32 | 33 | // GetUint8 return the uint8 value of a flag with the given name 34 | func (f *FlagSet) GetUint8(name string) (uint8, error) { 35 | val, err := f.getFlagType(name, "uint8", uint8Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(uint8), nil 40 | } 41 | 42 | // Uint8Var defines a uint8 flag with specified name, default value, and usage string. 43 | // The argument p points to a uint8 variable in which to store the value of the flag. 44 | func (f *FlagSet) Uint8Var(p *uint8, name string, value uint8, usage string) { 45 | f.VarP(newUint8Value(value, p), name, "", usage) 46 | } 47 | 48 | // Uint8VarP is like Uint8Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Uint8VarP(p *uint8, name, shorthand string, value uint8, usage string) { 50 | f.VarP(newUint8Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Uint8Var defines a uint8 flag with specified name, default value, and usage string. 54 | // The argument p points to a uint8 variable in which to store the value of the flag. 55 | func Uint8Var(p *uint8, name string, value uint8, usage string) { 56 | CommandLine.VarP(newUint8Value(value, p), name, "", usage) 57 | } 58 | 59 | // Uint8VarP is like Uint8Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Uint8VarP(p *uint8, name, shorthand string, value uint8, usage string) { 61 | CommandLine.VarP(newUint8Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Uint8 defines a uint8 flag with specified name, default value, and usage string. 65 | // The return value is the address of a uint8 variable that stores the value of the flag. 66 | func (f *FlagSet) Uint8(name string, value uint8, usage string) *uint8 { 67 | p := new(uint8) 68 | f.Uint8VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Uint8P is like Uint8, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Uint8P(name, shorthand string, value uint8, usage string) *uint8 { 74 | p := new(uint8) 75 | f.Uint8VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Uint8 defines a uint8 flag with specified name, default value, and usage string. 80 | // The return value is the address of a uint8 variable that stores the value of the flag. 81 | func Uint8(name string, value uint8, usage string) *uint8 { 82 | return CommandLine.Uint8P(name, "", value, usage) 83 | } 84 | 85 | // Uint8P is like Uint8, but accepts a shorthand letter that can be used after a single dash. 86 | func Uint8P(name, shorthand string, value uint8, usage string) *uint8 { 87 | return CommandLine.Uint8P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/AUTHORS: -------------------------------------------------------------------------------- 1 | # This source code refers to The Go Authors for copyright purposes. 2 | # The master list of authors is in the main Go distribution, 3 | # visible at http://tip.golang.org/AUTHORS. 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # This source code was written by the Go contributors. 2 | # The master list of contributors is in the main Go distribution, 3 | # visible at http://tip.golang.org/CONTRIBUTORS. 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/PATENTS: -------------------------------------------------------------------------------- 1 | Additional IP Rights Grant (Patents) 2 | 3 | "This implementation" means the copyrightable works distributed by 4 | Google as part of the Go project. 5 | 6 | Google hereby grants to You a perpetual, worldwide, non-exclusive, 7 | no-charge, royalty-free, irrevocable (except as stated in this section) 8 | patent license to make, have made, use, offer to sell, sell, import, 9 | transfer and otherwise run, modify and propagate the contents of this 10 | implementation of Go, where such license applies only to those patent 11 | claims, both currently owned or controlled by Google and acquired in 12 | the future, licensable by Google that are necessarily infringed by this 13 | implementation of Go. This grant does not include claims that would be 14 | infringed only as a consequence of further modification of this 15 | implementation. If you or your agent or exclusive licensee institute or 16 | order or agree to the institution of patent litigation against any 17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging 18 | that this implementation of Go or any code incorporated within this 19 | implementation of Go constitutes direct or contributory patent 20 | infringement, or inducement of patent infringement, then any patent 21 | rights granted to you under this License for this implementation of Go 22 | shall terminate as of the date such litigation is filed. 23 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/idna/trie.go: -------------------------------------------------------------------------------- 1 | // Code generated by running "go generate" in golang.org/x/text. DO NOT EDIT. 2 | 3 | // Copyright 2016 The Go Authors. All rights reserved. 4 | // Use of this source code is governed by a BSD-style 5 | // license that can be found in the LICENSE file. 6 | 7 | package idna 8 | 9 | // appendMapping appends the mapping for the respective rune. isMapped must be 10 | // true. A mapping is a categorization of a rune as defined in UTS #46. 11 | func (c info) appendMapping(b []byte, s string) []byte { 12 | index := int(c >> indexShift) 13 | if c&xorBit == 0 { 14 | s := mappings[index:] 15 | return append(b, s[1:s[0]+1]...) 16 | } 17 | b = append(b, s...) 18 | if c&inlineXOR == inlineXOR { 19 | // TODO: support and handle two-byte inline masks 20 | b[len(b)-1] ^= byte(index) 21 | } else { 22 | for p := len(b) - int(xorData[index]); p < len(b); p++ { 23 | index++ 24 | b[p] ^= xorData[index] 25 | } 26 | } 27 | return b 28 | } 29 | 30 | // Sparse block handling code. 31 | 32 | type valueRange struct { 33 | value uint16 // header: value:stride 34 | lo, hi byte // header: lo:n 35 | } 36 | 37 | type sparseBlocks struct { 38 | values []valueRange 39 | offset []uint16 40 | } 41 | 42 | var idnaSparse = sparseBlocks{ 43 | values: idnaSparseValues[:], 44 | offset: idnaSparseOffset[:], 45 | } 46 | 47 | // Don't use newIdnaTrie to avoid unconditional linking in of the table. 48 | var trie = &idnaTrie{} 49 | 50 | // lookup determines the type of block n and looks up the value for b. 51 | // For n < t.cutoff, the block is a simple lookup table. Otherwise, the block 52 | // is a list of ranges with an accompanying value. Given a matching range r, 53 | // the value for b is by r.value + (b - r.lo) * stride. 54 | func (t *sparseBlocks) lookup(n uint32, b byte) uint16 { 55 | offset := t.offset[n] 56 | header := t.values[offset] 57 | lo := offset + 1 58 | hi := lo + uint16(header.lo) 59 | for lo < hi { 60 | m := lo + (hi-lo)/2 61 | r := t.values[m] 62 | if r.lo <= b && b <= r.hi { 63 | return r.value + uint16(b-r.lo)*header.value 64 | } 65 | if b < r.lo { 66 | hi = m 67 | } else { 68 | lo = m + 1 69 | } 70 | } 71 | return 0 72 | } 73 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/idna/trieval.go: -------------------------------------------------------------------------------- 1 | // Code generated by running "go generate" in golang.org/x/text. DO NOT EDIT. 2 | 3 | package idna 4 | 5 | // This file contains definitions for interpreting the trie value of the idna 6 | // trie generated by "go run gen*.go". It is shared by both the generator 7 | // program and the resultant package. Sharing is achieved by the generator 8 | // copying gen_trieval.go to trieval.go and changing what's above this comment. 9 | 10 | // info holds information from the IDNA mapping table for a single rune. It is 11 | // the value returned by a trie lookup. In most cases, all information fits in 12 | // a 16-bit value. For mappings, this value may contain an index into a slice 13 | // with the mapped string. Such mappings can consist of the actual mapped value 14 | // or an XOR pattern to be applied to the bytes of the UTF8 encoding of the 15 | // input rune. This technique is used by the cases packages and reduces the 16 | // table size significantly. 17 | // 18 | // The per-rune values have the following format: 19 | // 20 | // if mapped { 21 | // if inlinedXOR { 22 | // 15..13 inline XOR marker 23 | // 12..11 unused 24 | // 10..3 inline XOR mask 25 | // } else { 26 | // 15..3 index into xor or mapping table 27 | // } 28 | // } else { 29 | // 15..14 unused 30 | // 13 mayNeedNorm 31 | // 12..11 attributes 32 | // 10..8 joining type 33 | // 7..3 category type 34 | // } 35 | // 2 use xor pattern 36 | // 1..0 mapped category 37 | // 38 | // See the definitions below for a more detailed description of the various 39 | // bits. 40 | type info uint16 41 | 42 | const ( 43 | catSmallMask = 0x3 44 | catBigMask = 0xF8 45 | indexShift = 3 46 | xorBit = 0x4 // interpret the index as an xor pattern 47 | inlineXOR = 0xE000 // These bits are set if the XOR pattern is inlined. 48 | 49 | joinShift = 8 50 | joinMask = 0x07 51 | 52 | // Attributes 53 | attributesMask = 0x1800 54 | viramaModifier = 0x1800 55 | modifier = 0x1000 56 | rtl = 0x0800 57 | 58 | mayNeedNorm = 0x2000 59 | ) 60 | 61 | // A category corresponds to a category defined in the IDNA mapping table. 62 | type category uint16 63 | 64 | const ( 65 | unknown category = 0 // not currently defined in unicode. 66 | mapped category = 1 67 | disallowedSTD3Mapped category = 2 68 | deviation category = 3 69 | ) 70 | 71 | const ( 72 | valid category = 0x08 73 | validNV8 category = 0x18 74 | validXV8 category = 0x28 75 | disallowed category = 0x40 76 | disallowedSTD3Valid category = 0x80 77 | ignored category = 0xC0 78 | ) 79 | 80 | // join types and additional rune information 81 | const ( 82 | joiningL = (iota + 1) 83 | joiningD 84 | joiningT 85 | joiningR 86 | 87 | //the following types are derived during processing 88 | joinZWJ 89 | joinZWNJ 90 | joinVirama 91 | numJoinTypes 92 | ) 93 | 94 | func (c info) isMapped() bool { 95 | return c&0x3 != 0 96 | } 97 | 98 | func (c info) category() category { 99 | small := c & catSmallMask 100 | if small != 0 { 101 | return category(small) 102 | } 103 | return category(c & catBigMask) 104 | } 105 | 106 | func (c info) joinType() info { 107 | if c.isMapped() { 108 | return 0 109 | } 110 | return (c >> joinShift) & joinMask 111 | } 112 | 113 | func (c info) isModifier() bool { 114 | return c&(modifier|catSmallMask) == modifier 115 | } 116 | 117 | func (c info) isViramaModifier() bool { 118 | return c&(attributesMask|catSmallMask) == viramaModifier 119 | } 120 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/AUTHORS: -------------------------------------------------------------------------------- 1 | # This source code refers to The Go Authors for copyright purposes. 2 | # The master list of authors is in the main Go distribution, 3 | # visible at http://tip.golang.org/AUTHORS. 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # This source code was written by the Go contributors. 2 | # The master list of contributors is in the main Go distribution, 3 | # visible at http://tip.golang.org/CONTRIBUTORS. 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/PATENTS: -------------------------------------------------------------------------------- 1 | Additional IP Rights Grant (Patents) 2 | 3 | "This implementation" means the copyrightable works distributed by 4 | Google as part of the Go project. 5 | 6 | Google hereby grants to You a perpetual, worldwide, non-exclusive, 7 | no-charge, royalty-free, irrevocable (except as stated in this section) 8 | patent license to make, have made, use, offer to sell, sell, import, 9 | transfer and otherwise run, modify and propagate the contents of this 10 | implementation of Go, where such license applies only to those patent 11 | claims, both currently owned or controlled by Google and acquired in 12 | the future, licensable by Google that are necessarily infringed by this 13 | implementation of Go. This grant does not include claims that would be 14 | infringed only as a consequence of further modification of this 15 | implementation. If you or your agent or exclusive licensee institute or 16 | order or agree to the institution of patent litigation against any 17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging 18 | that this implementation of Go or any code incorporated within this 19 | implementation of Go constitutes direct or contributory patent 20 | infringement, or inducement of patent infringement, then any patent 21 | rights granted to you under this License for this implementation of Go 22 | shall terminate as of the date such litigation is filed. 23 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/secure/bidirule/bidirule10.0.0.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build go1.10 6 | 7 | package bidirule 8 | 9 | func (t *Transformer) isFinal() bool { 10 | return t.state == ruleLTRFinal || t.state == ruleRTLFinal || t.state == ruleInitial 11 | } 12 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/secure/bidirule/bidirule9.0.0.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !go1.10 6 | 7 | package bidirule 8 | 9 | func (t *Transformer) isFinal() bool { 10 | if !t.isRTL() { 11 | return true 12 | } 13 | return t.state == ruleLTRFinal || t.state == ruleRTLFinal || t.state == ruleInitial 14 | } 15 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/unicode/bidi/trieval.go: -------------------------------------------------------------------------------- 1 | // Code generated by running "go generate" in golang.org/x/text. DO NOT EDIT. 2 | 3 | package bidi 4 | 5 | // Class is the Unicode BiDi class. Each rune has a single class. 6 | type Class uint 7 | 8 | const ( 9 | L Class = iota // LeftToRight 10 | R // RightToLeft 11 | EN // EuropeanNumber 12 | ES // EuropeanSeparator 13 | ET // EuropeanTerminator 14 | AN // ArabicNumber 15 | CS // CommonSeparator 16 | B // ParagraphSeparator 17 | S // SegmentSeparator 18 | WS // WhiteSpace 19 | ON // OtherNeutral 20 | BN // BoundaryNeutral 21 | NSM // NonspacingMark 22 | AL // ArabicLetter 23 | Control // Control LRO - PDI 24 | 25 | numClass 26 | 27 | LRO // LeftToRightOverride 28 | RLO // RightToLeftOverride 29 | LRE // LeftToRightEmbedding 30 | RLE // RightToLeftEmbedding 31 | PDF // PopDirectionalFormat 32 | LRI // LeftToRightIsolate 33 | RLI // RightToLeftIsolate 34 | FSI // FirstStrongIsolate 35 | PDI // PopDirectionalIsolate 36 | 37 | unknownClass = ^Class(0) 38 | ) 39 | 40 | var controlToClass = map[rune]Class{ 41 | 0x202D: LRO, // LeftToRightOverride, 42 | 0x202E: RLO, // RightToLeftOverride, 43 | 0x202A: LRE, // LeftToRightEmbedding, 44 | 0x202B: RLE, // RightToLeftEmbedding, 45 | 0x202C: PDF, // PopDirectionalFormat, 46 | 0x2066: LRI, // LeftToRightIsolate, 47 | 0x2067: RLI, // RightToLeftIsolate, 48 | 0x2068: FSI, // FirstStrongIsolate, 49 | 0x2069: PDI, // PopDirectionalIsolate, 50 | } 51 | 52 | // A trie entry has the following bits: 53 | // 7..5 XOR mask for brackets 54 | // 4 1: Bracket open, 0: Bracket close 55 | // 3..0 Class type 56 | 57 | const ( 58 | openMask = 0x10 59 | xorMaskShift = 5 60 | ) 61 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/unicode/norm/input.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package norm 6 | 7 | import "unicode/utf8" 8 | 9 | type input struct { 10 | str string 11 | bytes []byte 12 | } 13 | 14 | func inputBytes(str []byte) input { 15 | return input{bytes: str} 16 | } 17 | 18 | func inputString(str string) input { 19 | return input{str: str} 20 | } 21 | 22 | func (in *input) setBytes(str []byte) { 23 | in.str = "" 24 | in.bytes = str 25 | } 26 | 27 | func (in *input) setString(str string) { 28 | in.str = str 29 | in.bytes = nil 30 | } 31 | 32 | func (in *input) _byte(p int) byte { 33 | if in.bytes == nil { 34 | return in.str[p] 35 | } 36 | return in.bytes[p] 37 | } 38 | 39 | func (in *input) skipASCII(p, max int) int { 40 | if in.bytes == nil { 41 | for ; p < max && in.str[p] < utf8.RuneSelf; p++ { 42 | } 43 | } else { 44 | for ; p < max && in.bytes[p] < utf8.RuneSelf; p++ { 45 | } 46 | } 47 | return p 48 | } 49 | 50 | func (in *input) skipContinuationBytes(p int) int { 51 | if in.bytes == nil { 52 | for ; p < len(in.str) && !utf8.RuneStart(in.str[p]); p++ { 53 | } 54 | } else { 55 | for ; p < len(in.bytes) && !utf8.RuneStart(in.bytes[p]); p++ { 56 | } 57 | } 58 | return p 59 | } 60 | 61 | func (in *input) appendSlice(buf []byte, b, e int) []byte { 62 | if in.bytes != nil { 63 | return append(buf, in.bytes[b:e]...) 64 | } 65 | for i := b; i < e; i++ { 66 | buf = append(buf, in.str[i]) 67 | } 68 | return buf 69 | } 70 | 71 | func (in *input) copySlice(buf []byte, b, e int) int { 72 | if in.bytes == nil { 73 | return copy(buf, in.str[b:e]) 74 | } 75 | return copy(buf, in.bytes[b:e]) 76 | } 77 | 78 | func (in *input) charinfoNFC(p int) (uint16, int) { 79 | if in.bytes == nil { 80 | return nfcData.lookupString(in.str[p:]) 81 | } 82 | return nfcData.lookup(in.bytes[p:]) 83 | } 84 | 85 | func (in *input) charinfoNFKC(p int) (uint16, int) { 86 | if in.bytes == nil { 87 | return nfkcData.lookupString(in.str[p:]) 88 | } 89 | return nfkcData.lookup(in.bytes[p:]) 90 | } 91 | 92 | func (in *input) hangul(p int) (r rune) { 93 | var size int 94 | if in.bytes == nil { 95 | if !isHangulString(in.str[p:]) { 96 | return 0 97 | } 98 | r, size = utf8.DecodeRuneInString(in.str[p:]) 99 | } else { 100 | if !isHangul(in.bytes[p:]) { 101 | return 0 102 | } 103 | r, size = utf8.DecodeRune(in.bytes[p:]) 104 | } 105 | if size != hangulUTF8Size { 106 | return 0 107 | } 108 | return r 109 | } 110 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/unicode/norm/readwriter.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package norm 6 | 7 | import "io" 8 | 9 | type normWriter struct { 10 | rb reorderBuffer 11 | w io.Writer 12 | buf []byte 13 | } 14 | 15 | // Write implements the standard write interface. If the last characters are 16 | // not at a normalization boundary, the bytes will be buffered for the next 17 | // write. The remaining bytes will be written on close. 18 | func (w *normWriter) Write(data []byte) (n int, err error) { 19 | // Process data in pieces to keep w.buf size bounded. 20 | const chunk = 4000 21 | 22 | for len(data) > 0 { 23 | // Normalize into w.buf. 24 | m := len(data) 25 | if m > chunk { 26 | m = chunk 27 | } 28 | w.rb.src = inputBytes(data[:m]) 29 | w.rb.nsrc = m 30 | w.buf = doAppend(&w.rb, w.buf, 0) 31 | data = data[m:] 32 | n += m 33 | 34 | // Write out complete prefix, save remainder. 35 | // Note that lastBoundary looks back at most 31 runes. 36 | i := lastBoundary(&w.rb.f, w.buf) 37 | if i == -1 { 38 | i = 0 39 | } 40 | if i > 0 { 41 | if _, err = w.w.Write(w.buf[:i]); err != nil { 42 | break 43 | } 44 | bn := copy(w.buf, w.buf[i:]) 45 | w.buf = w.buf[:bn] 46 | } 47 | } 48 | return n, err 49 | } 50 | 51 | // Close forces data that remains in the buffer to be written. 52 | func (w *normWriter) Close() error { 53 | if len(w.buf) > 0 { 54 | _, err := w.w.Write(w.buf) 55 | if err != nil { 56 | return err 57 | } 58 | } 59 | return nil 60 | } 61 | 62 | // Writer returns a new writer that implements Write(b) 63 | // by writing f(b) to w. The returned writer may use an 64 | // an internal buffer to maintain state across Write calls. 65 | // Calling its Close method writes any buffered data to w. 66 | func (f Form) Writer(w io.Writer) io.WriteCloser { 67 | wr := &normWriter{rb: reorderBuffer{}, w: w} 68 | wr.rb.init(f, nil) 69 | return wr 70 | } 71 | 72 | type normReader struct { 73 | rb reorderBuffer 74 | r io.Reader 75 | inbuf []byte 76 | outbuf []byte 77 | bufStart int 78 | lastBoundary int 79 | err error 80 | } 81 | 82 | // Read implements the standard read interface. 83 | func (r *normReader) Read(p []byte) (int, error) { 84 | for { 85 | if r.lastBoundary-r.bufStart > 0 { 86 | n := copy(p, r.outbuf[r.bufStart:r.lastBoundary]) 87 | r.bufStart += n 88 | if r.lastBoundary-r.bufStart > 0 { 89 | return n, nil 90 | } 91 | return n, r.err 92 | } 93 | if r.err != nil { 94 | return 0, r.err 95 | } 96 | outn := copy(r.outbuf, r.outbuf[r.lastBoundary:]) 97 | r.outbuf = r.outbuf[0:outn] 98 | r.bufStart = 0 99 | 100 | n, err := r.r.Read(r.inbuf) 101 | r.rb.src = inputBytes(r.inbuf[0:n]) 102 | r.rb.nsrc, r.err = n, err 103 | if n > 0 { 104 | r.outbuf = doAppend(&r.rb, r.outbuf, 0) 105 | } 106 | if err == io.EOF { 107 | r.lastBoundary = len(r.outbuf) 108 | } else { 109 | r.lastBoundary = lastBoundary(&r.rb.f, r.outbuf) 110 | if r.lastBoundary == -1 { 111 | r.lastBoundary = 0 112 | } 113 | } 114 | } 115 | } 116 | 117 | // Reader returns a new reader that implements Read 118 | // by reading data from r and returning f(data). 119 | func (f Form) Reader(r io.Reader) io.Reader { 120 | const chunk = 4000 121 | buf := make([]byte, chunk) 122 | rr := &normReader{rb: reorderBuffer{}, r: r, inbuf: buf} 123 | rr.rb.init(f, buf) 124 | return rr 125 | } 126 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/unicode/norm/transform.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package norm 6 | 7 | import ( 8 | "unicode/utf8" 9 | 10 | "golang.org/x/text/transform" 11 | ) 12 | 13 | // Reset implements the Reset method of the transform.Transformer interface. 14 | func (Form) Reset() {} 15 | 16 | // Transform implements the Transform method of the transform.Transformer 17 | // interface. It may need to write segments of up to MaxSegmentSize at once. 18 | // Users should either catch ErrShortDst and allow dst to grow or have dst be at 19 | // least of size MaxTransformChunkSize to be guaranteed of progress. 20 | func (f Form) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) { 21 | n := 0 22 | // Cap the maximum number of src bytes to check. 23 | b := src 24 | eof := atEOF 25 | if ns := len(dst); ns < len(b) { 26 | err = transform.ErrShortDst 27 | eof = false 28 | b = b[:ns] 29 | } 30 | i, ok := formTable[f].quickSpan(inputBytes(b), n, len(b), eof) 31 | n += copy(dst[n:], b[n:i]) 32 | if !ok { 33 | nDst, nSrc, err = f.transform(dst[n:], src[n:], atEOF) 34 | return nDst + n, nSrc + n, err 35 | } 36 | if n < len(src) && !atEOF { 37 | err = transform.ErrShortSrc 38 | } 39 | return n, n, err 40 | } 41 | 42 | func flushTransform(rb *reorderBuffer) bool { 43 | // Write out (must fully fit in dst, or else it is an ErrShortDst). 44 | if len(rb.out) < rb.nrune*utf8.UTFMax { 45 | return false 46 | } 47 | rb.out = rb.out[rb.flushCopy(rb.out):] 48 | return true 49 | } 50 | 51 | var errs = []error{nil, transform.ErrShortDst, transform.ErrShortSrc} 52 | 53 | // transform implements the transform.Transformer interface. It is only called 54 | // when quickSpan does not pass for a given string. 55 | func (f Form) transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) { 56 | // TODO: get rid of reorderBuffer. See CL 23460044. 57 | rb := reorderBuffer{} 58 | rb.init(f, src) 59 | for { 60 | // Load segment into reorder buffer. 61 | rb.setFlusher(dst[nDst:], flushTransform) 62 | end := decomposeSegment(&rb, nSrc, atEOF) 63 | if end < 0 { 64 | return nDst, nSrc, errs[-end] 65 | } 66 | nDst = len(dst) - len(rb.out) 67 | nSrc = end 68 | 69 | // Next quickSpan. 70 | end = rb.nsrc 71 | eof := atEOF 72 | if n := nSrc + len(dst) - nDst; n < end { 73 | err = transform.ErrShortDst 74 | end = n 75 | eof = false 76 | } 77 | end, ok := rb.f.quickSpan(rb.src, nSrc, end, eof) 78 | n := copy(dst[nDst:], rb.src.bytes[nSrc:end]) 79 | nSrc += n 80 | nDst += n 81 | if ok { 82 | if n < rb.nsrc && !atEOF { 83 | err = transform.ErrShortSrc 84 | } 85 | return nDst, nSrc, err 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/unicode/norm/trie.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package norm 6 | 7 | type valueRange struct { 8 | value uint16 // header: value:stride 9 | lo, hi byte // header: lo:n 10 | } 11 | 12 | type sparseBlocks struct { 13 | values []valueRange 14 | offset []uint16 15 | } 16 | 17 | var nfcSparse = sparseBlocks{ 18 | values: nfcSparseValues[:], 19 | offset: nfcSparseOffset[:], 20 | } 21 | 22 | var nfkcSparse = sparseBlocks{ 23 | values: nfkcSparseValues[:], 24 | offset: nfkcSparseOffset[:], 25 | } 26 | 27 | var ( 28 | nfcData = newNfcTrie(0) 29 | nfkcData = newNfkcTrie(0) 30 | ) 31 | 32 | // lookupValue determines the type of block n and looks up the value for b. 33 | // For n < t.cutoff, the block is a simple lookup table. Otherwise, the block 34 | // is a list of ranges with an accompanying value. Given a matching range r, 35 | // the value for b is by r.value + (b - r.lo) * stride. 36 | func (t *sparseBlocks) lookup(n uint32, b byte) uint16 { 37 | offset := t.offset[n] 38 | header := t.values[offset] 39 | lo := offset + 1 40 | hi := lo + uint16(header.lo) 41 | for lo < hi { 42 | m := lo + (hi-lo)/2 43 | r := t.values[m] 44 | if r.lo <= b && b <= r.hi { 45 | return r.value + uint16(b-r.lo)*header.value 46 | } 47 | if b < r.lo { 48 | hi = m 49 | } else { 50 | lo = m + 1 51 | } 52 | } 53 | return 0 54 | } 55 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v2/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.4 5 | - 1.5 6 | - 1.6 7 | - tip 8 | 9 | go_import_path: gopkg.in/yaml.v2 10 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v2/LICENSE.libyaml: -------------------------------------------------------------------------------- 1 | The following files were ported to Go from C files of libyaml, and thus 2 | are still covered by their original copyright and license: 3 | 4 | apic.go 5 | emitterc.go 6 | parserc.go 7 | readerc.go 8 | scannerc.go 9 | writerc.go 10 | yamlh.go 11 | yamlprivateh.go 12 | 13 | Copyright (c) 2006 Kirill Simonov 14 | 15 | Permission is hereby granted, free of charge, to any person obtaining a copy of 16 | this software and associated documentation files (the "Software"), to deal in 17 | the Software without restriction, including without limitation the rights to 18 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 19 | of the Software, and to permit persons to whom the Software is furnished to do 20 | so, subject to the following conditions: 21 | 22 | The above copyright notice and this permission notice shall be included in all 23 | copies or substantial portions of the Software. 24 | 25 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 26 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 27 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 28 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 29 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 30 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 31 | SOFTWARE. 32 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v2/README.md: -------------------------------------------------------------------------------- 1 | # YAML support for the Go language 2 | 3 | Introduction 4 | ------------ 5 | 6 | The yaml package enables Go programs to comfortably encode and decode YAML 7 | values. It was developed within [Canonical](https://www.canonical.com) as 8 | part of the [juju](https://juju.ubuntu.com) project, and is based on a 9 | pure Go port of the well-known [libyaml](http://pyyaml.org/wiki/LibYAML) 10 | C library to parse and generate YAML data quickly and reliably. 11 | 12 | Compatibility 13 | ------------- 14 | 15 | The yaml package supports most of YAML 1.1 and 1.2, including support for 16 | anchors, tags, map merging, etc. Multi-document unmarshalling is not yet 17 | implemented, and base-60 floats from YAML 1.1 are purposefully not 18 | supported since they're a poor design and are gone in YAML 1.2. 19 | 20 | Installation and usage 21 | ---------------------- 22 | 23 | The import path for the package is *gopkg.in/yaml.v2*. 24 | 25 | To install it, run: 26 | 27 | go get gopkg.in/yaml.v2 28 | 29 | API documentation 30 | ----------------- 31 | 32 | If opened in a browser, the import path itself leads to the API documentation: 33 | 34 | * [https://gopkg.in/yaml.v2](https://gopkg.in/yaml.v2) 35 | 36 | API stability 37 | ------------- 38 | 39 | The package API for yaml v2 will remain stable as described in [gopkg.in](https://gopkg.in). 40 | 41 | 42 | License 43 | ------- 44 | 45 | The yaml package is licensed under the Apache License 2.0. Please see the LICENSE file for details. 46 | 47 | 48 | Example 49 | ------- 50 | 51 | Some more examples can be found in the "examples" folder. 52 | 53 | ```Go 54 | package main 55 | 56 | import ( 57 | "fmt" 58 | "log" 59 | 60 | "gopkg.in/yaml.v2" 61 | ) 62 | 63 | var data = ` 64 | a: Easy! 65 | b: 66 | c: 2 67 | d: [3, 4] 68 | ` 69 | 70 | type T struct { 71 | A string 72 | B struct { 73 | RenamedC int `yaml:"c"` 74 | D []int `yaml:",flow"` 75 | } 76 | } 77 | 78 | func main() { 79 | t := T{} 80 | 81 | err := yaml.Unmarshal([]byte(data), &t) 82 | if err != nil { 83 | log.Fatalf("error: %v", err) 84 | } 85 | fmt.Printf("--- t:\n%v\n\n", t) 86 | 87 | d, err := yaml.Marshal(&t) 88 | if err != nil { 89 | log.Fatalf("error: %v", err) 90 | } 91 | fmt.Printf("--- t dump:\n%s\n\n", string(d)) 92 | 93 | m := make(map[interface{}]interface{}) 94 | 95 | err = yaml.Unmarshal([]byte(data), &m) 96 | if err != nil { 97 | log.Fatalf("error: %v", err) 98 | } 99 | fmt.Printf("--- m:\n%v\n\n", m) 100 | 101 | d, err = yaml.Marshal(&m) 102 | if err != nil { 103 | log.Fatalf("error: %v", err) 104 | } 105 | fmt.Printf("--- m dump:\n%s\n\n", string(d)) 106 | } 107 | ``` 108 | 109 | This example will generate the following output: 110 | 111 | ``` 112 | --- t: 113 | {Easy! {2 [3 4]}} 114 | 115 | --- t dump: 116 | a: Easy! 117 | b: 118 | c: 2 119 | d: [3, 4] 120 | 121 | 122 | --- m: 123 | map[a:Easy! b:map[c:2 d:[3 4]]] 124 | 125 | --- m dump: 126 | a: Easy! 127 | b: 128 | c: 2 129 | d: 130 | - 3 131 | - 4 132 | ``` 133 | 134 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v2/sorter.go: -------------------------------------------------------------------------------- 1 | package yaml 2 | 3 | import ( 4 | "reflect" 5 | "unicode" 6 | ) 7 | 8 | type keyList []reflect.Value 9 | 10 | func (l keyList) Len() int { return len(l) } 11 | func (l keyList) Swap(i, j int) { l[i], l[j] = l[j], l[i] } 12 | func (l keyList) Less(i, j int) bool { 13 | a := l[i] 14 | b := l[j] 15 | ak := a.Kind() 16 | bk := b.Kind() 17 | for (ak == reflect.Interface || ak == reflect.Ptr) && !a.IsNil() { 18 | a = a.Elem() 19 | ak = a.Kind() 20 | } 21 | for (bk == reflect.Interface || bk == reflect.Ptr) && !b.IsNil() { 22 | b = b.Elem() 23 | bk = b.Kind() 24 | } 25 | af, aok := keyFloat(a) 26 | bf, bok := keyFloat(b) 27 | if aok && bok { 28 | if af != bf { 29 | return af < bf 30 | } 31 | if ak != bk { 32 | return ak < bk 33 | } 34 | return numLess(a, b) 35 | } 36 | if ak != reflect.String || bk != reflect.String { 37 | return ak < bk 38 | } 39 | ar, br := []rune(a.String()), []rune(b.String()) 40 | for i := 0; i < len(ar) && i < len(br); i++ { 41 | if ar[i] == br[i] { 42 | continue 43 | } 44 | al := unicode.IsLetter(ar[i]) 45 | bl := unicode.IsLetter(br[i]) 46 | if al && bl { 47 | return ar[i] < br[i] 48 | } 49 | if al || bl { 50 | return bl 51 | } 52 | var ai, bi int 53 | var an, bn int64 54 | for ai = i; ai < len(ar) && unicode.IsDigit(ar[ai]); ai++ { 55 | an = an*10 + int64(ar[ai]-'0') 56 | } 57 | for bi = i; bi < len(br) && unicode.IsDigit(br[bi]); bi++ { 58 | bn = bn*10 + int64(br[bi]-'0') 59 | } 60 | if an != bn { 61 | return an < bn 62 | } 63 | if ai != bi { 64 | return ai < bi 65 | } 66 | return ar[i] < br[i] 67 | } 68 | return len(ar) < len(br) 69 | } 70 | 71 | // keyFloat returns a float value for v if it is a number/bool 72 | // and whether it is a number/bool or not. 73 | func keyFloat(v reflect.Value) (f float64, ok bool) { 74 | switch v.Kind() { 75 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: 76 | return float64(v.Int()), true 77 | case reflect.Float32, reflect.Float64: 78 | return v.Float(), true 79 | case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: 80 | return float64(v.Uint()), true 81 | case reflect.Bool: 82 | if v.Bool() { 83 | return 1, true 84 | } 85 | return 0, true 86 | } 87 | return 0, false 88 | } 89 | 90 | // numLess returns whether a < b. 91 | // a and b must necessarily have the same kind. 92 | func numLess(a, b reflect.Value) bool { 93 | switch a.Kind() { 94 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: 95 | return a.Int() < b.Int() 96 | case reflect.Float32, reflect.Float64: 97 | return a.Float() < b.Float() 98 | case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: 99 | return a.Uint() < b.Uint() 100 | case reflect.Bool: 101 | return !a.Bool() && b.Bool() 102 | } 103 | panic("not a number") 104 | } 105 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v2/writerc.go: -------------------------------------------------------------------------------- 1 | package yaml 2 | 3 | // Set the writer error and return false. 4 | func yaml_emitter_set_writer_error(emitter *yaml_emitter_t, problem string) bool { 5 | emitter.error = yaml_WRITER_ERROR 6 | emitter.problem = problem 7 | return false 8 | } 9 | 10 | // Flush the output buffer. 11 | func yaml_emitter_flush(emitter *yaml_emitter_t) bool { 12 | if emitter.write_handler == nil { 13 | panic("write handler not set") 14 | } 15 | 16 | // Check if the buffer is empty. 17 | if emitter.buffer_pos == 0 { 18 | return true 19 | } 20 | 21 | // If the output encoding is UTF-8, we don't need to recode the buffer. 22 | if emitter.encoding == yaml_UTF8_ENCODING { 23 | if err := emitter.write_handler(emitter, emitter.buffer[:emitter.buffer_pos]); err != nil { 24 | return yaml_emitter_set_writer_error(emitter, "write error: "+err.Error()) 25 | } 26 | emitter.buffer_pos = 0 27 | return true 28 | } 29 | 30 | // Recode the buffer into the raw buffer. 31 | var low, high int 32 | if emitter.encoding == yaml_UTF16LE_ENCODING { 33 | low, high = 0, 1 34 | } else { 35 | high, low = 1, 0 36 | } 37 | 38 | pos := 0 39 | for pos < emitter.buffer_pos { 40 | // See the "reader.c" code for more details on UTF-8 encoding. Note 41 | // that we assume that the buffer contains a valid UTF-8 sequence. 42 | 43 | // Read the next UTF-8 character. 44 | octet := emitter.buffer[pos] 45 | 46 | var w int 47 | var value rune 48 | switch { 49 | case octet&0x80 == 0x00: 50 | w, value = 1, rune(octet&0x7F) 51 | case octet&0xE0 == 0xC0: 52 | w, value = 2, rune(octet&0x1F) 53 | case octet&0xF0 == 0xE0: 54 | w, value = 3, rune(octet&0x0F) 55 | case octet&0xF8 == 0xF0: 56 | w, value = 4, rune(octet&0x07) 57 | } 58 | for k := 1; k < w; k++ { 59 | octet = emitter.buffer[pos+k] 60 | value = (value << 6) + (rune(octet) & 0x3F) 61 | } 62 | pos += w 63 | 64 | // Write the character. 65 | if value < 0x10000 { 66 | var b [2]byte 67 | b[high] = byte(value >> 8) 68 | b[low] = byte(value & 0xFF) 69 | emitter.raw_buffer = append(emitter.raw_buffer, b[0], b[1]) 70 | } else { 71 | // Write the character using a surrogate pair (check "reader.c"). 72 | var b [4]byte 73 | value -= 0x10000 74 | b[high] = byte(0xD8 + (value >> 18)) 75 | b[low] = byte((value >> 10) & 0xFF) 76 | b[high+2] = byte(0xDC + ((value >> 8) & 0xFF)) 77 | b[low+2] = byte(value & 0xFF) 78 | emitter.raw_buffer = append(emitter.raw_buffer, b[0], b[1], b[2], b[3]) 79 | } 80 | } 81 | 82 | // Write the raw buffer. 83 | if err := emitter.write_handler(emitter, emitter.raw_buffer); err != nil { 84 | return yaml_emitter_set_writer_error(emitter, "write error: "+err.Error()) 85 | } 86 | emitter.buffer_pos = 0 87 | emitter.raw_buffer = emitter.raw_buffer[:0] 88 | return true 89 | } 90 | -------------------------------------------------------------------------------- /vendor/modules.txt: -------------------------------------------------------------------------------- 1 | # github.com/ciao-project/ciao v0.0.0-20180108144400-194264adc583 2 | ## explicit 3 | github.com/ciao-project/ciao/clogger 4 | github.com/ciao-project/ciao/deviceinfo 5 | github.com/ciao-project/ciao/uuid 6 | # github.com/coreos/go-systemd v0.0.0-20170731111925-d21964639418 7 | ## explicit 8 | github.com/coreos/go-systemd/activation 9 | # github.com/inconshreveable/mousetrap v1.0.0 10 | ## explicit 11 | github.com/inconshreveable/mousetrap 12 | # github.com/intel/govmm v0.0.0-20180104200030-22c99930c2f6 13 | ## explicit 14 | github.com/intel/govmm/qemu 15 | # github.com/mattn/goveralls v0.0.8 16 | ## explicit 17 | # github.com/pkg/errors v0.8.0 18 | ## explicit 19 | github.com/pkg/errors 20 | # github.com/pmezard/go-difflib v1.0.0 21 | ## explicit 22 | github.com/pmezard/go-difflib/difflib 23 | # github.com/spf13/cobra v0.0.2-0.20171231101556-b95ab734e27d 24 | ## explicit 25 | github.com/spf13/cobra 26 | # github.com/spf13/pflag v1.0.0 27 | ## explicit 28 | github.com/spf13/pflag 29 | # golang.org/x/net v0.0.0-20200226121028-0de0cce0169b 30 | ## explicit 31 | golang.org/x/net/http/httpproxy 32 | golang.org/x/net/idna 33 | # golang.org/x/text v0.3.1-0.20171227012246-e19ae1496984 34 | ## explicit 35 | golang.org/x/text/secure/bidirule 36 | golang.org/x/text/transform 37 | golang.org/x/text/unicode/bidi 38 | golang.org/x/text/unicode/norm 39 | # gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c 40 | ## explicit 41 | # gopkg.in/yaml.v2 v2.0.0-20180108131554-1244d3ce02e3 42 | ## explicit 43 | gopkg.in/yaml.v2 44 | --------------------------------------------------------------------------------