本文整理汇总了Golang中github.com/lxc/lxd/shared.GetTLSConfig函数的典型用法代码示例。如果您正苦于以下问题:Golang GetTLSConfig函数的具体用法?Golang GetTLSConfig怎么用?Golang GetTLSConfig使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetTLSConfig函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getRemoteCertificate
func getRemoteCertificate(address string) (*x509.Certificate, error) {
// Setup a permissive TLS config
tlsConfig, err := shared.GetTLSConfig("", "", nil)
if err != nil {
return nil, err
}
tlsConfig.InsecureSkipVerify = true
tr := &http.Transport{
TLSClientConfig: tlsConfig,
Dial: shared.RFC3493Dialer,
Proxy: shared.ProxyFromEnvironment,
}
// Connect
client := &http.Client{Transport: tr}
resp, err := client.Get(address)
if err != nil {
return nil, err
}
// Retrieve the certificate
if resp.TLS == nil || len(resp.TLS.PeerCertificates) == 0 {
return nil, fmt.Errorf("Unable to read remote TLS certificate")
}
return resp.TLS.PeerCertificates[0], nil
}
示例2: httpGetSync
func (d *Daemon) httpGetSync(url string, certificate string) (*lxd.Response, error) {
var err error
var cert *x509.Certificate
if certificate != "" {
certBlock, _ := pem.Decode([]byte(certificate))
if certBlock == nil {
return nil, fmt.Errorf("Invalid certificate")
}
cert, err = x509.ParseCertificate(certBlock.Bytes)
if err != nil {
return nil, err
}
}
tlsConfig, err := shared.GetTLSConfig("", "", "", cert)
if err != nil {
return nil, err
}
tr := &http.Transport{
TLSClientConfig: tlsConfig,
Dial: shared.RFC3493Dialer,
Proxy: d.proxy,
DisableKeepAlives: true,
}
myhttp := http.Client{
Transport: tr,
}
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
}
req.Header.Set("User-Agent", shared.UserAgent)
r, err := myhttp.Do(req)
if err != nil {
return nil, err
}
resp, err := lxd.ParseResponse(r)
if err != nil {
return nil, err
}
if resp.Type != lxd.Sync {
return nil, fmt.Errorf("unexpected non-sync response")
}
return resp, nil
}
示例3: httpGetFile
func (d *Daemon) httpGetFile(url string, certificate string) (*http.Response, error) {
var err error
var cert *x509.Certificate
if certificate != "" {
certBlock, _ := pem.Decode([]byte(certificate))
if certBlock == nil {
return nil, fmt.Errorf("Invalid certificate")
}
cert, err = x509.ParseCertificate(certBlock.Bytes)
if err != nil {
return nil, err
}
}
tlsConfig, err := shared.GetTLSConfig("", "", "", cert)
if err != nil {
return nil, err
}
tr := &http.Transport{
TLSClientConfig: tlsConfig,
Dial: shared.RFC3493Dialer,
Proxy: d.proxy,
DisableKeepAlives: true,
}
myhttp := http.Client{
Transport: tr,
}
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
}
req.Header.Set("User-Agent", shared.UserAgent)
raw, err := myhttp.Do(req)
if err != nil {
return nil, err
}
if raw.StatusCode != 200 {
_, err := lxd.HoistResponse(raw, lxd.Error)
if err != nil {
return nil, err
}
return nil, fmt.Errorf("non-200 status with no error response?")
}
return raw, nil
}
示例4: UpdateHTTPsPort
func (d *Daemon) UpdateHTTPsPort(oldAddress string, newAddress string) error {
var sockets []net.Listener
if oldAddress != "" {
_, _, err := net.SplitHostPort(oldAddress)
if err != nil {
oldAddress = fmt.Sprintf("%s:%s", oldAddress, shared.DefaultPort)
}
for _, socket := range d.Sockets {
if socket.Addr().String() == oldAddress {
socket.Close()
} else {
sockets = append(sockets, socket)
}
}
} else {
sockets = d.Sockets
}
if newAddress != "" {
_, _, err := net.SplitHostPort(newAddress)
if err != nil {
newAddress = fmt.Sprintf("%s:%s", newAddress, shared.DefaultPort)
}
tlsConfig, err := shared.GetTLSConfig(d.certf, d.keyf)
if err != nil {
return err
}
tcpl, err := tls.Listen("tcp", newAddress, tlsConfig)
if err != nil {
return fmt.Errorf("cannot listen on https socket: %v", err)
}
d.tomb.Go(func() error { return http.Serve(tcpl, d.mux) })
sockets = append(sockets, tcpl)
}
d.Sockets = sockets
return nil
}
示例5: httpGetSync
func (d *Daemon) httpGetSync(url string) (*lxd.Response, error) {
var err error
if d.tlsconfig == nil {
d.tlsconfig, err = shared.GetTLSConfig(d.certf, d.keyf)
if err != nil {
return nil, err
}
}
tr := &http.Transport{
TLSClientConfig: d.tlsconfig,
Dial: shared.RFC3493Dialer,
Proxy: http.ProxyFromEnvironment,
}
myhttp := http.Client{
Transport: tr,
}
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
}
req.Header.Set("User-Agent", shared.UserAgent)
r, err := myhttp.Do(req)
if err != nil {
return nil, err
}
resp, err := lxd.ParseResponse(r)
if err != nil {
return nil, err
}
if resp.Type != lxd.Sync {
return nil, fmt.Errorf("unexpected non-sync response")
}
return resp, nil
}
示例6: httpGetFile
func (d *Daemon) httpGetFile(url string) (*http.Response, error) {
var err error
if d.tlsconfig == nil {
d.tlsconfig, err = shared.GetTLSConfig(d.certf, d.keyf)
if err != nil {
return nil, err
}
}
tr := &http.Transport{
TLSClientConfig: d.tlsconfig,
Dial: shared.RFC3493Dialer,
Proxy: http.ProxyFromEnvironment,
}
myhttp := http.Client{
Transport: tr,
}
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
}
req.Header.Set("User-Agent", shared.UserAgent)
raw, err := myhttp.Do(req)
if err != nil {
return nil, err
}
if raw.StatusCode != 200 {
_, err := lxd.HoistResponse(raw, lxd.Error)
if err != nil {
return nil, err
}
return nil, fmt.Errorf("non-200 status with no error response?")
}
return raw, nil
}
示例7: NewClient
// NewClient returns a new LXD client.
func NewClient(config *Config, remote string) (*Client, error) {
c := Client{
Config: *config,
Http: http.Client{},
}
c.Name = remote
if remote == "" {
return nil, fmt.Errorf(i18n.G("A remote name must be provided."))
}
if r, ok := config.Remotes[remote]; ok {
if r.Addr[0:5] == "unix:" {
if r.Addr == "unix://" {
r.Addr = fmt.Sprintf("unix:%s", shared.VarPath("unix.socket"))
}
c.BaseURL = "http://unix.socket"
c.BaseWSURL = "ws://unix.socket"
c.Transport = "unix"
uDial := func(networ, addr string) (net.Conn, error) {
var err error
var raddr *net.UnixAddr
if r.Addr[7:] == "unix://" {
raddr, err = net.ResolveUnixAddr("unix", r.Addr[7:])
} else {
raddr, err = net.ResolveUnixAddr("unix", r.Addr[5:])
}
if err != nil {
return nil, err
}
return net.DialUnix("unix", nil, raddr)
}
c.Http.Transport = &http.Transport{Dial: uDial}
c.websocketDialer.NetDial = uDial
c.Remote = &r
} else {
certf, keyf, err := readMyCert(config.ConfigDir)
if err != nil {
return nil, err
}
tlsconfig, err := shared.GetTLSConfig(certf, keyf)
if err != nil {
return nil, err
}
tr := &http.Transport{
TLSClientConfig: tlsconfig,
Dial: shared.RFC3493Dialer,
Proxy: http.ProxyFromEnvironment,
}
c.websocketDialer = websocket.Dialer{
NetDial: shared.RFC3493Dialer,
TLSClientConfig: tlsconfig,
}
c.certf = certf
c.keyf = keyf
if r.Addr[0:8] == "https://" {
c.BaseURL = "https://" + r.Addr[8:]
c.BaseWSURL = "wss://" + r.Addr[8:]
} else {
c.BaseURL = "https://" + r.Addr
c.BaseWSURL = "wss://" + r.Addr
}
c.Transport = "https"
c.Http.Transport = tr
c.loadServerCert()
c.Remote = &r
}
} else {
return nil, fmt.Errorf(i18n.G("unknown remote name: %q"), remote)
}
return &c, nil
}
示例8: imgPostURLInfo
func imgPostURLInfo(d *Daemon, req imagePostReq, op *operation) error {
var err error
if req.Source["url"] == "" {
return fmt.Errorf("Missing URL")
}
// Resolve the image URL
if d.tlsconfig == nil {
d.tlsconfig, err = shared.GetTLSConfig(d.certf, d.keyf)
if err != nil {
return err
}
}
tr := &http.Transport{
TLSClientConfig: d.tlsconfig,
Dial: shared.RFC3493Dialer,
Proxy: http.ProxyFromEnvironment,
}
myhttp := http.Client{
Transport: tr,
}
head, err := http.NewRequest("HEAD", req.Source["url"], nil)
if err != nil {
return err
}
architecturesStr := []string{}
for _, arch := range d.architectures {
architecturesStr = append(architecturesStr, fmt.Sprintf("%d", arch))
}
head.Header.Set("User-Agent", shared.UserAgent)
head.Header.Set("LXD-Server-Architectures", strings.Join(architecturesStr, ", "))
head.Header.Set("LXD-Server-Version", shared.Version)
raw, err := myhttp.Do(head)
if err != nil {
return err
}
hash := raw.Header.Get("LXD-Image-Hash")
if hash == "" {
return fmt.Errorf("Missing LXD-Image-Hash header")
}
url := raw.Header.Get("LXD-Image-URL")
if url == "" {
return fmt.Errorf("Missing LXD-Image-URL header")
}
// Import the image
err = d.ImageDownload(op,
url, hash, "", false, true)
if err != nil {
return err
}
info, err := dbImageGet(d.db, hash, false, false)
if err != nil {
return err
}
if req.Public {
err = dbImageSetPublic(d.db, info.Id, req.Public)
if err != nil {
return err
}
}
metadata := make(map[string]string)
metadata["fingerprint"] = info.Fingerprint
metadata["size"] = strconv.FormatInt(info.Size, 10)
op.UpdateMetadata(metadata)
return nil
}
示例9: createFromMigration
func createFromMigration(d *Daemon, req *containerPostReq) Response {
if req.Source.Mode != "pull" {
return NotImplemented
}
run := func(op *operation) error {
args := containerArgs{
Architecture: req.Architecture,
BaseImage: req.Source.BaseImage,
Config: req.Config,
Ctype: cTypeRegular,
Devices: req.Devices,
Ephemeral: req.Ephemeral,
Name: req.Name,
Profiles: req.Profiles,
}
var c container
_, err := dbImageGet(d.db, req.Source.BaseImage, false, true)
/* Only create a container from an image if we're going to
* rsync over the top of it. In the case of a better file
* transfer mechanism, let's just use that.
*
* TODO: we could invent some negotiation here, where if the
* source and sink both have the same image, we can clone from
* it, but we have to know before sending the snapshot that
* we're sending the whole thing or just a delta from the
* image, so one extra negotiation round trip is needed. An
* alternative is to move actual container object to a later
* point and just negotiate it over the migration control
* socket. Anyway, it'll happen later :)
*/
if err == nil && d.Storage.MigrationType() == MigrationFSType_RSYNC {
c, err = containerCreateFromImage(d, args, req.Source.BaseImage)
if err != nil {
return err
}
} else {
c, err = containerCreateAsEmpty(d, args)
if err != nil {
return err
}
}
config, err := shared.GetTLSConfig(d.certf, d.keyf)
if err != nil {
c.Delete()
return err
}
migrationArgs := MigrationSinkArgs{
Url: req.Source.Operation,
Dialer: websocket.Dialer{
TLSClientConfig: config,
NetDial: shared.RFC3493Dialer},
Container: c,
Secrets: req.Source.Websockets,
}
sink, err := NewMigrationSink(&migrationArgs)
if err != nil {
c.Delete()
return err
}
// Start the storage for this container (LVM mount/umount)
c.StorageStart()
// And finaly run the migration.
err = sink()
if err != nil {
c.StorageStop()
shared.Log.Error("Error during migration sink", "err", err)
c.Delete()
return fmt.Errorf("Error transferring container data: %s", err)
}
defer c.StorageStop()
err = c.TemplateApply("copy")
if err != nil {
return err
}
return nil
}
resources := map[string][]string{}
resources["containers"] = []string{req.Name}
op, err := operationCreate(operationClassTask, resources, nil, run, nil, nil)
if err != nil {
return InternalError(err)
}
return OperationResponse(op)
}
示例10: createFromMigration
func createFromMigration(d *Daemon, req *containerPostReq) Response {
if req.Source.Mode != "pull" {
return NotImplemented
}
run := func() shared.OperationResult {
createArgs := containerLXDArgs{
Ctype: cTypeRegular,
Config: req.Config,
Profiles: req.Profiles,
Ephemeral: req.Ephemeral,
BaseImage: req.Source.BaseImage,
}
var c container
if _, err := dbImageGet(d.db, req.Source.BaseImage, false, true); err == nil {
c, err = containerLXDCreateFromImage(
d, req.Name, createArgs, req.Source.BaseImage)
if err != nil {
return shared.OperationError(err)
}
} else {
c, err = containerLXDCreateAsEmpty(d, req.Name, createArgs)
if err != nil {
return shared.OperationError(err)
}
}
config, err := shared.GetTLSConfig(d.certf, d.keyf)
if err != nil {
c.Delete()
return shared.OperationError(err)
}
args := MigrationSinkArgs{
Url: req.Source.Operation,
Dialer: websocket.Dialer{
TLSClientConfig: config,
NetDial: shared.RFC3493Dialer},
Container: c,
Secrets: req.Source.Websockets,
}
sink, err := NewMigrationSink(&args)
if err != nil {
c.Delete()
return shared.OperationError(err)
}
// Start the storage for this container (LVM mount/umount)
c.StorageStart()
// And finaly run the migration.
err = sink()
if err != nil {
c.StorageStop()
c.Delete()
return shared.OperationError(fmt.Errorf("Error transferring container data: %s", err))
}
defer c.StorageStop()
err = c.TemplateApply("copy")
if err != nil {
return shared.OperationError(err)
}
return shared.OperationError(nil)
}
resources := make(map[string][]string)
resources["containers"] = []string{req.Name}
return &asyncResponse{run: run, resources: resources}
}
示例11: imgPostURLInfo
func imgPostURLInfo(d *Daemon, req imagePostReq, op *operation) error {
var err error
if req.Source["url"] == "" {
return fmt.Errorf("Missing URL")
}
// Resolve the image URL
tlsConfig, err := shared.GetTLSConfig("", "", "", nil)
if err != nil {
return err
}
tr := &http.Transport{
TLSClientConfig: tlsConfig,
Dial: shared.RFC3493Dialer,
Proxy: d.proxy,
}
myhttp := http.Client{
Transport: tr,
}
head, err := http.NewRequest("HEAD", req.Source["url"], nil)
if err != nil {
return err
}
architecturesStr := []string{}
for _, arch := range d.architectures {
architecturesStr = append(architecturesStr, fmt.Sprintf("%d", arch))
}
head.Header.Set("User-Agent", shared.UserAgent)
head.Header.Set("LXD-Server-Architectures", strings.Join(architecturesStr, ", "))
head.Header.Set("LXD-Server-Version", shared.Version)
raw, err := myhttp.Do(head)
if err != nil {
return err
}
hash := raw.Header.Get("LXD-Image-Hash")
if hash == "" {
return fmt.Errorf("Missing LXD-Image-Hash header")
}
url := raw.Header.Get("LXD-Image-URL")
if url == "" {
return fmt.Errorf("Missing LXD-Image-URL header")
}
// Import the image
hash, err = d.ImageDownload(op, url, "direct", "", "", hash, false, req.AutoUpdate)
if err != nil {
return err
}
id, info, err := dbImageGet(d.db, hash, false, false)
if err != nil {
return err
}
// Allow overriding or adding properties
for k, v := range req.Properties {
info.Properties[k] = v
}
if req.Public || req.AutoUpdate || req.Filename != "" || len(req.Properties) > 0 {
err = dbImageUpdate(d.db, id, req.Filename, info.Size, req.Public, req.AutoUpdate, info.Architecture, info.CreationDate, info.ExpiryDate, info.Properties)
if err != nil {
return err
}
}
metadata := make(map[string]string)
metadata["fingerprint"] = info.Fingerprint
metadata["size"] = strconv.FormatInt(info.Size, 10)
op.UpdateMetadata(metadata)
return nil
}
示例12: UpdateHTTPsPort
func (d *Daemon) UpdateHTTPsPort(oldAddress string, newAddress string) error {
var sockets []Socket
if oldAddress == newAddress {
return nil
}
if oldAddress != "" {
oldHost, oldPort, err := net.SplitHostPort(oldAddress)
if err != nil {
oldHost = oldAddress
oldPort = shared.DefaultPort
}
// Strip brackets around IPv6 once we've gotten rid of the port
oldHost = strings.TrimLeft(oldHost, "[")
oldHost = strings.TrimRight(oldHost, "]")
for _, socket := range d.Sockets {
host, port, err := net.SplitHostPort(socket.Socket.Addr().String())
if err != nil {
host = socket.Socket.Addr().String()
port = shared.DefaultPort
}
// Strip brackets around IPv6 once we've gotten rid of the port
host = strings.TrimLeft(host, "[")
host = strings.TrimRight(host, "]")
if !shared.PathExists(host) && IpsEqual(net.ParseIP(host), net.ParseIP(oldHost)) && port == oldPort {
socket.Socket.Close()
} else {
sockets = append(sockets, socket)
}
}
} else {
sockets = d.Sockets
}
if newAddress != "" {
_, _, err := net.SplitHostPort(newAddress)
if err != nil {
ip := net.ParseIP(newAddress)
if ip != nil && ip.To4() == nil {
newAddress = fmt.Sprintf("[%s]:%s", newAddress, shared.DefaultPort)
} else {
newAddress = fmt.Sprintf("%s:%s", newAddress, shared.DefaultPort)
}
}
tlsConfig, err := shared.GetTLSConfig(d.certf, d.keyf)
if err != nil {
return err
}
tcpl, err := tls.Listen("tcp", newAddress, tlsConfig)
if err != nil {
return fmt.Errorf("cannot listen on https socket: %v", err)
}
d.tomb.Go(func() error { return http.Serve(tcpl, d.mux) })
sockets = append(sockets, Socket{Socket: tcpl, CloseOnExit: true})
}
d.Sockets = sockets
return nil
}
示例13: NewClient
// NewClient returns a new LXD client.
func NewClient(config *Config, remote string) (*Client, error) {
c := Client{
config: *config,
http: http.Client{},
}
c.name = remote
// TODO: Here, we don't support configurable local remotes, we only
// support the default local LXD at /var/lib/lxd/unix.socket.
if remote == "" {
c.BaseURL = "http://unix.socket"
c.BaseWSURL = "ws://unix.socket"
c.Transport = "unix"
c.http.Transport = &unixTransport
c.websocketDialer.NetDial = unixDial
} else if r, ok := config.Remotes[remote]; ok {
if r.Addr[0:5] == "unix:" {
c.BaseURL = "http://unix.socket"
c.BaseWSURL = "ws://unix.socket"
c.Transport = "unix"
uDial := func(networ, addr string) (net.Conn, error) {
var err error
var raddr *net.UnixAddr
if r.Addr[7:] == "unix://" {
raddr, err = net.ResolveUnixAddr("unix", r.Addr[7:])
} else {
raddr, err = net.ResolveUnixAddr("unix", r.Addr[5:])
}
if err != nil {
return nil, err
}
return net.DialUnix("unix", nil, raddr)
}
c.http.Transport = &http.Transport{Dial: uDial}
c.websocketDialer.NetDial = uDial
c.Remote = &r
} else {
certf, keyf, err := readMyCert()
if err != nil {
return nil, err
}
tlsconfig, err := shared.GetTLSConfig(certf, keyf)
if err != nil {
return nil, err
}
tr := &http.Transport{
TLSClientConfig: tlsconfig,
Dial: shared.RFC3493Dialer,
Proxy: http.ProxyFromEnvironment,
}
c.websocketDialer = websocket.Dialer{
NetDial: shared.RFC3493Dialer,
TLSClientConfig: tlsconfig,
}
c.certf = certf
c.keyf = keyf
if r.Addr[0:8] == "https://" {
c.BaseURL = "https://" + r.Addr[8:]
c.BaseWSURL = "wss://" + r.Addr[8:]
} else {
c.BaseURL = "https://" + r.Addr
c.BaseWSURL = "wss://" + r.Addr
}
c.Transport = "https"
c.http.Transport = tr
c.loadServerCert()
c.Remote = &r
}
} else {
return nil, fmt.Errorf(gettext.Gettext("unknown remote name: %q"), remote)
}
if err := c.Finger(); err != nil {
return nil, err
}
return &c, nil
}
示例14: Init
//.........这里部分代码省略.........
}
}()
/* Setup /dev/lxd */
d.devlxd, err = createAndBindDevLxd()
if err != nil {
return err
}
if err := setupSharedMounts(); err != nil {
return err
}
var tlsConfig *tls.Config
if !d.IsMock {
err = d.SetupStorageDriver()
if err != nil {
return fmt.Errorf("Failed to setup storage: %s", err)
}
/* Restart containers */
containersRestart(d)
containersWatch(d)
/* Setup the TLS authentication */
certf, keyf, err := readMyCert()
if err != nil {
return err
}
d.certf = certf
d.keyf = keyf
readSavedClientCAList(d)
tlsConfig, err = shared.GetTLSConfig(d.certf, d.keyf)
if err != nil {
return err
}
}
/* Setup the web server */
d.mux = mux.NewRouter()
d.mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
SyncResponse(true, []string{"/1.0"}).Render(w)
})
for _, c := range api10 {
d.createCmd("1.0", c)
}
d.mux.NotFoundHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
shared.Log.Debug("Sending top level 404", log.Ctx{"url": r.URL})
w.Header().Set("Content-Type", "application/json")
NotFound.Render(w)
})
listeners, err := activation.Listeners(false)
if err != nil {
return err
}
var sockets []Socket
if len(listeners) > 0 {
shared.Log.Info("LXD is socket activated")
示例15: StartDaemon
// StartDaemon starts the shared daemon with the provided configuration.
func StartDaemon(listenAddr string) (*Daemon, error) {
d := &Daemon{}
d.lxcpath = shared.VarPath("lxc")
err := os.MkdirAll(shared.VarPath("/"), 0755)
if err != nil {
return nil, err
}
err = os.MkdirAll(d.lxcpath, 0755)
if err != nil {
return nil, err
}
d.BackingFs, err = shared.GetFilesystem(d.lxcpath)
if err != nil {
shared.Debugf("Error detecting backing fs: %s\n", err)
}
certf, keyf, err := readMyCert()
if err != nil {
return nil, err
}
d.certf = certf
d.keyf = keyf
err = initDb(d)
if err != nil {
return nil, err
}
readSavedClientCAList(d)
d.mux = mux.NewRouter()
d.mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
SyncResponse(true, []string{"/1.0"}).Render(w)
})
for _, c := range api10 {
d.createCmd("1.0", c)
}
d.mux.NotFoundHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
shared.Debugf("sending top level 404: %s", r.URL)
w.Header().Set("Content-Type", "application/json")
NotFound.Render(w)
})
d.IdmapSet, err = shared.DefaultIdmapSet()
if err != nil {
shared.Logf("error reading idmap: %s", err.Error())
shared.Logf("operations requiring idmap will not be available")
} else {
shared.Debugf("Default uid/gid map:")
for _, lxcmap := range d.IdmapSet.ToLxcString() {
shared.Debugf(" - " + lxcmap)
}
}
tlsConfig, err := shared.GetTLSConfig(d.certf, d.keyf)
if err != nil {
return nil, err
}
listeners, err := activation.Listeners(false)
if err != nil {
return nil, err
}
var localSockets []net.Listener
var remoteSockets []net.Listener
if len(listeners) > 0 {
shared.Debugf("LXD is socket activated.\n")
for _, listener := range listeners {
if _, err := os.Stat(listener.Addr().String()); err == nil {
localSockets = append(localSockets, listener)
} else {
tlsListener := tls.NewListener(listener, tlsConfig)
remoteSockets = append(remoteSockets, tlsListener)
}
}
} else {
shared.Debugf("LXD isn't socket activated.\n")
localSocketPath := shared.VarPath("unix.socket")
// If the socket exists, let's try to connect to it and see if there's
// a lxd running.
if _, err := os.Stat(localSocketPath); err == nil {
c := &lxd.Config{Remotes: map[string]lxd.RemoteConfig{}}
_, err := lxd.NewClient(c, "")
if err != nil {
shared.Debugf("Detected old but dead unix socket, deleting it...")
// Connecting failed, so let's delete the socket and
// listen on it ourselves.
err = os.Remove(localSocketPath)
//.........这里部分代码省略.........