Skip to content
This repository has been archived by the owner on Sep 26, 2021. It is now read-only.

Hostnames #219

Merged
merged 1 commit into from
Jan 14, 2015
Merged

Hostnames #219

merged 1 commit into from
Jan 14, 2015

Conversation

sthulb
Copy link
Contributor

@sthulb sthulb commented Jan 5, 2015

This work sets the machine name in the Cloud API or Hypervisor. As well
as setting the hostname inside the VM.

I've added the machine name to the NewDriver func to allow for
identification by Cloud APIs and for the driver package.

Each driver will attempt to set the hostname for the VM, except for
Azure, which sets it based on the DNS name.

Refs: #59

@@ -363,6 +363,14 @@ func (d *Driver) Create() error {
return err
}

cmd, err = d.GetSSHCommand(fmt.Sprintf("sudo hostname %s", d.MachineName))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe this will persist reboots will it (need to update /etc/hostname at least).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that persist on boot2docker? Perhaps we don't bother setting the hostname on boot2docker... I think the big win from this pull request is the correct name showing up in your cloud provider's admin (e.g. list of instances on EC2), not the hostname when you log in.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, it won't persist reboots. However one needs to update /usr/local/etc/hostname for it to persist on a b2d image.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bfirsh I'm going for naming all of the things.

@bfirsh
Copy link
Contributor

bfirsh commented Jan 6, 2015

Thanks for this @sthulb. The bit I'm really interested in is setting the correct name on cloud providers. E.g. on Digital Ocean, removing the concept of DropletName and just making the name of the droplet the name of the host.

@sthulb
Copy link
Contributor Author

sthulb commented Jan 6, 2015

EC2 support is kind of there, I can tag an instance with the machine ID, just the internal hostname remaining.

@sthulb
Copy link
Contributor Author

sthulb commented Jan 6, 2015

I moved how we set the hostname to the driver.Create func since different drivers need the hostname func to be called at different times.

@@ -225,9 +228,32 @@ func (d *Driver) Create() error {
return err
}

log.Infof("Settings tags for instance")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be Debug

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you prefer :)

@ehazlett
Copy link
Contributor

ehazlett commented Jan 6, 2015

@sthulb i like this so far -- good work!

@bfirsh
Copy link
Contributor

bfirsh commented Jan 7, 2015

Great stuff. Since a driver is always attached to a machine, perhaps the name should be passed to NewDriver?

@sthulb
Copy link
Contributor Author

sthulb commented Jan 7, 2015

@bfirsh It's something that should be considered when we need it in other places, but for now, I think leaving it on Create(name string) seems ok.

@sthulb
Copy link
Contributor Author

sthulb commented Jan 7, 2015

@bfirsh I take back my comment... azure kind of forces your idea.

@sthulb sthulb changed the title [wip] Hostnames Hostnames Jan 7, 2015
@sthulb
Copy link
Contributor Author

sthulb commented Jan 7, 2015

@bfirsh @ehazlett I think it's finished. someone should perhaps test the Azure & Google drivers

@ehazlett
Copy link
Contributor

ehazlett commented Jan 7, 2015

awesome! thanks -- I will check it out

On Wed, Jan 7, 2015 at 6:36 AM, Simon Thulbourn notifications@github.com
wrote:

@bfirsh https://github.com/bfirsh @ehazlett
https://github.com/ehazlett I think it's finished. someone should
perhaps test the Azure & Google drivers


Reply to this email directly or view it on GitHub
#219 (comment).

@ehazlett
Copy link
Contributor

ehazlett commented Jan 7, 2015

I'm getting "sudo: unable to resolve host test-ec2" with amazonec2. The hostname isn't added to /etc/hosts. You may need to silence this for the first sudo to add it but I think it would be good otherwise it will spit this out for every sudo command.

@sthulb
Copy link
Contributor Author

sthulb commented Jan 7, 2015

I'll alter the PR to add to the hosts file also.

@ehazlett
Copy link
Contributor

ehazlett commented Jan 7, 2015

@sthulb thanks

@ehazlett
Copy link
Contributor

ehazlett commented Jan 8, 2015

@sthulb i'm also getting the following with azure:

