Skip to content

Commit bc51a42

Browse files
committed
Merge pull request #705 from borisroman/CLOUDSTACK-8736
Refactored NicProfile.java for readability.Only changed names and reorganized them! No functional implementation change. See issue CLOUDSTACK-8736 for ongoing effort to clean up network code. * pr/705: Refactored NicProfile.java for readability. Signed-off-by: Wido den Hollander <wido@widodh.nl>
2 parents 9c7e81e + 5db3371 commit bc51a42

File tree

44 files changed

+668
-640
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+668
-640
lines changed

api/src/com/cloud/vm/NicProfile.java

Lines changed: 242 additions & 201 deletions
Large diffs are not rendered by default.

engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,21 @@
3737
import javax.inject.Inject;
3838
import javax.naming.ConfigurationException;
3939

40-
import com.cloud.network.Networks;
41-
42-
import org.apache.log4j.Logger;
4340
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
4441
import org.apache.cloudstack.context.CallContext;
4542
import org.apache.cloudstack.engine.cloud.entity.api.db.VMNetworkMapVO;
4643
import org.apache.cloudstack.engine.cloud.entity.api.db.dao.VMNetworkMapDao;
4744
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
4845
import org.apache.cloudstack.framework.config.ConfigDepot;
4946
import org.apache.cloudstack.framework.config.ConfigKey;
50-
import org.apache.cloudstack.framework.config.Configurable;
5147
import org.apache.cloudstack.framework.config.ConfigKey.Scope;
48+
import org.apache.cloudstack.framework.config.Configurable;
5249
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
5350
import org.apache.cloudstack.framework.messagebus.MessageBus;
5451
import org.apache.cloudstack.framework.messagebus.PublishScope;
5552
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
5653
import org.apache.cloudstack.region.PortableIpDao;
54+
import org.apache.log4j.Logger;
5755

