Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions api/src/main/java/com/cloud/network/NetworkModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,20 @@ public interface NetworkModel {
String PUBLIC_KEYS_FILE = "public-keys";
String CLOUD_IDENTIFIER_FILE = "cloud-identifier";
String HYPERVISOR_HOST_NAME_FILE = "hypervisor-host-name";
String CLOUD_DOMAIN_FILE = "cloud-domain";
String CLOUD_DOMAIN_ID_FILE = "cloud-domain-id";
int CONFIGDATA_DIR = 0;
int CONFIGDATA_FILE = 1;
int CONFIGDATA_CONTENT = 2;
ImmutableMap<String, String> openStackFileMapping = ImmutableMap.of(
AVAILABILITY_ZONE_FILE, "availability_zone",
LOCAL_HOSTNAME_FILE, "hostname",
VM_ID_FILE, "uuid",
PUBLIC_HOSTNAME_FILE, "name"
);
ImmutableMap<String, String> openStackFileMapping = ImmutableMap.<String, String>builder()
.put(AVAILABILITY_ZONE_FILE, "availability_zone")
.put(LOCAL_HOSTNAME_FILE, "hostname")
.put(VM_ID_FILE, "uuid")
.put(PUBLIC_HOSTNAME_FILE, "name")
.put(CLOUD_DOMAIN_FILE, CLOUD_DOMAIN_FILE)
.put(CLOUD_DOMAIN_ID_FILE, CLOUD_DOMAIN_ID_FILE)
.put(HYPERVISOR_HOST_NAME_FILE, HYPERVISOR_HOST_NAME_FILE)
.build();

static final ConfigKey<Integer> MACIdentifier = new ConfigKey<Integer>("Advanced",Integer.class, "mac.identifier", "0",
"This value will be used while generating the mac addresses for isolated and shared networks. The hexadecimal equivalent value will be present at the 2nd octet of the mac address. Default value is null which means this feature is disabled.Its scope is global.", true, ConfigKey.Scope.Global);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ public interface VirtualMachineManager extends Manager {
ConfigKey<Boolean> AllowExposeHypervisorHostname = new ConfigKey<Boolean>("Advanced", Boolean.class, "global.allow.expose.host.hostname",
"false", "If set to true, it allows the hypervisor host name on which the VM is spawned on to be exposed to the VM", true, ConfigKey.Scope.Global);

ConfigKey<Boolean> AllowExposeDomainInMetadata = new ConfigKey<>("Advanced", Boolean.class, "metadata.allow.expose.domain",
"false", "If set to true, it allows the VM's domain to be seen in metadata.", true, ConfigKey.Scope.Domain);

interface Topics {
String VM_POWER_STATE = "vm.powerstate";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4611,7 +4611,9 @@ public ConfigKey<?>[] getConfigKeys() {
return new ConfigKey<?>[] { ClusterDeltaSyncInterval, StartRetry, VmDestroyForcestop, VmOpCancelInterval, VmOpCleanupInterval, VmOpCleanupWait,
VmOpLockStateRetry, VmOpWaitInterval, ExecuteInSequence, VmJobCheckInterval, VmJobTimeout, VmJobStateReportInterval,
VmConfigDriveLabel, VmConfigDriveOnPrimaryPool, VmConfigDriveForceHostCacheUse, VmConfigDriveUseHostCacheOnUnsupportedPool,
HaVmRestartHostUp, ResourceCountRunningVMsonly, AllowExposeHypervisorHostname, AllowExposeHypervisorHostnameAccountLevel, SystemVmRootDiskSize };
HaVmRestartHostUp, ResourceCountRunningVMsonly, AllowExposeHypervisorHostname, AllowExposeHypervisorHostnameAccountLevel, SystemVmRootDiskSize,
AllowExposeDomainInMetadata
};
}

public List<StoragePoolAllocator> getStoragePoolAllocators() {
Expand Down
14 changes: 14 additions & 0 deletions server/src/main/java/com/cloud/network/NetworkModelImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import javax.inject.Inject;
import javax.naming.ConfigurationException;

import com.cloud.domain.Domain;
import com.cloud.vm.VirtualMachineManager;
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
Expand Down Expand Up @@ -2551,6 +2553,10 @@ public List<String[]> generateVmData(String userData, String serviceOffering, lo
final String zoneName = dcVo.getName();

IPAddressVO publicIp = _ipAddressDao.findByAssociatedVmId(vmId);
VirtualMachine vm = _vmDao.findById(vmId);
if (vm == null) {
throw new CloudRuntimeException(String.format("Cannot generate VM instance data, no VM exists by ID: %d", vmId));
}

final List<String[]> vmData = new ArrayList<String[]>();

Expand Down Expand Up @@ -2619,6 +2625,14 @@ public List<String[]> generateVmData(String userData, String serviceOffering, lo
vmData.add(new String[]{PASSWORD_DIR, PASSWORD_FILE, password});
}
vmData.add(new String[]{METATDATA_DIR, HYPERVISOR_HOST_NAME_FILE, hostname});

Domain domain = _domainDao.findById(vm.getDomainId());
if (domain != null && VirtualMachineManager.AllowExposeDomainInMetadata.valueIn(domain.getId())) {
s_logger.debug("Adding domain info to cloud metadata");
Comment thread
mlsorensen marked this conversation as resolved.
vmData.add(new String[]{METATDATA_DIR, CLOUD_DOMAIN_FILE, domain.getName()});
vmData.add(new String[]{METATDATA_DIR, CLOUD_DOMAIN_ID_FILE, domain.getUuid()});
}

return vmData;
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

import javax.inject.Inject;

import com.cloud.domain.Domain;
import com.cloud.domain.dao.DomainDao;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
Expand Down Expand Up @@ -149,6 +151,8 @@ public class CommandSetupHelper {
@Inject
private EntityManager _entityMgr;

@Inject
private DomainDao domainDao;
@Inject
private NicDao _nicDao;
@Inject
Expand Down Expand Up @@ -210,11 +214,18 @@ public void createVmDataCommand(final VirtualRouter router, final UserVm vm, fin

Host host = _hostDao.findById(vm.getHostId());
String destHostname = VirtualMachineManager.getHypervisorHostname(host != null ? host.getName() : "");
cmds.addCommand(
"vmdata",
generateVmDataCommand(router, nic.getIPv4Address(), vm.getUserData(), serviceOffering, zoneName,
staticNatIp == null || staticNatIp.getState() != IpAddress.State.Allocated ? null : staticNatIp.getAddress().addr(), vm.getHostName(), vm.getInstanceName(),
vm.getId(), vm.getUuid(), publicKey, nic.getNetworkId(), destHostname));
VmDataCommand vmDataCommand = generateVmDataCommand(router, nic.getIPv4Address(), vm.getUserData(), serviceOffering, zoneName,
staticNatIp == null || staticNatIp.getState() != IpAddress.State.Allocated ? null : staticNatIp.getAddress().addr(), vm.getHostName(), vm.getInstanceName(),
vm.getId(), vm.getUuid(), publicKey, nic.getNetworkId(), destHostname);

Domain domain = domainDao.findById(vm.getDomainId());
if (domain != null && VirtualMachineManager.AllowExposeDomainInMetadata.valueIn(domain.getId())) {
s_logger.debug("Adding domain info to cloud metadata");
Comment thread
mlsorensen marked this conversation as resolved.
vmDataCommand.addVmData(NetworkModel.METATDATA_DIR, NetworkModel.CLOUD_DOMAIN_FILE, domain.getName());
vmDataCommand.addVmData(NetworkModel.METATDATA_DIR, NetworkModel.CLOUD_DOMAIN_ID_FILE, domain.getUuid());
}

cmds.addCommand("vmdata", vmDataCommand);
}
}

Expand Down
Loading