FATA[0004] A hosted service with the specified name already exists.

It's not happening in master.

@sthulb
Copy link
Contributor Author

sthulb commented Jan 8, 2015

I've fixed the sudo thing.

@sthulb
Copy link
Contributor Author

sthulb commented Jan 8, 2015

So Azure likes globally unique names... so the best we can do is: foo-<timestamp> for azure, which sucks. Unless someone knows differently?

@jeffmendoza
Copy link
Contributor

In Azure, your VM sits inside a "Cloud Service." The cloud service must have a globally unique name, as it's used for DNS: .cloudapp.net. The VM can have any name, and that will be the hostname of the VM.

@ehazlett
Copy link
Contributor

ehazlett commented Jan 8, 2015

@sthulb i think naming with a unique/timestamp is fine. it's just the cloud service and not the actual VM hostname which is what we want to name anyway.

@ehazlett
Copy link
Contributor

ehazlett commented Jan 8, 2015

@sthulb sorry to be nitpicky but I'm still getting a couple sudo: unable to resolve host test-ec2. We may need to > /dev/null 2>&1 or something to hide the initial set. wdyt?

@sthulb
Copy link
Contributor Author

sthulb commented Jan 8, 2015

That's fine, ... I just need to track down the origin of it...

@sthulb
Copy link
Contributor Author

sthulb commented Jan 9, 2015

@ehazlett This should be good to merge now.

@ehazlett
Copy link
Contributor

ehazlett commented Jan 9, 2015

@sthulb Hmm I keep getting this error with EC2:

Error creating host: Error decoding error response: Error decoding error response: http: read on closed response body

Have you ran into that?

@sthulb
Copy link
Contributor Author

sthulb commented Jan 9, 2015

Not at all.

@ehazlett
Copy link
Contributor

ehazlett commented Jan 9, 2015

Hmm ok -- may be AWS. I'll try again -- thx

@sthulb
Copy link
Contributor Author

sthulb commented Jan 9, 2015

Perhaps we can get @bfirsh try it too.

@ehazlett
Copy link
Contributor

ehazlett commented Jan 9, 2015

@sthulb can you do a fresh build and confirm it's not doing it? It's not doing it to me in master.

@ehazlett
Copy link
Contributor

ehazlett commented Jan 9, 2015

@sthulb +1 /cc @bfirsh

@@ -147,9 +145,24 @@ func (d *Driver) Create() error {
return err
}

log.Debugf("Setting hostname: %s", d.MachineName)
cmd, err := d.GetSSHCommand(fmt.Sprintf(
"echo \"127.0.0.1 %s\" | sudo tee -a /etc/hosts && sudo hostname %s && echo \"%s\" | sudo tee /etc/hostname",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't Digital Ocean set the hostname to be the droplet name?

@sthulb
Copy link
Contributor Author

sthulb commented Jan 9, 2015

@ehazlett I think I've figured out why you get it... By any chance, do you already have a security group with the same group name?

@ehazlett
Copy link
Contributor

ehazlett commented Jan 9, 2015

yep. looks like it was left over from a previous run. i will remove and
test. thanks!

On Fri, Jan 9, 2015 at 2:21 PM, Simon Thulbourn notifications@github.com
wrote:

@ehazlett https://github.com/ehazlett I think I've figured out why you
get it... By any chance, do you already have a security group with the same
group name?


Reply to this email directly or view it on GitHub
#219 (comment).

This work sets the machine name in the Cloud API or Hypervisor. As well
as setting the hostname inside the VM.

I've added the machine name to the NewDriver func to allow for
identification by Cloud APIs and for the driver package.

Each driver will attempt to set the hostname for the VM, except for
Azure, which sets it based on the DNS name.

Signed-off-by: Simon Thulbourn <simon+github@thulbourn.com>
@ehazlett
Copy link
Contributor

LGTM

ehazlett added a commit that referenced this pull request Jan 14, 2015
@ehazlett ehazlett merged commit c2f1fea into docker:master Jan 14, 2015
@sthulb sthulb deleted the hostnames branch January 16, 2015 16:15
tomeon pushed a commit to tomeon/machine that referenced this pull request May 9, 2018
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants