// CreateSSHShell creates a new SSH shell / client
183653
func CreateSSHShell(api libmachine.API, args []string) error {
	machineName := cfg.GetMachineName()
	host, err := CheckIfHostExistsAndLoad(api, machineName)
	if err != nil {
		return errors.Wrap(err, "host exists and load")
	}

	currentState, err := host.Driver.GetState()
	if err != nil {
		return errors.Wrap(err, "state")
	}

	if currentState != state.Running {
		return errors.Errorf("%q is not running", machineName)
	}

	client, err := host.CreateSSHClient()
	if err != nil {
		return errors.Wrap(err, "Creating ssh client")
	}
	return client.Shell(args...)
}
704392
func CreateClient(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
	path := p.Get("url", "unix:///var/run/docker.sock").(string)

	return docli.NewClient(path)
}
1371023
func (ch *CredHub) GenerateSSH(name string, gen generate.SSH, overwrite Mode) (credentials.SSH, error) {
	var cred credentials.SSH
	err := ch.generateCredential(name, "ssh", gen, overwrite, &cred)
	return cred, err
}
293763
func createVolumeWithData(cli *client.Client, volumeName string, data map[string][]byte, image string) error {
	_, err := cli.VolumeCreate(context.Background(),
		volume.VolumeCreateBody{
			Driver: "local",
			Name:   volumeName,
		})
	if err != nil {
		return err
	}
	mnt := "/mnt"
	miniContainer, err := cli.ContainerCreate(context.Background(),
		&container.Config{
			Image: image,
		},
		&container.HostConfig{
			Mounts: []mount.Mount{
				{
					Type:   mount.TypeVolume,
					Source: volumeName,
					Target: mnt,
				},
			},
		}, nil, "")
	if err != nil {
		return err
	}
	tr, err := createTar(data)
	if err != nil {
		return err
	}
	if cli.CopyToContainer(context.Background(),
		miniContainer.ID, mnt, tr, types.CopyToContainerOptions{}); err != nil {
		return err
	}
	return cli.ContainerRemove(context.Background(),
		miniContainer.ID,
		types.ContainerRemoveOptions{})
}
383232
func (c *Client) SSH(argv []string) error {
	usage := `Open an interactive shell on a machine in the cluster given a unit or machine id.

If an optional <command> is provided, that command is run remotely, and the results returned.

Usage:
  deisctl ssh <target> [<command>...]
`
	// parse command-line arguments
	args, err := docopt.Parse(usage, argv, true, "", true)
	if err != nil {
		return err
	}

	target := args["<target>"].(string)
	// handle help explicitly since docopt parsing is relaxed
	if target == "--help" {
		fmt.Println(usage)
		os.Exit(0)
	}

	var vargs []string
	if v, ok := args["<command>"]; ok {
		vargs = v.([]string)
	}

	return cmd.SSH(target, vargs, c.Backend)
}
286538
func (h *fs) Create(filename string) (io.WriteCloser, error) {
	return os.Create(filename)
}
1182619
func (fsh *Handler) CreateFile(file string) error {
	path, _ := filepath.Split(file)
	// Create path at first if necessary
	if path != "" {
		if err := os.MkdirAll(path, os.ModePerm); err != nil {
			return errors.Errorf("failed to create path for file %s: %v", file, err)
		}
	}
	sf, err := os.Create(file)
	if err != nil {
		return errors.Errorf("failed to create file %s: %v", file, err)
	}
	return sf.Close()
}
1912
func createFile(name string, isDir bool) (syscall.Handle, error) {
	namep := syscall.StringToUTF16(name)
	da := uint32(desiredAccessReadControl | desiredAccessWriteDac)
	sm := uint32(shareModeRead | shareModeWrite)
	fa := uint32(syscall.FILE_ATTRIBUTE_NORMAL)
	if isDir {
		fa = uint32(fa | syscall.FILE_FLAG_BACKUP_SEMANTICS)
	}
	fd, err := syscall.CreateFile(&namep[0], da, sm, nil, syscall.OPEN_EXISTING, fa, 0)
	if err != nil {
		return 0, errors.Wrapf(err, "%s syscall.CreateFile %s", gvmga, name)
	}
	return fd, nil
}
875868
func (ch *CredHub) SetSSH(name string, value values.SSH) (credentials.SSH, error) {
	var cred credentials.SSH
	err := ch.setCredential(name, "ssh", value, &cred)

	return cred, err
}
991005
func (api *LocalClient) Create(h *host.Host) error {
	if def, err := registry.Driver(h.DriverName); err != nil {
		return err
	} else if !def.Builtin || def.DriverCreator == nil {
		return api.legacyClient.Create(h)
	}

	steps := []struct {
		name string
		f    func() error
	}{
		{
			"bootstrapping certificates",
			func() error { return cert.BootstrapCertificates(h.AuthOptions()) },
		},
		{
			"precreate",
			h.Driver.PreCreateCheck,
		},
		{
			"saving",
			func() error {
				return api.Save(h)
			},
		},
		{
			"creating",
			h.Driver.Create,
		},
		{
			"waiting",
			func() error {
				if h.Driver.DriverName() == "none" {
					return nil
				}
				return mcnutils.WaitFor(drivers.MachineInState(h.Driver, state.Running))
			},
		},
		{
			"provisioning",
			func() error {
				if h.Driver.DriverName() == "none" {
					return nil
				}
				pv := provision.NewBuildrootProvisioner(h.Driver)
				return pv.Provision(*h.HostOptions.SwarmOptions, *h.HostOptions.AuthOptions, *h.HostOptions.EngineOptions)
			},
		},
	}

	for _, step := range steps {
		if err := step.f(); err != nil {
			return errors.Wrap(err, step.name)
		}
	}

	return nil
}
23743
func (o *Zone) CreateDHCPOption(child *DHCPOption) *bambou.Error {

	return bambou.CurrentSession().CreateChild(o, child)
}
1322323
func (client *Client) CreateSnapshot(args *CreateSnapshotArgs) (snapshotId string, err error) {

	response := CreateSnapshotResponse{}

	err = client.Invoke("CreateSnapshot", args, &response)
	if err == nil {
		snapshotId = response.SnapshotId
	}
	return snapshotId, err
}
1156524
func (namespace *HostComputeNamespace) Create() (*HostComputeNamespace, error) {
	logrus.Debugf("hcn::HostComputeNamespace::Create id=%s", namespace.Id)

	jsonString, err := json.Marshal(namespace)
	if err != nil {
		return nil, err
	}

	logrus.Debugf("hcn::HostComputeNamespace::Create JSON: %s", jsonString)
	namespace, hcnErr := createNamespace(string(jsonString))
	if hcnErr != nil {
		return nil, hcnErr
	}
	return namespace, nil
}
8921
func teeSSH(s *ssh.Session, cmd string, outB io.Writer, errB io.Writer) error {
	outPipe, err := s.StdoutPipe()
	if err != nil {
		return errors.Wrap(err, "stdout")
	}

	errPipe, err := s.StderrPipe()
	if err != nil {
		return errors.Wrap(err, "stderr")
	}
	var wg sync.WaitGroup
	wg.Add(2)

	go func() {
		if err := util.TeePrefix(util.ErrPrefix, errPipe, errB, glog.Infof); err != nil {
			glog.Errorf("tee stderr: %v", err)
		}
		wg.Done()
	}()
	go func() {
		if err := util.TeePrefix(util.OutPrefix, outPipe, outB, glog.Infof); err != nil {
			glog.Errorf("tee stdout: %v", err)
		}
		wg.Done()
	}()
	err = s.Run(cmd)
	wg.Wait()
	return err
}
295548
func (c *sSHCredentials) Create(sSHCredential *v1alpha1.SSHCredential) (result *v1alpha1.SSHCredential, err error) {
	result = &v1alpha1.SSHCredential{}
	err = c.client.Post().
		Namespace(c.ns).
		Resource("sshcredentials").
		Body(sSHCredential).
		Do().
		Into(result)
	return
}
606332
func (o *InfrastructureAccessProfile) CreateSSHKey(child *SSHKey) *bambou.Error {

	return bambou.CurrentSession().CreateChild(o, child)
}
144073
func (vg *Vangoh) createHeadersString(r *http.Request) string {
	if len(vg.includedHeaders) == 0 {
		return ""
	}

	// For each defined regex, determine the set of headers that match. Repeat
	// for all regexes, without duplication, to get the final set of custom
	// headers to use.
	var sanitizedHeaders = make(map[string][]string)

	for _, compiledRegex := range vg.includedHeaders {
		for header := range r.Header {
			lowerHeader := strings.ToLower(header)
			if _, found := sanitizedHeaders[lowerHeader]; found {
				continue
			}
			if compiledRegex.MatchString(header) {
				sanitizedHeaders[lowerHeader] = r.Header[header]
			}
		}
	}

	var orderedHeaders []string
	for header := range sanitizedHeaders {
		orderedHeaders = append(orderedHeaders, header)
	}
	sort.Strings(orderedHeaders)

	// At this point sanitized contains all the headers to be included in the
	// hash. Now we need to retrieve their values, and sanitize them
	// appropriately.
	var buffer bytes.Buffer
	for header := range orderedHeaders {
		buffer.WriteString(orderedHeaders[header])
		buffer.WriteString(":")

		var sanitizedValues []string
		for i := range sanitizedHeaders[orderedHeaders[header]] {
			str := sanitizedHeaders[orderedHeaders[header]][i]
			str = strings.TrimSpace(str)
			str = strings.Replace(str, "\n", "", -1)
			sanitizedValues = append(sanitizedValues, str)
		}

		// Note that sanitizedValues are unsorted here - the order that they are
		// specified in the header will affect the hash result. This conforms with
		// the standard set by AWS, though it may be more reliable to add this
		// sorting in at some point.
		for i := range sanitizedValues {
			buffer.WriteString(sanitizedValues[i])
			if i < (len(sanitizedValues) - 1) {
				buffer.WriteString(",")
			}
		}

		buffer.WriteString(newline)
	}

	return buffer.String()
}