本文整理汇总了Java中org.openstack4j.model.common.ActionResponse类的典型用法代码示例。如果您正苦于以下问题:Java ActionResponse类的具体用法?Java ActionResponse怎么用?Java ActionResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ActionResponse类属于org.openstack4j.model.common包,在下文中一共展示了ActionResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doRequest
import org.openstack4j.model.common.ActionResponse; //导入依赖的package包/类
@Override
public Void doRequest(OSClient api) throws NotFoundException, ResponseException {
// look for victim server in all regions
ServerService serverApi = api.compute().servers();
Server victimServer = serverApi.get(this.victimId);
if (victimServer == null) {
throw new NotFoundException(format("delete failed: server with id '%s' could not be found in region %s",
this.victimId, getApiAccessConfig().getRegion()));
}
releaseFloatingIps(api, victimServer);
ActionResponse response = serverApi.delete(this.victimId);
if (!response.isSuccess()) {
throw new ResponseException(
String.format("delete failed: server %s: %s", this.victimId, response.getFault()),
response.getCode());
}
awaitTermination(victimServer.getId());
return null;
}
示例2: build
import org.openstack4j.model.common.ActionResponse; //导入依赖的package包/类
@Override
public List<CloudResource> build(OpenStackContext context, long privateId, AuthenticatedContext auth, Group group, Image image,
List<CloudResource> buildableResource, Map<String, String> tags) throws Exception {
CloudResource resource = buildableResource.get(0);
try {
String publicNetId = context.getStringParameter(OpenStackConstants.PUBLIC_NET_ID);
if (publicNetId != null) {
OSClient osClient = createOSClient(auth);
List<CloudResource> computeResources = context.getComputeResources(privateId);
CloudResource instance = getInstance(computeResources);
FloatingIP unusedIp = osClient.compute().floatingIps().allocateIP(publicNetId);
ActionResponse response = osClient.compute().floatingIps().addFloatingIP(instance.getParameter(OpenStackConstants.SERVER, Server.class),
unusedIp.getFloatingIpAddress());
if (!response.isSuccess()) {
throw new OpenStackResourceException("Add floating-ip to server failed", resourceType(), resource.getName(),
auth.getCloudContext().getId(), response.getFault());
}
return Collections.singletonList(createPersistedResource(resource, group.getName(), unusedIp.getId()));
}
return Collections.emptyList();
} catch (OS4JException ex) {
throw new OpenStackResourceException("Add floating-ip to server failed", resourceType(), resource.getName(), ex);
}
}
示例3: delete
import org.openstack4j.model.common.ActionResponse; //导入依赖的package包/类
@Override
public CloudResource delete(OpenStackContext context, AuthenticatedContext auth, CloudResource resource, Network network) throws Exception {
try {
OSClient osClient = createOSClient(auth);
NeutronNetworkView networkView = new NeutronNetworkView(network);
if (!networkView.isExistingSubnet()) {
String subnetId = context.getStringParameter(OpenStackConstants.SUBNET_ID);
osClient.networking().router().detachInterface(resource.getReference(), subnetId, null);
}
if (!networkView.isExistingNetwork()) {
ActionResponse response = osClient.networking().router().delete(resource.getReference());
return checkDeleteResponse(response, resourceType(), auth, resource, "Router deletion failed");
}
return null;
} catch (OS4JException ex) {
throw new OpenStackResourceException("Router deletion failed", resourceType(), resource.getName(), ex);
}
}
示例4: deletePortById
import org.openstack4j.model.common.ActionResponse; //导入依赖的package包/类
/**
* Deletes the port given an Id. Returns true if the port is successfully deleted. Does not throw any error
* if the port does not exist.
*
* @param region region
* @param portId non-null port id
* @return true if successfully deleted
*/
public boolean deletePortById(String region, String portId) {
boolean success = true;
getOs().useRegion(region);
Port port = getOs().networking().port().get(portId);
if (port != null) {
ActionResponse delete = getOs().networking().port().delete(portId);
success = delete.isSuccess();
} else {
log.warn(String.format("No port: %s found in region: %s", portId, region));
}
return success;
}
示例5: deleteSecurityGroupById
import org.openstack4j.model.common.ActionResponse; //导入依赖的package包/类
public boolean deleteSecurityGroupById(String region, String sgRefId) throws IllegalStateException {
getOs().useRegion(region);
ActionResponse actionResponse = getOs().networking().securitygroup().delete(sgRefId);
if (!actionResponse.isSuccess()) {
String message = String.format("Deleting Security group: %s in region: %s failed. Error: %s", sgRefId,
region, actionResponse.getFault());
log.warn(message);
throw new IllegalStateException(message);
}
return actionResponse.isSuccess();
}
示例6: deleteFloatingIp
import org.openstack4j.model.common.ActionResponse; //导入依赖的package包/类
public synchronized void deleteFloatingIp(String region, String floatingIpId) {
getOs().useRegion(region);
log.info("Deleting Floating ip with id: " + floatingIpId);
ActionResponse actionResponse = getOs().networking().floatingip().delete(floatingIpId);
if (!actionResponse.isSuccess()) {
String message = String.format("Deleting floating ip with id: %s in region: %s failed with message: %s",
floatingIpId, region, actionResponse.getFault());
log.warn(message);
if (actionResponse.getCode() != Response.Status.NOT_FOUND.getStatusCode()) {
throw new ResponseException(message, actionResponse.getCode());
}
}
}
示例7: uploadImage
import org.openstack4j.model.common.ActionResponse; //导入依赖的package包/类
public String uploadImage(String region, String imageName, File imageFile, Map<String, String> imageProperties)
throws IOException, VmidcBrokerValidationException {
log.info("Uploading Image " + imageName + " to region " + region);
getOs().useRegion(region);
String fileExtension = FilenameUtils.getExtension(imageFile.getName());
ImageBuilder imageBuilder = Builders.imageV2()
.name(imageName)
.containerFormat(ContainerFormat.BARE)
.visibility(Image.ImageVisibility.PRIVATE)
.diskFormat(getDiskFormat(fileExtension));
if (imageProperties != null) {
imageProperties.forEach(imageBuilder::additionalProperty);
}
Image createdImage = getOs().imagesV2().create(imageBuilder.build());
String imageId = createdImage.getId();
Payload<File> payload = Payloads.create(imageFile);
ActionResponse actionResponse = getOs().imagesV2().upload(imageId, payload, createdImage);
if (actionResponse.isSuccess()) {
log.info("Image uploaded with Id: " + imageId);
} else {
String message = String.format("Failed to upload image: %s to region: %s. error: %s", imageName, region,
actionResponse.getFault());
log.warn(message);
throw new ResponseException(message, actionResponse.getCode());
}
return imageId;
}
示例8: deleteImageById
import org.openstack4j.model.common.ActionResponse; //导入依赖的package包/类
public boolean deleteImageById(String region, String id) {
getOs().useRegion(region);
ActionResponse actionResponse = getOs().imagesV2().delete(id);
if (!actionResponse.isSuccess()) {
String message = String.format("Image Id: %s in region: %s cannot be removed. Error: %s", id, region,
actionResponse.getFault());
log.warn(message);
throw new ResponseException(message, actionResponse.getCode());
}
return actionResponse.isSuccess();
}
示例9: deleteFlavorById
import org.openstack4j.model.common.ActionResponse; //导入依赖的package包/类
public void deleteFlavorById(String region, String id) {
getOs().useRegion(region);
ActionResponse actionResponse = getOs().compute().flavors().delete(id);
if (!actionResponse.isSuccess()) {
String message = String.format("Deleting flavor Id: %s failed. Error: %s", id, actionResponse.getFault());
log.warn(message);
throw new ResponseException(message, actionResponse.getCode());
}
}
示例10: doDelete
import org.openstack4j.model.common.ActionResponse; //导入依赖的package包/类
@Override
protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ObjectStorageService objectStorage = authenticateAndGetObjectStorageService();
System.out.println("Deleting file from ObjectStorage...");
String containerName = request.getParameter("container");
String fileName = request.getParameter("file");
if(containerName == null || fileName == null){ //No file was specified to be found, or container name is missing
response.sendError(HttpServletResponse.SC_NOT_FOUND);
System.out.println("File not found.");
return;
}
ActionResponse deleteResponse = objectStorage.objects().delete(containerName,fileName);
if(!deleteResponse.isSuccess()){
response.sendError(deleteResponse.getCode());
System.out.println("Delete failed: " + deleteResponse.getFault());
return;
}
else{
response.setStatus(HttpServletResponse.SC_OK);
}
System.out.println("Successfully deleted file from ObjectStorage!");
}
开发者ID:ibm-bluemix-mobile-services,项目名称:bluemix-objectstorage-sample-liberty,代码行数:30,代码来源:SimpleServlet.java
示例11: detachVolume
import org.openstack4j.model.common.ActionResponse; //导入依赖的package包/类
public static void detachVolume(String serverId, String volumeId) throws Exception {
BlockVolumeService volService=Osp4jSession.getOspSession().blockStorage().volumes();
volumeId=CommonAPI.takeFromMemory(CinderKey.VOLUME_ID, volumeId);
serverId=CommonAPI.takeFromMemory(NovaKey.NOVA_SERVERID, serverId);
ServerService serverService = Osp4jSession.getOspSession().compute().servers();
Volume volume = volService.get(volumeId);
if (volume != null) {
// Detach volume from server
final ActionResponse response = serverService.detachVolume(serverId, volumeId);
waitUntilVolumeStatus(volService, volume.getId(), Volume.Status.AVAILABLE);
}
}
示例12: uploadSshPublicKey
import org.openstack4j.model.common.ActionResponse; //导入依赖的package包/类
public boolean uploadSshPublicKey(String keyPairName, Nova nova, boolean removeOld) {
if (removeOld) {
ActionResponse res = this.novaContext.getCompute().keypairs().delete(keyPairName);
if (!res.isSuccess())
logger.info(String.format("Could not remove key maube it does not exist '%s'", keyPairName));
}
logger.info(String.format("New keypair '%s' is being uploaded to Nova OpenStack", keyPairName));
this.novaContext.getCompute().keypairs().create(keyPairName, sshKeyPair.getPublicKey());
return true;
}
示例13: main
import org.openstack4j.model.common.ActionResponse; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
HttpLoggingFilter.toggleLogging(false);
CloudApiSettings driverConfig = DriverConfigLoader.loadDefault();
OSClient client = new OSClientFactory(driverConfig).authenticatedClient();
KeypairService keyApi = client.compute().keypairs();
ActionResponse response = keyApi.delete(keyPairName);
LOG.info("deleted keypair {}: {}", keyPairName, response);
}
示例14: executeAction
import org.openstack4j.model.common.ActionResponse; //导入依赖的package包/类
private List<CloudVmInstanceStatus> executeAction(AuthenticatedContext ac, List<CloudInstance> cloudInstances, Action action) {
List<CloudVmInstanceStatus> statuses = new ArrayList<>();
OSClient osClient = openStackClient.createOSClient(ac);
for (CloudInstance cloudInstance : cloudInstances) {
ActionResponse actionResponse = osClient.compute().servers().action(cloudInstance.getInstanceId(), action);
if (actionResponse.isSuccess()) {
statuses.add(new CloudVmInstanceStatus(cloudInstance, InstanceStatus.IN_PROGRESS));
} else {
statuses.add(new CloudVmInstanceStatus(cloudInstance, InstanceStatus.FAILED, actionResponse.getFault()));
}
}
return statuses;
}
示例15: delete
import org.openstack4j.model.common.ActionResponse; //导入依赖的package包/类
@Override
public CloudResource delete(OpenStackContext context, AuthenticatedContext auth, CloudResource resource) throws Exception {
try {
OSClient osClient = createOSClient(auth);
ActionResponse response = osClient.compute().servers().delete(resource.getReference());
return checkDeleteResponse(response, resourceType(), auth, resource, "Instance deletion failed");
} catch (OS4JException ex) {
throw new OpenStackResourceException("Instance deletion failed", resourceType(), resource.getName(), ex);
}
}