5856
import com.cloud.agent.AgentManager;
5957
import com.cloud.agent.Listener;
@@ -111,6 +109,7 @@
111109
import com.cloud.network.NetworkModel;
112110
import com.cloud.network.NetworkProfile;
113111
import com.cloud.network.NetworkStateListener;
112+
import com.cloud.network.Networks;
114113
import com.cloud.network.Networks.BroadcastDomainType;
115114
import com.cloud.network.Networks.TrafficType;
116115
import com.cloud.network.PhysicalNetwork;
@@ -839,16 +838,16 @@ protected Integer applyProfileToNic(NicVO vo, NicProfile profile, Integer device
839838

840839
vo.setDefaultNic(profile.isDefaultNic());
841840

842-
vo.setIp4Address(profile.getIp4Address());
841+
vo.setIp4Address(profile.getIPv4Address());
843842
vo.setAddressFormat(profile.getFormat());
844843

845844
if (profile.getMacAddress() != null) {
846845
vo.setMacAddress(profile.getMacAddress());
847846
}
848847

849848
vo.setMode(profile.getMode());
850-
vo.setNetmask(profile.getNetmask());
851-
vo.setGateway(profile.getGateway());
849+
vo.setNetmask(profile.getIPv4Netmask());
850+
vo.setGateway(profile.getIPv4Gateway());
852851

853852
if (profile.getBroadCastUri() != null) {
854853
vo.setBroadcastUri(profile.getBroadCastUri());
@@ -860,25 +859,25 @@ protected Integer applyProfileToNic(NicVO vo, NicProfile profile, Integer device
860859

861860
vo.setState(Nic.State.Allocated);
862861

863-
vo.setIp6Address(profile.getIp6Address());
864-
vo.setIp6Gateway(profile.getIp6Gateway());
865-
vo.setIp6Cidr(profile.getIp6Cidr());
862+
vo.setIp6Address(profile.getIPv6Address());
863+
vo.setIp6Gateway(profile.getIPv6Gateway());
864+
vo.setIp6Cidr(profile.getIPv6Cidr());
866865

867866
return deviceId;
868867
}
869868

870869
protected void applyProfileToNicForRelease(NicVO vo, NicProfile profile) {
871-
vo.setGateway(profile.getGateway());
870+
vo.setGateway(profile.getIPv4Gateway());
872871
vo.setAddressFormat(profile.getFormat());
873-
vo.setIp4Address(profile.getIp4Address());
874-
vo.setIp6Address(profile.getIp6Address());
872+
vo.setIp4Address(profile.getIPv4Address());
873+
vo.setIp6Address(profile.getIPv6Address());
875874
vo.setMacAddress(profile.getMacAddress());
876875
if (profile.getReservationStrategy() != null) {
877876
vo.setReservationStrategy(profile.getReservationStrategy());
878877
}
879878
vo.setBroadcastUri(profile.getBroadCastUri());
880879
vo.setIsolationUri(profile.getIsolationUri());
881-
vo.setNetmask(profile.getNetmask());
880+
vo.setNetmask(profile.getIPv4Netmask());
882881
}
883882

884883
protected void applyProfileToNetwork(NetworkVO network, NetworkProfile profile) {
@@ -896,8 +895,8 @@ protected NicTO toNicTO(NicVO nic, NicProfile profile, NetworkVO config) {
896895
to.setIp(nic.getIp4Address());
897896
to.setNetmask(nic.getNetmask());
898897
to.setMac(nic.getMacAddress());
899-
to.setDns1(profile.getDns1());
900-
to.setDns2(profile.getDns2());
898+
to.setDns1(profile.getIPv4Dns1());
899+
to.setDns2(profile.getIPv4Dns2());
901900
if (nic.getGateway() != null) {
902901
to.setGateway(nic.getGateway());
903902
} else {
@@ -910,8 +909,8 @@ protected NicTO toNicTO(NicVO nic, NicProfile profile, NetworkVO config) {
910909
to.setBroadcastUri(nic.getBroadcastUri());
911910
to.setIsolationuri(nic.getIsolationUri());
912911
if (profile != null) {
913-
to.setDns1(profile.getDns1());
914-
to.setDns2(profile.getDns2());
912+
to.setDns1(profile.getIPv4Dns1());
913+
to.setDns2(profile.getIPv4Dns2());
915914
}
916915

917916
Integer networkRate = _networkModel.getNetworkRate(config.getId(), null);
@@ -1240,7 +1239,7 @@ protected boolean prepareElement(NetworkElement element, Network network, NicPro
12401239
DhcpServiceProvider sp = (DhcpServiceProvider)element;
12411240
Map<Capability, String> dhcpCapabilities = element.getCapabilities().get(Service.Dhcp);
12421241
String supportsMultipleSubnets = dhcpCapabilities.get(Capability.DhcpAccrossMultipleSubnets);
1243-
if ((supportsMultipleSubnets != null && Boolean.valueOf(supportsMultipleSubnets)) && profile.getIp6Address() == null) {
1242+
if ((supportsMultipleSubnets != null && Boolean.valueOf(supportsMultipleSubnets)) && profile.getIPv6Address() == null) {
12441243
if (!sp.configDhcpSupportForSubnet(network, profile, vmProfile, dest, context)) {
12451244
return false;
12461245
}
@@ -1333,19 +1332,19 @@ public NicProfile prepareNic(VirtualMachineProfile vmProfile, DeployDestination
13331332

13341333
networkRate, _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vmProfile.getHypervisorType(), network));
13351334
guru.reserve(profile, network, vmProfile, dest, context);
1336-
nic.setIp4Address(profile.getIp4Address());
1335+
nic.setIp4Address(profile.getIPv4Address());
13371336
nic.setAddressFormat(profile.getFormat());
1338-
nic.setIp6Address(profile.getIp6Address());
1337+
nic.setIp6Address(profile.getIPv6Address());
13391338
nic.setMacAddress(profile.getMacAddress());
13401339
nic.setIsolationUri(profile.getIsolationUri());
13411340
nic.setBroadcastUri(profile.getBroadCastUri());
13421341
nic.setReserver(guru.getName());
13431342
nic.setState(Nic.State.Reserved);
1344-
nic.setNetmask(profile.getNetmask());
1345-
nic.setGateway(profile.getGateway());
1343+
nic.setNetmask(profile.getIPv4Netmask());
1344+
nic.setGateway(profile.getIPv4Gateway());
13461345

1347-
if (profile.getStrategy() != null) {
1348-
nic.setReservationStrategy(profile.getStrategy());
1346+
if (profile.getReservationStrategy() != null) {
1347+
nic.setReservationStrategy(profile.getReservationStrategy());
13491348
}
13501349

13511350
updateNic(nic, network.getId(), 1);
@@ -1478,9 +1477,9 @@ public void prepareAllNicsForMigration(VirtualMachineProfile vm, DeployDestinati
14781477
NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName());
14791478
NicProfile profile = new NicProfile();
14801479
profile.setDeviceId(255); //dummyId
1481-
profile.setIp4Address(userIp.getAddress().toString());
1482-
profile.setNetmask(publicIp.getNetmask());
1483-
profile.setGateway(publicIp.getGateway());
1480+
profile.setIPv4Address(userIp.getAddress().toString());
1481+
profile.setIPv4Netmask(publicIp.getNetmask());
1482+
profile.setIPv4Gateway(publicIp.getGateway());
14841483
profile.setMacAddress(publicIp.getMacAddress());
14851484
profile.setBroadcastType(network.getBroadcastDomainType());
14861485
profile.setTrafficType(network.getTrafficType());
@@ -3116,7 +3115,7 @@ protected NicProfile getNicProfileForVm(Network network, NicProfile requested, V
31163115
NicProfile nic = null;
31173116
if (requested != null && requested.getBroadCastUri() != null) {
31183117
String broadcastUri = requested.getBroadCastUri().toString();
3119-
String ipAddress = requested.getIp4Address();
3118+
String ipAddress = requested.getIPv4Address();
31203119
NicVO nicVO = _nicDao.findByNetworkIdInstanceIdAndBroadcastUri(network.getId(), vm.getId(), broadcastUri);
31213120
if (nicVO != null) {
31223121
if (ipAddress == null || nicVO.getIp4Address().equals(ipAddress)) {

plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BareMetalPingServiceImpl.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,17 @@
3030
import javax.ejb.Local;
3131
import javax.inject.Inject;
3232

33-
import com.cloud.network.Network;
34-
import org.apache.log4j.Logger;
35-
3633
import org.apache.cloudstack.api.AddBaremetalPxeCmd;
3734
import org.apache.cloudstack.api.AddBaremetalPxePingServerCmd;
3835
import org.apache.cloudstack.api.ListBaremetalPxeServersCmd;
36+
import org.apache.log4j.Logger;
3937

4038
import com.cloud.agent.api.Answer;
4139
import com.cloud.agent.api.baremetal.IpmISetBootDevCommand;
4240
import com.cloud.agent.api.baremetal.IpmISetBootDevCommand.BootDev;
41+
import com.cloud.agent.api.baremetal.PrepareCreateTemplateCommand;
4342
import com.cloud.agent.api.baremetal.PreparePxeServerAnswer;
4443
import com.cloud.agent.api.baremetal.PreparePxeServerCommand;
45-
import com.cloud.agent.api.baremetal.PrepareCreateTemplateCommand;
4644
import com.cloud.baremetal.database.BaremetalPxeDao;
4745
import com.cloud.baremetal.database.BaremetalPxeVO;
4846
import com.cloud.baremetal.networkservice.BaremetalPxeManager.BaremetalPxeType;
@@ -52,6 +50,7 @@
5250
import com.cloud.host.Host;
5351
import com.cloud.host.HostVO;
5452
import com.cloud.host.dao.HostDetailsDao;
53+
import com.cloud.network.Network;
5554
import com.cloud.network.PhysicalNetworkServiceProvider;
5655
import com.cloud.network.dao.PhysicalNetworkDao;
5756
import com.cloud.network.dao.PhysicalNetworkServiceProviderDao;
@@ -95,12 +94,12 @@ public boolean prepare(VirtualMachineProfile profile, NicProfile pxeNic, Network
9594
long pxeServerId = pxeVo.getHostId();
9695

9796
String mac = pxeNic.getMacAddress();
98-
String ip = pxeNic.getIp4Address();
99-
String gateway = pxeNic.getGateway();
100-
String mask = pxeNic.getNetmask();
101-
String dns = pxeNic.getDns1();
97+
String ip = pxeNic.getIPv4Address();
98+
String gateway = pxeNic.getIPv4Gateway();
99+
String mask = pxeNic.getIPv4Netmask();
100+
String dns = pxeNic.getIPv4Dns1();
102101
if (dns == null) {
103-
dns = pxeNic.getDns2();
102+
dns = pxeNic.getIPv4Dns2();
104103
}
105104

106105
try {

plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetaNetworkGuru.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818
// Automatically generated by addcopyright.py at 01/29/2013
1919
package com.cloud.baremetal.networkservice;
2020

21+
import javax.ejb.Local;
22+
import javax.inject.Inject;
23+
24+
import org.apache.cloudstack.api.ApiConstants;
25+
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
26+
import org.apache.log4j.Logger;
27+
2128
import com.cloud.dc.DataCenter;
2229
import com.cloud.dc.Pod;
2330
import com.cloud.dc.PodVlanMapVO;
@@ -50,12 +57,6 @@
5057
import com.cloud.vm.NicProfile;
5158
import com.cloud.vm.ReservationContext;
5259
import com.cloud.vm.VirtualMachineProfile;
53-
import org.apache.cloudstack.api.ApiConstants;
54-
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
55-
import org.apache.log4j.Logger;
56-
57-
import javax.ejb.Local;
58-
import javax.inject.Inject;
5960

6061
@Local(value = {NetworkGuru.class})
6162
public class BaremetaNetworkGuru extends DirectPodBasedNetworkGuru {
@@ -93,7 +94,7 @@ public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, D
9394
return;
9495
}
9596

96-
String oldIp = nic.getIp4Address();
97+
String oldIp = nic.getIPv4Address();
9798
boolean getNewIp = false;
9899
if (oldIp == null) {
99100
getNewIp = true;
@@ -113,7 +114,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
113114
}
114115
});
115116

116-
nic.setIp4Address(null);
117+
nic.setIPv4Address(null);
117118
getNewIp = true;
118119
}
119120
}
@@ -127,8 +128,8 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
127128
}
128129

129130
DataCenter dc = _dcDao.findById(network.getDataCenterId());
130-
nic.setDns1(dc.getDns1());
131-
nic.setDns2(dc.getDns2());
131+
nic.setIPv4Dns1(dc.getDns1());
132+
nic.setIPv4Dns2(dc.getDns2());
132133

133134
/*
134135
* Pod pod = dest.getPod(); Pair<String, Long> ip =
@@ -154,13 +155,13 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
154155
private void getBaremetalIp(NicProfile nic, Pod pod, VirtualMachineProfile vm, Network network, String requiredIp) throws
155156
InsufficientAddressCapacityException, ConcurrentOperationException {
156157
DataCenter dc = _dcDao.findById(pod.getDataCenterId());
157-
if (nic.getIp4Address() == null) {
158-
s_logger.debug(String.format("Requiring ip address: %s", nic.getIp4Address()));
158+
if (nic.getIPv4Address() == null) {
159+
s_logger.debug(String.format("Requiring ip address: %s", nic.getIPv4Address()));
159160
PublicIp ip = _ipAddrMgr.assignPublicIpAddress(dc.getId(), pod.getId(), vm.getOwner(), VlanType.DirectAttached, network.getId(), requiredIp, false);
160-
nic.setIp4Address(ip.getAddress().toString());
161+
nic.setIPv4Address(ip.getAddress().toString());
161162
nic.setFormat(AddressFormat.Ip4);
162-
nic.setGateway(ip.getGateway());
163-
nic.setNetmask(ip.getNetmask());
163+
nic.setIPv4Gateway(ip.getGateway());
164+
nic.setIPv4Netmask(ip.getNetmask());
164165
if (ip.getVlanTag() != null && ip.getVlanTag().equalsIgnoreCase(Vlan.UNTAGGED)) {
165166
nic.setIsolationUri(IsolationType.Ec2.toUri(Vlan.UNTAGGED));
166167
nic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(Vlan.UNTAGGED));
@@ -169,7 +170,7 @@ private void getBaremetalIp(NicProfile nic, Pod pod, VirtualMachineProfile vm, N
169170
nic.setReservationId(String.valueOf(ip.getVlanTag()));
170171
nic.setMacAddress(ip.getMacAddress());
171172
}
172-
nic.setDns1(dc.getDns1());
173-
nic.setDns2(dc.getDns2());
173+
nic.setIPv4Dns1(dc.getDns1());
174+
nic.setIPv4Dns2(dc.getDns2());
174175
}
175176
}

plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpManagerImpl.java

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@
2222
// Automatically generated by addcopyright.py at 04/03/2012
2323
package com.cloud.baremetal.networkservice;
2424

25+
import java.net.URI;
26+
import java.util.ArrayList;
27+
import java.util.HashMap;
28+
import java.util.List;
29+
import java.util.Map;
30+
31+
import javax.ejb.Local;
32+
import javax.inject.Inject;
33+
import javax.naming.ConfigurationException;
34+
35+
import org.apache.cloudstack.api.AddBaremetalDhcpCmd;
36+
import org.apache.cloudstack.api.ListBaremetalDhcpCmd;
37+
import org.apache.log4j.Logger;
38+
2539
import com.cloud.agent.AgentManager;
2640
import com.cloud.agent.api.Answer;
2741
import com.cloud.agent.api.StartupCommand;
@@ -60,18 +74,6 @@
6074
import com.cloud.vm.VirtualMachineProfile;
6175
import com.cloud.vm.dao.NicDao;
6276
import com.cloud.vm.dao.UserVmDao;
63-
import org.apache.cloudstack.api.AddBaremetalDhcpCmd;
64-
import org.apache.cloudstack.api.ListBaremetalDhcpCmd;
65-
import org.apache.log4j.Logger;
66-
67-
import javax.ejb.Local;
68-
import javax.inject.Inject;
69-
import javax.naming.ConfigurationException;
70-
import java.net.URI;
71-
import java.util.ArrayList;
72-
import java.util.HashMap;
73-
import java.util.List;
74-
import java.util.Map;
7577

7678
@Local(value = {BaremetalDhcpManager.class})
7779
public class BaremetalDhcpManagerImpl extends ManagerBase implements BaremetalDhcpManager, ResourceStateAdapter {
@@ -141,22 +143,22 @@ public boolean addVirtualMachineIntoNetwork(Network network, NicProfile nic, Vir
141143
}
142144

143145
HostVO h = hosts.get(0);
144-
String dns = nic.getDns1();
146+
String dns = nic.getIPv4Dns1();
145147
if (dns == null) {
146-
dns = nic.getDns2();
148+
dns = nic.getIPv4Dns2();
147149
}
148150
DhcpEntryCommand dhcpCommand =
149-
new DhcpEntryCommand(nic.getMacAddress(), nic.getIp4Address(), profile.getVirtualMachine().getHostName(), null, dns, nic.getGateway(), null,
151+
new DhcpEntryCommand(nic.getMacAddress(), nic.getIPv4Address(), profile.getVirtualMachine().getHostName(), null, dns, nic.getIPv4Gateway(), null,
150152
_ntwkModel.getExecuteInSeqNtwkElmtCmd());
151153
String errMsg =
152-
String.format("Set dhcp entry on external DHCP %1$s failed(ip=%2$s, mac=%3$s, vmname=%4$s)", h.getPrivateIpAddress(), nic.getIp4Address(),
154+
String.format("Set dhcp entry on external DHCP %1$s failed(ip=%2$s, mac=%3$s, vmname=%4$s)", h.getPrivateIpAddress(), nic.getIPv4Address(),
153155
nic.getMacAddress(), profile.getVirtualMachine().getHostName());
154156
// prepareBareMetalDhcpEntry(nic, dhcpCommand);
155157
try {
156158
Answer ans = _agentMgr.send(h.getId(), dhcpCommand);
157159
if (ans.getResult()) {
158160
s_logger.debug(String.format("Set dhcp entry on external DHCP %1$s successfully(ip=%2$s, mac=%3$s, vmname=%4$s)", h.getPrivateIpAddress(),
159-
nic.getIp4Address(), nic.getMacAddress(), profile.getVirtualMachine().getHostName()));
161+
nic.getIPv4Address(), nic.getMacAddress(), profile.getVirtualMachine().getHostName()));
160162
return true;
161163
} else {
162164
s_logger.debug(errMsg + " " + ans.getDetails());

0 commit comments

Comments
 (0)