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:
@@ -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()
|
||||
|
Reference in New Issue
Block a user