Skip to content

Commit bebe79e

Browse files
author
Alex Huang
committed
more work from alex
1 parent e0d962a commit bebe79e

30 files changed

Lines changed: 409 additions & 131 deletions

‎api/src/com/cloud/network/NetworkConfiguration.java‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
* owned by an account.
1313
*/
1414
public interface NetworkConfiguration {
15+
enum State {
16+
Allocated, // Indicates the network configuration is in allocated but not setup.
17+
Setup, // Indicates the network configuration is setup.
18+
InUse; // Indicates the network configuration is in use.
19+
}
1520

1621
/**
1722
* @return id of the network profile. Null means the network profile is not from the database.
@@ -28,7 +33,9 @@ public interface NetworkConfiguration {
2833

2934
String getCidr();
3035

31-
public long getDataCenterId();
36+
long getDataCenterId();
3237

3338
long getNetworkOfferingId();
39+
40+
State getState();
3441
}

‎api/src/com/cloud/network/NetworkProfiler.java‎

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
*
3+
*/
4+
package com.cloud.network.configuration;
5+
6+
import com.cloud.deploy.DeployDestination;
7+
import com.cloud.deploy.DeploymentPlan;
8+
import com.cloud.network.NetworkConfiguration;
9+
import com.cloud.offering.NetworkOffering;
10+
import com.cloud.user.Account;
11+
import com.cloud.utils.component.Adapter;
12+
13+
/**
14+
* NetworkProfiler takes the list of network offerings requested and figures
15+
* out what are the additional network profiles that are needed to add
16+
* to the account in order to support this network.
17+
*
18+
*/
19+
public interface NetworkGuru extends Adapter {
20+
NetworkConfiguration design(NetworkOffering offering, DeploymentPlan plan, NetworkConfiguration config, Account owner);
21+
NetworkConfiguration implement(NetworkConfiguration config, NetworkOffering offering, DeployDestination destination);
22+
23+
24+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
*
3+
*/
4+
package com.cloud.network.element;
5+
6+
import com.cloud.network.NetworkConfiguration;
7+
import com.cloud.offering.NetworkOffering;
8+
import com.cloud.utils.component.Adapter;
9+
import com.cloud.vm.NicProfile;
10+
import com.cloud.vm.VirtualMachineProfile;
11+
12+
/**
13+
* Represents one network element that exists in a network.
14+
*/
15+
public interface NetworkElement extends Adapter {
16+
/**
17+
* Implement the network configuration as specified.
18+
* @param config fully specified network configuration.
19+
* @param offering network offering that originated the network configuration.
20+
* @return true if network configuration is now usable; false if not.
21+
*/
22+
boolean implement(NetworkConfiguration config, NetworkOffering offering);
23+
24+
/**
25+
* Prepare the nic profile to be used within the network.
26+
* @param config
27+
* @param nic
28+
* @param offering
29+
* @return
30+
*/
31+
boolean prepare(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile vm, NetworkOffering offering);
32+
}

‎api/src/com/cloud/resource/Resource.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ enum State {
1919
Releasing,
2020
}
2121

22+
enum ReservationStrategy {
23+
UserSpecified,
24+
Create,
25+
Start
26+
}
27+
2228
/**
2329
* @return id in the CloudStack database
2430
*/
@@ -56,4 +62,6 @@ enum State {
5662
* @return the reservation state of the resource.
5763
*/
5864
State getState();
65+
66+
ReservationStrategy getReservationStrategy();
5967
}

‎api/src/com/cloud/vm/NetworkConcierge.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import com.cloud.exception.InsufficientAddressCapacityException;
88
import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
99
import com.cloud.network.NetworkConfiguration;
10-
import com.cloud.utils.component.Adapter;
10+
import com.cloud.resource.Concierge;
1111

1212
/**
1313
* NetworkConcierge reserves network settings for a VM based
@@ -16,7 +16,7 @@
1616
* the reservation.
1717
*
1818
*/
19-
public interface NetworkConcierge extends Adapter {
19+
public interface NetworkConcierge extends Concierge<Nic> {
2020
String getUniqueName();
2121

2222
NicProfile allocate(VirtualMachine vm, NetworkConfiguration config, NicProfile nic) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException;

‎api/src/com/cloud/vm/State.java‎

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@
1919
package com.cloud.vm;
2020

2121
import java.util.List;
22+
import java.util.Set;
2223

24+
import com.cloud.utils.fsm.FiniteState;
2325
import com.cloud.utils.fsm.StateMachine;
26+
import com.cloud.vm.VirtualMachine.Event;
2427

25-
public enum State {
28+
public enum State implements FiniteState<State, Event> {
2629
Creating(true),
2730
Starting(true),
2831
Running(false),
@@ -44,22 +47,24 @@ public boolean isTransitional() {
4447
return _transitional;
4548
}
4649

47-
public static String[] toStrings(State... states) {
48-
String[] strs = new String[states.length];
49-
for (int i = 0; i < states.length; i++) {
50-
strs[i] = states[i].toString();
51-
}
52-
53-
return strs;
54-
}
55-
50+
@Override
5651
public State getNextState(VirtualMachine.Event e) {
5752
return s_fsm.getNextState(this, e);
5853
}
5954

60-
public State[] getFromStates(VirtualMachine.Event e) {
61-
List<State> from = s_fsm.getFromStates(this, e);
62-
return from.toArray(new State[from.size()]);
55+
@Override
56+
public List<State> getFromStates(VirtualMachine.Event e) {
57+
return s_fsm.getFromStates(this, e);
58+
}
59+
60+
@Override
61+
public Set<Event> getPossibleEvents() {
62+
return s_fsm.getPossibleEvents(this);
63+
}
64+
65+
@Override
66+
public StateMachine<State, Event> getStateMachine() {
67+
return s_fsm;
6368
}
6469

6570
protected static final StateMachine<State, VirtualMachine.Event> s_fsm = new StateMachine<State, VirtualMachine.Event>();

‎api/src/com/cloud/vm/VirtualMachineProfile.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,18 @@ public void setNics(List<NicProfile> profiles) {
6767
this._nics = profiles;
6868
}
6969

70+
public List<NicProfile> getNics() {
71+
return _nics;
72+
}
73+
7074
public void setDisks(List<DiskProfile> profiles) {
7175
this._disks = profiles;
7276
}
7377

78+
public List<DiskProfile> getDisks() {
79+
return _disks;
80+
}
81+
7482
public Hypervisor.Type getHypervisorType() {
7583
return _hypervisorType;
7684
}

‎core/src/com/cloud/vm/VMInstanceVO.java‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@
3636
import javax.persistence.TemporalType;
3737

3838
import com.cloud.utils.db.GenericDao;
39+
import com.cloud.utils.db.StateMachine;
40+
import com.cloud.utils.fsm.FiniteStateObject;
3941

4042
@Entity
4143
@Table(name="vm_instance")
4244
@Inheritance(strategy=InheritanceType.JOINED)
4345
@DiscriminatorColumn(name="type", discriminatorType=DiscriminatorType.STRING, length=32)
44-
public class VMInstanceVO implements VirtualMachine {
46+
public class VMInstanceVO implements VirtualMachine, FiniteStateObject<State, VirtualMachine.Event> {
4547
@Id
4648
@TableGenerator(name="vm_instance_sq", table="sequence", pkColumnName="name", valueColumnName="value", pkColumnValue="vm_instance_seq", allocationSize=1)
4749
@Column(name="id", updatable=false, nullable = false)
@@ -65,7 +67,8 @@ public class VMInstanceVO implements VirtualMachine {
6567
* the state machine needs to go through the DAO object because someone
6668
* else could be updating it as well.
6769
*/
68-
@Enumerated(value=EnumType.STRING)
70+
@Enumerated(value=EnumType.STRING)
71+
@StateMachine(state=State.class, event=Event.class)
6972
@Column(name="state", updatable=true, nullable=false, length=32)
7073
private State state = null;
7174

@@ -249,7 +252,8 @@ public State getState() {
249252
}
250253

251254
// don't use this directly, use VM state machine instead, this method is added for migration tool only
252-
public void setState(State state) {
255+
@Override
256+
public void setState(State state) {
253257
this.state = state;
254258
}
255259

‎server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ protected Map<String, Object> createProxyInstance2(long dataCenterId) {
10201020
List<NetworkOfferingVO> offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemVmControlNetwork, NetworkOfferingVO.SystemVmManagementNetwork, NetworkOfferingVO.SystemVmPublicNetwork);
10211021
List<NetworkConfigurationVO> profiles = new ArrayList<NetworkConfigurationVO>(offerings.size());
10221022
for (NetworkOfferingVO offering : offerings) {
1023-
profiles.add(_networkMgr.setupNetworkProfile(_accountMgr.getSystemAccount(), offering, plan));
1023+
profiles.add(_networkMgr.setupNetworkConfiguration(_accountMgr.getSystemAccount(), offering, plan));
10241024
}
10251025
ConsoleProxyVO proxy = new ConsoleProxyVO(id, name, _template.getId(), _template.getGuestOSId(), dataCenterId, 0);
10261026
proxy = _consoleProxyDao.persist(proxy);

0 commit comments

Comments
 (0)