本文整理汇总了Golang中github.com/lxc/lxd.Config.ParseRemote方法的典型用法代码示例。如果您正苦于以下问题:Golang Config.ParseRemote方法的具体用法?Golang Config.ParseRemote怎么用?Golang Config.ParseRemote使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/lxc/lxd.Config
的用法示例。
在下文中一共展示了Config.ParseRemote方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: run
func (c *fingerCmd) run(config *lxd.Config, args []string) error {
if len(args) > 1 {
return errArgs
}
var remote string
if len(args) == 1 {
remote = config.ParseRemote(args[0])
} else {
remote = config.DefaultRemote
}
// NewClient will finger the server to test the connection before returning.
_, err := lxd.NewClient(config, remote)
return err
}
示例2: run
func (c *fingerCmd) run(config *lxd.Config, args []string) error {
if len(args) > 1 {
return errArgs
}
var remote string
if len(args) == 1 {
remote = config.ParseRemote(args[0])
} else {
remote = config.DefaultRemote
}
// New client may or may not need to connect to the remote host, but
// client.ServerStatus will at least request the basic information from
// the server.
client, err := lxd.NewClient(config, remote)
if err != nil {
return err
}
_, err = client.ServerStatus()
return err
}
示例3: run
func (c *configCmd) run(config *lxd.Config, args []string) error {
if len(args) < 1 {
return errArgs
}
switch args[0] {
case "unset":
if len(args) < 2 {
return errArgs
}
// 2 args means we're unsetting a server key
if len(args) == 2 {
key := args[1]
c, err := lxd.NewClient(config, config.DefaultRemote)
if err != nil {
return err
}
_, err = c.SetServerConfig(key, "")
return err
}
// 3 args is a container config key
args = append(args, "")
return doSet(config, args)
case "set":
if len(args) < 3 {
return errArgs
}
// 3 args means we're setting a server key
if len(args) == 3 {
key := args[1]
c, err := lxd.NewClient(config, config.DefaultRemote)
if err != nil {
return err
}
_, err = c.SetServerConfig(key, args[2])
return err
}
// 4 args is a container config key
return doSet(config, args)
case "trust":
if len(args) < 2 {
return errArgs
}
switch args[1] {
case "list":
var remote string
if len(args) == 3 {
remote = config.ParseRemote(args[2])
} else {
remote = config.DefaultRemote
}
d, err := lxd.NewClient(config, remote)
if err != nil {
return err
}
trust, err := d.CertificateList()
if err != nil {
return err
}
data := [][]string{}
for _, cert := range trust {
fp := cert.Fingerprint[0:12]
certBlock, _ := pem.Decode([]byte(cert.Certificate))
cert, err := x509.ParseCertificate(certBlock.Bytes)
if err != nil {
return err
}
const layout = "Jan 2, 2006 at 3:04pm (MST)"
issue := cert.NotBefore.Format(layout)
expiry := cert.NotAfter.Format(layout)
data = append(data, []string{fp, cert.Subject.CommonName, issue, expiry})
}
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"FINGERPRINT", "COMMON NAME", "ISSUE DATE", "EXPIRY DATE"})
for _, v := range data {
table.Append(v)
}
table.Render()
return nil
case "add":
var remote string
if len(args) < 3 {
return fmt.Errorf(gettext.Gettext("No cert provided to add"))
} else if len(args) == 4 {
//.........这里部分代码省略.........
示例4: addServer
func (c *remoteCmd) addServer(config *lxd.Config, server string, addr string, acceptCert bool, password string, public bool, protocol string) error {
var rScheme string
var rHost string
var rPort string
// Setup the remotes list
if config.Remotes == nil {
config.Remotes = make(map[string]lxd.RemoteConfig)
}
// Fast track simplestreams
if protocol == "simplestreams" {
config.Remotes[server] = lxd.RemoteConfig{Addr: addr, Public: true, Protocol: protocol}
return nil
}
/* Complex remote URL parsing */
remoteURL, err := url.Parse(addr)
if err != nil {
return err
}
if remoteURL.Scheme != "" {
if remoteURL.Scheme != "unix" && remoteURL.Scheme != "https" {
rScheme = "https"
} else {
rScheme = remoteURL.Scheme
}
} else if addr[0] == '/' {
rScheme = "unix"
} else {
if !shared.PathExists(addr) {
rScheme = "https"
} else {
rScheme = "unix"
}
}
if remoteURL.Host != "" {
rHost = remoteURL.Host
} else {
rHost = addr
}
host, port, err := net.SplitHostPort(rHost)
if err == nil {
rHost = host
rPort = port
} else {
rPort = shared.DefaultPort
}
if rScheme == "unix" {
if addr[0:5] == "unix:" {
if addr[0:7] == "unix://" {
if len(addr) > 8 {
rHost = addr[8:]
} else {
rHost = ""
}
} else {
rHost = addr[6:]
}
}
rPort = ""
}
if strings.Contains(rHost, ":") && !strings.HasPrefix(rHost, "[") {
rHost = fmt.Sprintf("[%s]", rHost)
}
if rPort != "" {
addr = rScheme + "://" + rHost + ":" + rPort
} else {
addr = rScheme + "://" + rHost
}
/* Actually add the remote */
config.Remotes[server] = lxd.RemoteConfig{Addr: addr, Protocol: protocol}
remote := config.ParseRemote(server)
d, err := lxd.NewClient(config, remote)
if err != nil {
return err
}
if len(addr) > 5 && addr[0:5] == "unix:" {
// NewClient succeeded so there was a lxd there (we fingered
// it) so just accept it
return nil
}
var certificate *x509.Certificate
/* Attempt to connect using the system root CA */
err = d.Finger()
if err != nil {
// Failed to connect using the system CA, so retrieve the remote certificate
certificate, err = getRemoteCertificate(addr)
if err != nil {
//.........这里部分代码省略.........
示例5: addServer
func addServer(config *lxd.Config, server string, addr string, acceptCert bool, password string, public bool) error {
var r_scheme string
var r_host string
var r_port string
/* Complex remote URL parsing */
remote_url, err := url.Parse(addr)
if err != nil {
return err
}
if remote_url.Scheme != "" {
if remote_url.Scheme != "unix" && remote_url.Scheme != "https" {
r_scheme = "https"
} else {
r_scheme = remote_url.Scheme
}
} else if addr[0] == '/' {
r_scheme = "unix"
} else {
if !shared.PathExists(addr) {
r_scheme = "https"
} else {
r_scheme = "unix"
}
}
if remote_url.Host != "" {
r_host = remote_url.Host
} else {
r_host = addr
}
host, port, err := net.SplitHostPort(r_host)
if err == nil {
r_host = host
r_port = port
} else {
r_port = shared.DefaultPort
}
if r_scheme == "unix" {
if addr[0:5] == "unix:" {
if addr[0:7] == "unix://" {
if len(addr) > 8 {
r_host = addr[8:]
} else {
r_host = ""
}
} else {
r_host = addr[6:]
}
}
r_port = ""
}
if strings.Contains(r_host, ":") && !strings.HasPrefix(r_host, "[") {
r_host = fmt.Sprintf("[%s]", r_host)
}
if r_port != "" {
addr = r_scheme + "://" + r_host + ":" + r_port
} else {
addr = r_scheme + "://" + r_host
}
if config.Remotes == nil {
config.Remotes = make(map[string]lxd.RemoteConfig)
}
/* Actually add the remote */
config.Remotes[server] = lxd.RemoteConfig{Addr: addr}
remote := config.ParseRemote(server)
c, err := lxd.NewClient(config, remote)
if err != nil {
return err
}
if len(addr) > 5 && addr[0:5] == "unix:" {
// NewClient succeeded so there was a lxd there (we fingered
// it) so just accept it
return nil
}
/* grab the server's cert */
err = c.Finger()
if err != nil {
return err
}
if !acceptCert {
// Try to use the CAs on localhost to verify the cert so we
// don't have to bother the user.
digest, err := c.TryVerifyServerCert(host)
if err != nil {
fmt.Printf(i18n.G("Certificate fingerprint: %x")+"\n", digest)
fmt.Printf(i18n.G("ok (y/n)?") + " ")
line, err := shared.ReadStdin()
if err != nil {
//.........这里部分代码省略.........
示例6: run
func (c *configCmd) run(config *lxd.Config, args []string) error {
if len(args) < 1 {
return errArgs
}
switch args[0] {
case "unset":
if len(args) < 2 {
return errArgs
}
// 2 args means we're unsetting a server key
if len(args) == 2 {
key := args[1]
c, err := lxd.NewClient(config, "")
if err != nil {
return err
}
_, err = c.SetServerConfig(key, "")
return err
}
// 3 args is a container config key
args = append(args, "")
return doSet(config, args)
case "set":
if len(args) < 3 {
return errArgs
}
// 3 args means we're setting a server key
if len(args) == 3 {
key := args[1]
c, err := lxd.NewClient(config, "")
if err != nil {
return err
}
_, err = c.SetServerConfig(key, args[2])
return err
}
// 4 args is a container config key
return doSet(config, args)
case "trust":
if len(args) < 2 {
return errArgs
}
switch args[1] {
case "list":
var remote string
if len(args) == 3 {
remote = config.ParseRemote(args[2])
} else {
remote = config.DefaultRemote
}
d, err := lxd.NewClient(config, remote)
if err != nil {
return err
}
trust, err := d.CertificateList()
if err != nil {
return err
}
for _, fingerprint := range trust {
fmt.Println(fmt.Sprintf("%s", fingerprint))
}
return nil
case "add":
var remote string
if len(args) < 3 {
return fmt.Errorf(gettext.Gettext("No cert provided to add"))
} else if len(args) == 4 {
remote = config.ParseRemote(args[2])
} else {
remote = config.DefaultRemote
}
d, err := lxd.NewClient(config, remote)
if err != nil {
return err
}
fname := args[len(args)-1]
cert, err := shared.ReadCert(fname)
if err != nil {
return err
}
name, _ := shared.SplitExt(fname)
return d.CertificateAdd(cert, name)
case "remove":
var remote string
//.........这里部分代码省略.........
示例7: run
func (c *imageCmd) run(config *lxd.Config, args []string) error {
var remote string
if len(args) < 1 {
return errArgs
}
switch args[0] {
case "alias":
if len(args) < 2 {
return errArgs
}
return c.doImageAlias(config, args)
case "copy":
/* copy [<remote>:]<image> [<rmeote>:]<image> */
if len(args) != 3 {
return errArgs
}
remote, inName := config.ParseRemoteAndContainer(args[1])
if inName == "" {
inName = "default"
}
destRemote, outName := config.ParseRemoteAndContainer(args[2])
if outName != "" {
return errArgs
}
d, err := lxd.NewClient(config, remote)
if err != nil {
return err
}
dest, err := lxd.NewClient(config, destRemote)
if err != nil {
return err
}
progressHandler := func(progress string) {
fmt.Printf(i18n.G("Copying the image: %s")+"\r", progress)
}
err = d.CopyImage(inName, dest, c.copyAliases, c.addAliases, c.publicImage, c.autoUpdate, progressHandler)
if err == nil {
fmt.Println(i18n.G("Image copied successfully!"))
}
return err
case "delete":
/* delete [<remote>:]<image> [<remote>:][<image>...] */
if len(args) < 2 {
return errArgs
}
for _, arg := range args[1:] {
remote, inName := config.ParseRemoteAndContainer(arg)
if inName == "" {
inName = "default"
}
d, err := lxd.NewClient(config, remote)
if err != nil {
return err
}
image := c.dereferenceAlias(d, inName)
err = d.DeleteImage(image)
if err != nil {
return err
}
}
return nil
case "info":
if len(args) < 2 {
return errArgs
}
remote, inName := config.ParseRemoteAndContainer(args[1])
if inName == "" {
inName = "default"
}
d, err := lxd.NewClient(config, remote)
if err != nil {
return err
}
image := c.dereferenceAlias(d, inName)
info, err := d.GetImageInfo(image)
if err != nil {
return err
}
public := i18n.G("no")
if info.Public {
public = i18n.G("yes")
//.........这里部分代码省略.........
示例8: run
func (c *imageCmd) run(config *lxd.Config, args []string) error {
var remote string
if len(args) < 1 {
return errArgs
}
switch args[0] {
case "alias":
if len(args) < 2 {
return errArgs
}
return doImageAlias(config, args)
case "copy":
/* copy [<remote>:]<image> [<rmeote>:]<image> */
if len(args) != 3 {
return errArgs
}
remote, inName := config.ParseRemoteAndContainer(args[1])
if inName == "" {
return errArgs
}
destRemote, outName := config.ParseRemoteAndContainer(args[2])
if outName != "" {
return errArgs
}
d, err := lxd.NewClient(config, remote)
if err != nil {
return err
}
dest, err := lxd.NewClient(config, destRemote)
if err != nil {
return err
}
image := dereferenceAlias(d, inName)
return d.CopyImage(image, dest, copyAliases, addAliases, publicImage)
case "delete":
/* delete [<remote>:]<image> */
if len(args) < 2 {
return errArgs
}
remote, inName := config.ParseRemoteAndContainer(args[1])
if inName == "" {
return errArgs
}
d, err := lxd.NewClient(config, remote)
if err != nil {
return err
}
image := dereferenceAlias(d, inName)
err = d.DeleteImage(image)
return err
case "info":
if len(args) < 2 {
return errArgs
}
remote, inName := config.ParseRemoteAndContainer(args[1])
if inName == "" {
return errArgs
}
d, err := lxd.NewClient(config, remote)
if err != nil {
return err
}
image := dereferenceAlias(d, inName)
info, err := d.GetImageInfo(image)
if err != nil {
return err
}
fmt.Printf(gettext.Gettext("Fingerprint: %s")+"\n", info.Fingerprint)
public := gettext.Gettext("no")
if shared.InterfaceToBool(info) {
public = gettext.Gettext("yes")
}
fmt.Printf(gettext.Gettext("Size: %.2vMB")+"\n", float64(info.Size)/1024.0/1024.0)
arch, _ := shared.ArchitectureName(info.Architecture)
fmt.Printf(gettext.Gettext("Architecture: %s")+"\n", arch)
fmt.Printf(gettext.Gettext("Public: %s")+"\n", public)
fmt.Printf(gettext.Gettext("Timestamps:") + "\n")
const layout = "2006/01/02 15:04 UTC"
if info.CreationDate != 0 {
fmt.Printf(" "+gettext.Gettext("Created: %s")+"\n", time.Unix(info.CreationDate, 0).UTC().Format(layout))
}
fmt.Printf(" "+gettext.Gettext("Uploaded: %s")+"\n", time.Unix(info.UploadDate, 0).UTC().Format(layout))
if info.ExpiryDate != 0 {
fmt.Printf(" "+gettext.Gettext("Expires: %s")+"\n", time.Unix(info.ExpiryDate, 0).UTC().Format(layout))
} else {
fmt.Printf(" " + gettext.Gettext("Expires: never") + "\n")
}
fmt.Println(gettext.Gettext("Properties:"))
for key, value := range info.Properties {
fmt.Printf(" %s: %s\n", key, value)
}
fmt.Println(gettext.Gettext("Aliases:"))
for _, alias := range info.Aliases {
fmt.Printf(" - %s\n", alias.Name)
//.........这里部分代码省略.........
示例9: addServer
func addServer(config *lxd.Config, server string, addr string, acceptCert bool, password string) error {
var r_scheme string
var r_host string
var r_port string
remote_url, err := url.Parse(addr)
if err != nil {
return err
}
if remote_url.Scheme != "" {
if remote_url.Scheme != "unix" && remote_url.Scheme != "https" {
r_scheme = "https"
} else {
r_scheme = remote_url.Scheme
}
} else if addr[0] == '/' {
r_scheme = "unix"
} else {
if !shared.PathExists(addr) {
r_scheme = "https"
} else {
r_scheme = "unix"
}
}
if remote_url.Host != "" {
r_host = remote_url.Host
} else {
r_host = addr
}
host, port, err := net.SplitHostPort(r_host)
if err == nil {
r_host = host
r_port = port
} else {
r_port = shared.DefaultPort
}
if r_scheme == "unix" {
if addr[0:5] == "unix:" {
if addr[0:7] == "unix://" {
r_host = addr[8:]
} else {
r_host = addr[6:]
}
}
r_port = ""
}
if strings.Contains(r_host, ":") && !strings.HasPrefix(r_host, "[") {
r_host = fmt.Sprintf("[%s]", r_host)
}
if r_port != "" {
addr = r_scheme + "://" + r_host + ":" + r_port
} else {
addr = r_scheme + "://" + r_host
}
if config.Remotes == nil {
config.Remotes = make(map[string]lxd.RemoteConfig)
}
config.Remotes[server] = lxd.RemoteConfig{Addr: addr}
remote := config.ParseRemote(server)
c, err := lxd.NewClient(config, remote)
if err != nil {
return err
}
if len(addr) > 5 && addr[0:5] == "unix:" {
// NewClient succeeded so there was a lxd there (we fingered
// it) so just accept it
return nil
}
err = c.UserAuthServerCert(host, acceptCert)
if err != nil {
return err
}
if c.AmTrusted() {
// server already has our cert, so we're done
return nil
}
if password == "" {
fmt.Printf(gettext.Gettext("Admin password for %s: "), server)
pwd, err := terminal.ReadPassword(0)
if err != nil {
/* We got an error, maybe this isn't a terminal, let's try to
* read it as a file */
pwd, err = shared.ReadStdin()
if err != nil {
return err
}
}
//.........这里部分代码省略.........
示例10: run
func (c *imageCmd) run(config *lxd.Config, args []string) error {
var remote string
if len(args) < 1 {
return errArgs
}
switch args[0] {
case "alias":
if len(args) < 2 {
return errArgs
}
return doImageAlias(config, args)
case "copy":
/* copy [<remote>:]<image> [<rmeote>:]<image> */
if len(args) != 3 {
return errArgs
}
remote, inName := config.ParseRemoteAndContainer(args[1])
if inName == "" {
return errArgs
}
destRemote, outName := config.ParseRemoteAndContainer(args[2])
if outName != "" {
return errArgs
}
d, err := lxd.NewClient(config, remote)
if err != nil {
return err
}
dest, err := lxd.NewClient(config, destRemote)
if err != nil {
return err
}
image := dereferenceAlias(d, inName)
progressHandler := func(progress string) {
fmt.Printf(i18n.G("Copying the image: %s")+"\r", progress)
}
return d.CopyImage(image, dest, copyAliases, addAliases, publicImage, progressHandler)
case "delete":
/* delete [<remote>:]<image> */
if len(args) < 2 {
return errArgs
}
remote, inName := config.ParseRemoteAndContainer(args[1])
if inName == "" {
return errArgs
}
d, err := lxd.NewClient(config, remote)
if err != nil {
return err
}
image := dereferenceAlias(d, inName)
err = d.DeleteImage(image)
return err
case "info":
if len(args) < 2 {
return errArgs
}
remote, inName := config.ParseRemoteAndContainer(args[1])
if inName == "" {
return errArgs
}
d, err := lxd.NewClient(config, remote)
if err != nil {
return err
}
image := dereferenceAlias(d, inName)
info, err := d.GetImageInfo(image)
if err != nil {
return err
}
fmt.Printf(i18n.G("Fingerprint: %s")+"\n", info.Fingerprint)
public := i18n.G("no")
// FIXME: InterfaceToBool is there for backward compatibility
if shared.InterfaceToBool(info) {
public = i18n.G("yes")
}
fmt.Printf(i18n.G("Size: %.2fMB")+"\n", float64(info.Size)/1024.0/1024.0)
arch, _ := shared.ArchitectureName(info.Architecture)
fmt.Printf(i18n.G("Architecture: %s")+"\n", arch)
fmt.Printf(i18n.G("Public: %s")+"\n", public)
fmt.Printf(i18n.G("Timestamps:") + "\n")
const layout = "2006/01/02 15:04 UTC"
if info.CreationDate != 0 {
fmt.Printf(" "+i18n.G("Created: %s")+"\n", time.Unix(info.CreationDate, 0).UTC().Format(layout))
}
fmt.Printf(" "+i18n.G("Uploaded: %s")+"\n", time.Unix(info.UploadDate, 0).UTC().Format(layout))
if info.ExpiryDate != 0 {
fmt.Printf(" "+i18n.G("Expires: %s")+"\n", time.Unix(info.ExpiryDate, 0).UTC().Format(layout))
} else {
fmt.Printf(" " + i18n.G("Expires: never") + "\n")
//.........这里部分代码省略.........
示例11: run
func (c *configCmd) run(config *lxd.Config, args []string) error {
if len(args) < 1 {
return errArgs
}
switch args[0] {
case "unset":
if len(args) < 2 {
return errArgs
}
// Deal with local server
if len(args) == 2 {
c, err := lxd.NewClient(config, config.DefaultRemote)
if err != nil {
return err
}
ss, err := c.ServerStatus()
if err != nil {
return err
}
_, ok := ss.Config[args[1]]
if !ok {
return fmt.Errorf(i18n.G("Can't unset key '%s', it's not currently set."), args[1])
}
_, err = c.SetServerConfig(args[1], "")
return err
}
// Deal with remote server
remote, container := config.ParseRemoteAndContainer(args[1])
if container == "" {
c, err := lxd.NewClient(config, remote)
if err != nil {
return err
}
ss, err := c.ServerStatus()
if err != nil {
return err
}
_, ok := ss.Config[args[1]]
if !ok {
return fmt.Errorf(i18n.G("Can't unset key '%s', it's not currently set."), args[1])
}
_, err = c.SetServerConfig(args[2], "")
return err
}
// Deal with container
args = append(args, "")
return c.doSet(config, args, true)
case "set":
if len(args) < 3 {
return errArgs
}
// Deal with local server
if len(args) == 3 {
c, err := lxd.NewClient(config, config.DefaultRemote)
if err != nil {
return err
}
_, err = c.SetServerConfig(args[1], args[2])
return err
}
// Deal with remote server
remote, container := config.ParseRemoteAndContainer(args[1])
if container == "" {
c, err := lxd.NewClient(config, remote)
if err != nil {
return err
}
_, err = c.SetServerConfig(args[2], args[3])
return err
}
// Deal with container
return c.doSet(config, args, false)
case "trust":
if len(args) < 2 {
return errArgs
}
switch args[1] {
case "list":
var remote string
if len(args) == 3 {
remote = config.ParseRemote(args[2])
//.........这里部分代码省略.........
示例12: run
func (c *configCmd) run(config *lxd.Config, args []string) error {
if len(args) < 1 {
return errArgs
}
switch args[0] {
case "unset":
if len(args) < 2 {
return errArgs
}
// Deal with local server
if len(args) == 2 {
c, err := lxd.NewClient(config, config.DefaultRemote)
if err != nil {
return err
}
_, err = c.SetServerConfig(args[1], "")
return err
}
// Deal with remote server
remote, container := config.ParseRemoteAndContainer(args[1])
if container == "" {
c, err := lxd.NewClient(config, remote)
if err != nil {
return err
}
_, err = c.SetServerConfig(args[2], "")
return err
}
// Deal with container
args = append(args, "")
return doSet(config, args)
case "set":
if len(args) < 3 {
return errArgs
}
// Deal with local server
if len(args) == 3 {
c, err := lxd.NewClient(config, config.DefaultRemote)
if err != nil {
return err
}
_, err = c.SetServerConfig(args[1], args[2])
return err
}
// Deal with remote server
remote, container := config.ParseRemoteAndContainer(args[1])
if container == "" {
c, err := lxd.NewClient(config, remote)
if err != nil {
return err
}
_, err = c.SetServerConfig(args[2], args[3])
return err
}
// Deal with container
return doSet(config, args)
case "trust":
if len(args) < 2 {
return errArgs
}
switch args[1] {
case "list":
var remote string
if len(args) == 3 {
remote = config.ParseRemote(args[2])
} else {
remote = config.DefaultRemote
}
d, err := lxd.NewClient(config, remote)
if err != nil {
return err
}
trust, err := d.CertificateList()
if err != nil {
return err
}
data := [][]string{}
for _, cert := range trust {
fp := cert.Fingerprint[0:12]
certBlock, _ := pem.Decode([]byte(cert.Certificate))
cert, err := x509.ParseCertificate(certBlock.Bytes)
//.........这里部分代码省略.........
示例13: addServer
func addServer(config *lxd.Config, server string, addr string, acceptCert bool, password string, public bool) error {
var r_scheme string
var r_host string
var r_port string
/* Complex remote URL parsing */
remote_url, err := url.Parse(addr)
if err != nil {
return err
}
if remote_url.Scheme != "" {
if remote_url.Scheme != "unix" && remote_url.Scheme != "https" {
r_scheme = "https"
} else {
r_scheme = remote_url.Scheme
}
} else if addr[0] == '/' {
r_scheme = "unix"
} else {
if !shared.PathExists(addr) {
r_scheme = "https"
} else {
r_scheme = "unix"
}
}
if remote_url.Host != "" {
r_host = remote_url.Host
} else {
r_host = addr
}
host, port, err := net.SplitHostPort(r_host)
if err == nil {
r_host = host
r_port = port
} else {
r_port = shared.DefaultPort
}
if r_scheme == "unix" {
if addr[0:5] == "unix:" {
if addr[0:7] == "unix://" {
r_host = addr[8:]
} else {
r_host = addr[6:]
}
}
r_port = ""
}
if strings.Contains(r_host, ":") && !strings.HasPrefix(r_host, "[") {
r_host = fmt.Sprintf("[%s]", r_host)
}
if r_port != "" {
addr = r_scheme + "://" + r_host + ":" + r_port
} else {
addr = r_scheme + "://" + r_host
}
if config.Remotes == nil {
config.Remotes = make(map[string]lxd.RemoteConfig)
}
/* Actually add the remote */
config.Remotes[server] = lxd.RemoteConfig{Addr: addr, Public: public}
remote := config.ParseRemote(server)
c, err := lxd.NewClient(config, remote)
if err != nil {
return err
}
if len(addr) > 5 && addr[0:5] == "unix:" {
// NewClient succeeded so there was a lxd there (we fingered
// it) so just accept it
return nil
}
err = c.UserAuthServerCert(host, acceptCert)
if err != nil {
return err
}
if public {
if err := c.Finger(); err != nil {
return err
}
return nil
}
if c.AmTrusted() {
// server already has our cert, so we're done
return nil
}
if password == "" {
//.........这里部分代码省略.........