-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[Vmware] Improve listing of Vmware Datacenter VMs for migration to KVM #10770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
b770d27
8cac953
16eab4d
c4a2224
a7cfdb6
ab29fd8
065cd73
4f83ca8
202f9d5
456f3ac
81a9771
76604e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
// 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 org.apache.cloudstack.api.command.admin.zone; | ||
|
||
import com.cloud.exception.ConcurrentOperationException; | ||
import com.cloud.exception.InsufficientCapacityException; | ||
import com.cloud.exception.NetworkRuleConflictException; | ||
import com.cloud.exception.ResourceAllocationException; | ||
import com.cloud.exception.ResourceUnavailableException; | ||
import com.cloud.hypervisor.Hypervisor; | ||
import com.cloud.hypervisor.vmware.VmwareDatacenterService; | ||
import com.cloud.hypervisor.vmware.mo.HostMO; | ||
import com.cloud.user.Account; | ||
|
||
import org.apache.cloudstack.api.APICommand; | ||
import org.apache.cloudstack.api.ApiConstants; | ||
import org.apache.cloudstack.api.ApiErrorCode; | ||
import org.apache.cloudstack.api.BaseListCmd; | ||
import org.apache.cloudstack.api.Parameter; | ||
import org.apache.cloudstack.api.ServerApiException; | ||
import org.apache.cloudstack.api.response.HostResponse; | ||
import org.apache.cloudstack.api.response.ListResponse; | ||
import org.apache.cloudstack.api.response.VmwareDatacenterResponse; | ||
import org.apache.commons.collections.CollectionUtils; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import javax.inject.Inject; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@APICommand(name = "listVmwareDcHosts", responseObject = HostResponse.class, | ||
description = "Lists the Hosts in a Vmware Datacenter", | ||
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) | ||
public class ListVmwareDcHostsCmd extends BaseListCmd implements ListVmwareDcItems { | ||
|
||
@Inject | ||
public VmwareDatacenterService _vmwareDatacenterService; | ||
|
||
@Parameter(name = ApiConstants.EXISTING_VCENTER_ID, | ||
type = CommandType.UUID, | ||
entityType = VmwareDatacenterResponse.class, | ||
description = "UUID of a linked existing vCenter") | ||
private Long existingVcenterId; | ||
|
||
@Parameter(name = ApiConstants.VCENTER, | ||
type = CommandType.STRING, | ||
description = "The name/ip of vCenter. Make sure it is IP address or full qualified domain name for host running vCenter server.") | ||
private String vcenter; | ||
|
||
@Parameter(name = ApiConstants.DATACENTER_NAME, type = CommandType.STRING, description = "Name of Vmware datacenter.") | ||
private String datacenterName; | ||
|
||
@Parameter(name = ApiConstants.USERNAME, type = CommandType.STRING, description = "The Username required to connect to resource.") | ||
private String username; | ||
|
||
@Parameter(name = ApiConstants.PASSWORD, type = CommandType.STRING, description = "The password for specified username.") | ||
private String password; | ||
|
||
public String getVcenter() { | ||
return vcenter; | ||
} | ||
Check warning on line 75 in plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcHostsCmd.java
|
||
|
||
public String getUsername() { | ||
return username; | ||
} | ||
Check warning on line 79 in plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcHostsCmd.java
|
||
|
||
public String getPassword() { | ||
return password; | ||
} | ||
Check warning on line 83 in plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcHostsCmd.java
|
||
|
||
public String getDatacenterName() { | ||
return datacenterName; | ||
} | ||
Check warning on line 87 in plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcHostsCmd.java
|
||
|
||
public Long getExistingVcenterId() { | ||
return existingVcenterId; | ||
} | ||
Check warning on line 91 in plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcHostsCmd.java
|
||
|
||
@Override | ||
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { | ||
checkParameters(); | ||
try { | ||
List<HostMO> hosts = _vmwareDatacenterService.listHostsInDatacenter(this); | ||
ListResponse<HostResponse> response = new ListResponse<>(); | ||
List<HostResponse> baseResponseList = new ArrayList<>(); | ||
Check warning on line 99 in plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcHostsCmd.java
|
||
if (CollectionUtils.isNotEmpty(hosts)) { | ||
for (HostMO vmwareHost : hosts) { | ||
HostResponse resp = createHostResponse(vmwareHost); | ||
baseResponseList.add(resp); | ||
} | ||
} | ||
response.setResponses(baseResponseList, baseResponseList.size()); | ||
response.setResponseName(getCommandName()); | ||
setResponseObject(response); | ||
} catch (Exception e) { | ||
String errorMsg = String.format("Error retrieving VMs from Vmware VC: %s", e.getMessage()); | ||
DaanHoogland marked this conversation as resolved.
Show resolved
Hide resolved
|
||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, errorMsg); | ||
} | ||
} | ||
Check warning on line 113 in plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcHostsCmd.java
|
||
|
||
private HostResponse createHostResponse(HostMO hostInstance) throws Exception { | ||
HostResponse response = new HostResponse(); | ||
response.setHypervisor(Hypervisor.HypervisorType.VMware.toString()); | ||
response.setName(hostInstance.getHostName()); | ||
response.setObjectName("host"); | ||
return response; | ||
} | ||
Check warning on line 121 in plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcHostsCmd.java
|
||
|
||
private void checkParameters() { | ||
Check warning on line 123 in plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcHostsCmd.java
|
||
if ((existingVcenterId == null && vcenter == null) || (existingVcenterId != null && vcenter != null)) { | ||
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, | ||
Check warning on line 125 in plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcHostsCmd.java
|
||
"Please provide an existing vCenter ID or a vCenter IP/Name, parameters are mutually exclusive"); | ||
} | ||
if (existingVcenterId == null && StringUtils.isAnyBlank(vcenter, datacenterName, username, password)) { | ||
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, | ||
Check warning on line 129 in plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcHostsCmd.java
|
||
"Please set all the information for a vCenter IP/Name, datacenter, username and password"); | ||
} | ||
} | ||
Check warning on line 132 in plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcHostsCmd.java
|
||
|
||
@Override | ||
public long getEntityOwnerId() { | ||
return Account.ACCOUNT_ID_SYSTEM; | ||
} | ||
Check warning on line 137 in plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcHostsCmd.java
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// 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 org.apache.cloudstack.api.command.admin.zone; | ||
|
||
public interface ListVmwareDcItems { | ||
String getVcenter(); | ||
|
||
String getDatacenterName(); | ||
|
||
String getUsername(); | ||
|
||
String getPassword(); | ||
|
||
Long getExistingVcenterId(); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.