forked from AnythingLinux/cloudstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDummyHostServerResource.java
More file actions
190 lines (154 loc) · 5.71 KB
/
DummyHostServerResource.java
File metadata and controls
190 lines (154 loc) · 5.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.resource;
import java.util.HashMap;
import java.util.Map;
import javax.naming.ConfigurationException;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.HostVmStateReportEntry;
import com.cloud.agent.api.PingCommand;
import com.cloud.agent.api.PingRoutingCommand;
import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.api.StartupRoutingCommand;
import com.cloud.host.Host.Type;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.utils.net.MacAddress;
public class DummyHostServerResource extends ServerResourceBase {
private String _name;
private String _zone;
private String _pod;
private String _guid;
private String _url;
private int _instanceId;
private final int _prefix = 0x55;
private static volatile int s_nextSequence = 1;
@Override
protected String getDefaultScriptsDir() {
return "/dummy";
}
@Override
public Answer executeRequest(Command cmd) {
return new Answer(cmd, false, "Unsupported in dummy host server resource");
}
@Override
public PingCommand getCurrentStatus(long id) {
return new PingRoutingCommand(com.cloud.host.Host.Type.Routing, id, new HashMap<String, HostVmStateReportEntry>());
}
@Override
public Type getType() {
return com.cloud.host.Host.Type.Routing;
}
@Override
public StartupCommand[] initialize() {
StartupRoutingCommand cmd = new StartupRoutingCommand();
cmd.setCpus(1);
cmd.setSpeed(1000L);
cmd.setMemory(1000000L);
cmd.setDom0MinMemory(256L);
cmd.setCaps("hvm");
cmd.setGuid(_guid);
cmd.setDataCenter(_zone);
cmd.setPod(_pod);
cmd.setHypervisorType(HypervisorType.None);
cmd.setAgentTag("vmops-simulator");
cmd.setName(_url);
cmd.setPrivateIpAddress(this.getHostPrivateIp());
cmd.setPrivateMacAddress(this.getHostMacAddress().toString());
cmd.setPrivateNetmask("255.255.0.0");
cmd.setIqn("iqn:" + _url);
cmd.setStorageIpAddress(getHostStoragePrivateIp());
cmd.setStorageMacAddress(getHostStorageMacAddress().toString());
cmd.setStorageIpAddressDeux(getHostStoragePrivateIp2());
cmd.setStorageMacAddressDeux(getHostStorageMacAddress2().toString());
cmd.setPublicIpAddress(getHostStoragePrivateIp());
cmd.setPublicMacAddress(getHostStorageMacAddress().toString());
cmd.setPublicNetmask("255.255.0.0");
cmd.setVersion(DummyHostServerResource.class.getPackage().getImplementationVersion());
return new StartupCommand[] {cmd};
}
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = name;
_guid = (String)params.get("guid");
_zone = (String)params.get("zone");
_pod = (String)params.get("pod");
_url = (String)params.get("url");
_instanceId = getNextSequenceId();
return true;
}
public synchronized static int getNextSequenceId() {
return s_nextSequence++;
}
public MacAddress getHostMacAddress() {
long address = 0;
address = (_prefix & 0xff);
address <<= 40;
address |= _instanceId;
return new MacAddress(address);
}
public String getHostPrivateIp() {
int id = _instanceId;
return "172.16." + String.valueOf((id >> 8) & 0xff) + "." + String.valueOf(id & 0xff);
}
public MacAddress getHostStorageMacAddress() {
long address = 0;
address = (_prefix & 0xff);
address <<= 40;
address |= (_instanceId | (1L << 31)) & 0xffffffff;
return new MacAddress(address);
}
public MacAddress getHostStorageMacAddress2() {
long address = 0;
address = (_prefix & 0xff);
address <<= 40;
address |= (_instanceId | (3L << 30)) & 0xffffffff;
return new MacAddress(address);
}
public String getHostStoragePrivateIp() {
int id = _instanceId;
id |= 1 << 15;
return "172.16." + String.valueOf((id >> 8) & 0xff) + "." + String.valueOf(id & 0xff);
}
public String getHostStoragePrivateIp2() {
int id = _instanceId;
id |= 3 << 14;
return "172.16." + String.valueOf((id >> 8) & 0xff) + "." + String.valueOf((id) & 0xff);
}
@Override
public void setName(String name) {
// TODO Auto-generated method stub
}
@Override
public void setConfigParams(Map<String, Object> params) {
// TODO Auto-generated method stub
}
@Override
public Map<String, Object> getConfigParams() {
// TODO Auto-generated method stub
return null;
}
@Override
public int getRunLevel() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void setRunLevel(int level) {
// TODO Auto-generated method stub
}
}