FQDN in SET_HOSTNAME

Fairly new to ONE and have what may be a n00b question. I am trying to set FQDN in context using SET_HOSTNAME="$NAME.example.com". The machine keeps coming back online as $NAME-example-com. Is there a way to keep the dots or is there a way to set $DOMAIN and use that?

Thanks

Tony

The info is here:

http://docs.opennebula.org/5.0/operation/vm_setup/kvm.html

and here:

http://docs.opennebula.org/5.0/operation/references/template.html#template-context

Make sure you have installed the context packages in the VM.

Thanks for the reply!

So yeah I am using the Centos image from marketplace and I verified that it has context packages installed in the VM.

I tried adding $DOMAIN as a custom variable and then SET_HOSTNAME as $NAME.$DOMAIN and that didn’t work. Also, when I put FQDN into SET_HOSTNAME the dots are replaced with “-” when instantiated on the VM.

I am sure that I can come up with some script that gets FQDN set after first boot, or bake it into the image, but it looks like there should be a way when I am instantiating.

I also just tried leaving it $NAME and added the machine as test.example.com. It shows up as “test.example.com” in sunstone, but on the VM the hostname is “test-example-com”.

Can you post the output of onetemplate show and onevm show for the template
and the resulting instantiated VM?

Sure…this is REALLY weird. Looks like it should be working. I also posted the hostname command at the end showing the dashes.

onetemplate show 0 --------->

TEMPLATE 0 INFORMATION
ID : 0
NAME : CentOS 7.2 - KVM
USER : oneadmin
GROUP : oneadmin
REGISTER TIME : 06/15 14:56:49

PERMISSIONS
OWNER : um-
GROUP : —
OTHER : —

