1
0
mirror of https://github.com/bingohuang/docker-labs.git synced 2025-10-04 17:33:21 +08:00

Add support for setting alias when creatign instance. (#140)

* Add support for setting alias when creatign instance.

The POST to create a instance now provides an `alias` field which
then can be used to access the instance services through the following
URL:

`http://<alias>-<short_session>-<port>.<tld>`

When creating a session you can now send an `alias`

* Remove unnecessary function

* Add alias support for DNS resolution
This commit is contained in:
Marcos Nils
2017-05-11 17:39:17 -03:00
committed by GitHub
parent 62c5d3761d
commit 61a0bb4db1
5 changed files with 59 additions and 6 deletions

View File

@@ -34,6 +34,7 @@ type Instance struct {
IsManager *bool `json:"is_manager"`
Mem string `json:"mem"`
Cpu string `json:"cpu"`
Alias string `json:"alias"`
Ports UInt16Slice
tempPorts []uint16 `json:"-"`
ServerCert []byte `json:"server_cert"`
@@ -96,7 +97,7 @@ func getDindImageName() string {
return dindImage
}
func NewInstance(session *Session, imageName string) (*Instance, error) {
func NewInstance(session *Session, imageName, alias string) (*Instance, error) {
if imageName == "" {
imageName = dindImage
}
@@ -105,6 +106,9 @@ func NewInstance(session *Session, imageName string) (*Instance, error) {
if err != nil {
return nil, err
}
instance.Alias = alias
instance.session = session
if session.Instances == nil {
@@ -174,6 +178,19 @@ func FindInstanceByIP(ip string) *Instance {
return nil
}
func FindInstanceByAlias(sessionPrefix, alias string) *Instance {
for id, s := range sessions {
if strings.HasPrefix(id, sessionPrefix) {
for _, i := range s.Instances {
if i.Alias == alias {
return i
}
}
}
}
return nil
}
func DeleteInstance(session *Session, instance *Instance) error {
if instance.conn != nil {
instance.conn.Close()