TEMPLATE CONTENTS
CONTEXT=[
DOMAIN=“dkistdc.nso.edu”,
NETWORK=“YES”,
SET_HOSTNAME="$NAME",
SSH_PUBLIC_KEY="$USER[SSH_PUBLIC_KEY]",
START_SCRIPT="#!/bin/sh
if [ ! -f /etc/salt/minion ]; then
yum clean all
yum -y update
yum -y install salt-minion
systemctl enable salt-minion.service
systemctl start salt-minion.service
fi" ]
CPU="1"
DISK=[
IMAGE=“CentOS 7.2 - KVM”,
IMAGE_UNAME=“oneadmin” ]
DISK=[
IMAGE=“Test Disk”,
IMAGE_UNAME=“thays” ]
GRAPHICS=[
LISTEN=“0.0.0.0”,
TYPE=“VNC” ]
LOGO="images/logos/centos.png"
MEMORY="768"
NIC=[
NETWORK=“Mgmt”,
NETWORK_UNAME=“oneadmin” ]
OS=[
ARCH=“x86_64” ]

onevm show 71 output ------->

VIRTUAL MACHINE 71 INFORMATION
ID : 71
NAME : dnstest2.dkistdc.nso.edu
USER : thays
GROUP : oneadmin
STATE : ACTIVE
LCM_STATE : RUNNING
RESCHED : No
HOST : drax
CLUSTER ID : 0
CLUSTER : default
START TIME : 08/02 07:52:54
END TIME : -
DEPLOY ID : one-71

VIRTUAL MACHINE MONITORING
CPU : 74.94
MEMORY : 1G
NETTX : 1.6M
NETRX : 222.6M

PERMISSIONS
OWNER : um-
GROUP : —
OTHER : —

VM DISKS
ID DATASTORE TARGET IMAGE SIZE TYPE SAVE
0 default vda CentOS 7.2 - KVM 1.2G/8G file NO
1 default vdb Test Disk 1000M/100 file NO
2 - hda CONTEXT 1M/- - -

VM NICS
ID NETWORK BRIDGE IP MAC PCI_ID
0 Mgmt br0 10.224.128.205 02:00:0a:e0:80:cd

SECURITY

NIC_ID NETWORK SECURITY_GROUPS
0 Mgmt 0

SECURITY GROUP TYPE PROTOCOL NETWORK RANGE
ID NAME VNET START SIZE
0 default OUTBOUND ALL
0 default INBOUND ALL

VIRTUAL MACHINE HISTORY
SEQ HOST ACTION DS START TIME PROLOG
0 drax none 0 08/02 07:53:13 0d 00h07m 0h00m19s

USER TEMPLATE
LOGO=“images/logos/centos.png”

VIRTUAL MACHINE TEMPLATE
AUTOMATIC_DS_REQUIREMENTS="“CLUSTERS/ID” @> 0"
AUTOMATIC_REQUIREMENTS="(CLUSTER_ID = 0) & !(PUBLIC_CLOUD = YES)“
CONTEXT=[
DISK_ID=“2”,
DOMAIN=“dkistdc.nso.edu”,
ETH0_CONTEXT_FORCE_IPV4=”",
ETH0_DNS=“10.224.128.13”,
ETH0_GATEWAY=“10.224.128.1”,
ETH0_GATEWAY6="",
ETH0_IP=“10.224.128.205”,
ETH0_IP6="",
ETH0_IP6_ULA="",
ETH0_MAC=“02:00:0a:e0:80:cd”,
ETH0_MASK="",
ETH0_MTU="",
ETH0_NETWORK="",
ETH0_SEARCH_DOMAIN=“dkistdc.nso.edu”,
ETH0_VLAN_ID="",
ETH0_VROUTER_IP="",
ETH0_VROUTER_IP6="",
ETH0_VROUTER_MANAGEMENT="",
NETWORK=“YES”,
SET_HOSTNAME=“dnstest2.dkistdc.nso.edu”,
SSH_PUBLIC_KEY=“ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDdI0ldF55NEfr/mSSZL/Ft4kjuJnuzTftwunYI/x63ORJFf/LclNOGGqSRPlxYPBZXAPbImu1O9qndn9XLcJYZuTRgWIXQOJXmlxjtN3BNI1VGYWSyhloyslCbEviMKklkjYBzDy4+aBgciyGzKsEDe4XF9pcPPfhQLWHRrvCQ1Jq6hXDSTjfCJ2PiaTMf5oZqmfnguDfDgfjdjCb3YVrPW7rpHzKjg1+MFAQt3GujnQwQkMKbDQrGmCzFNKeRoyAx4YWwykF1T3eHSCr1QLa7IcASQTz1kZsqNkDY8H8ygW7JaU1RV96p1Qor9jq2PKbv4BZhFVVfitYWTe+H6LFz”,
START_SCRIPT="#!/bin/sh
if [ ! -f /etc/salt/minion ]; then
yum clean all
yum -y update
yum -y install salt-minion
systemctl enable salt-minion.service
systemctl start salt-minion.service
fi",
TARGET=“hda” ]
CPU="1"
GRAPHICS=[
LISTEN=“0.0.0.0”,
PORT=“5971”,
TYPE=“VNC” ]
MEMORY="1024"
OS=[
ARCH=“x86_64” ]
TEMPLATE_ID="0"
VMID=“71”

hostname output ---------------->

[root@dnstest2-dkistdc-nso-edu ~]# hostname
dnstest2-dkistdc-nso-edu

Yes you are right SET_HOSTNAME is for the hostname which is different from the FQDN. Unsafe chars are explicitly removed:

echo “$SET_HOSTNAME” | sed -e ‘s/[^-a-zA-Z0-9]/-/g’ -e ‘s/^-​*//g’ -e 's/-*​$//g’
dnstest2-dkistdc-nso-edu

This is what is happening for the VM.

By the way, you can add SEARCH_DOMAIN and DNS in the Network template to
configure the DNS client for VMs in that network…

So the “.” is an unsafe char?

I have the SEARCH_DOMAIN and DNS working now and it resolves great.

My main issue is that my config management relies on FQDN, so when it auto-registers itself without FQDN it is rejected.

Is there no way to escape the “.” to override and have SET_HOSTNAME be exact?

You can:

1.- Modify the context script

2.- Do it after context with something like hostname $NAME in the
START_SCRIPT as it is executed after the network set up.

That’s a good idea. Just keep it to shortname in ONE and handle it externally.

Thanks so much for your help!

Do you know if context variables are passed into the startup script or do I need to set them there as well?

They should be available

Hi Ruben,

So I ended up with a pretty good solution, I think. I have SET_HOSTNAME=$NIC[IP]-$UNAME-$VMID. Once I instantiate this becomes x-x-x-x-thays-x as the hostname, on the box which is exactly what I am looking for. I am trying to figure out what is swapping out the delimiter. Is this base64 encoding that is actually swapping the “.” for the “-”? I have a dns hook that uses SET_HOSTNAME and it actually shows up as x.x.x.x-thays-x, and it is conflicting with the name that was set by the template.

Where does this sed take place?

I found the sed in addon-context-linux. Is there a reason that “.” is considered unsafe? Is the code just manipulating the text so it can be standard input to hostnamectl? For example, collapsing spaces. I feel like there must be some history here I am missing.

Thanks

for hostname, “.” is consider unsafe because “.” is used as delimiter between hostname and domain. So the parameter “SET_HOSTNAME” is passing the hostname only.

So if you need to append the domain name, modify the one-context script (/etc/one-context.d/05-hostname) and add the domain

Perfect…Thanks for the reply.

I’m thinking that setting FQDN is useful but I’m not sure how to implement this.

  • Remove “.” restriction from SET_HOSTNAME
  • Add SET_DOMAIN and use it to set the FQDN

I believe that letting use “.” is the most straightforward solution and maybe what people expect.

I prefer the second option using the “SET_DOMAIN” or use “SET_FQDN”