public static Builder fromDriveInfo(DriveInfo in) { return new Builder() .uuid(in.getUuid()) .name(in.getName()) .resourceUri(in.getResourceUri()) .owner(in.getOwner()) .status(in.getStatus()) .size(in.getSize()) .allowMultimount(in.isAllowMultimount()) .affinities(in.getAffinities()) .jobs(in.getJobs()) .licenses(in.getLicenses()) .media(in.getMedia()) .meta(in.getMeta()) .mountedOn(in.getMountedOn()) .tags(in.getTags()); }
/** * Warning: media, name & size should be specified * * @return DriveInfo instance */ @Override public DriveInfo build() { return new DriveInfo(uuid, name, resourceUri, size, owner, status, allowMultimount, affinities, jobs, licenses, media, meta, mountedOn, tags); }
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof LibraryDrive)) return false; if (!super.equals(o)) return false; LibraryDrive that = (LibraryDrive) o; if (isFavorite != that.isFavorite) return false; if (isPaid != that.isPaid) return false; if (arch != null ? !arch.equals(that.arch) : that.arch != null) return false; if (category != null ? !category.equals(that.category) : that.category != null) return false; if (description != null ? !description.equals(that.description) : that.description != null) return false; if (imageType != null ? !imageType.equals(that.imageType) : that.imageType != null) return false; if (installNotes != null ? !installNotes.equals(that.installNotes) : that.installNotes != null) return false; if (os != null ? !os.equals(that.os) : that.os != null) return false; if (url != null ? !url.equals(that.url) : that.url != null) return false; return true; }
@Override public boolean apply(DriveInfo input) { DriveInfo drive = api.getDriveInfo(input.getUuid()); switch (drive.getStatus()) { case COPYING: case UNAVAILABLE: return false; case MOUNTED: case UNMOUNTED: return true; default: throw new IllegalStateException("Resource is in invalid status: " + drive.getStatus()); } } }
JsonObject driveObject = new JsonObject(); if (input.getName() != null) { driveObject.addProperty("name", input.getName()); if (input.getSize() != null) { driveObject.addProperty("size", "" + input.getSize().toString()); if (input.getMedia() != null) { driveObject.addProperty("media", input.getMedia().toString()); if (input.getAffinities() != null) { driveObject.add("affinities", new JsonParser().parse(new Gson().toJson(input.getAffinities()))); if (input.getMeta() != null) { driveObject.add("meta", new JsonParser().parse(new Gson().toJson(input.getMeta()))); if (input.getTags() != null) { driveObject.add("tags", new JsonParser().parse(new Gson().toJson(input.getTags()))); driveObject.addProperty("allow_multimount", input.isAllowMultimount()); return driveObject;
if (!drive.getMedia().equals(MediaType.CDROM)) { logger.debug(">> cloning library drive %s...", image.getProviderId()); drive = api.getDriveInfo(drive.getUuid()); DriveStatus status = drive.getStatus(); destroyDrives(ImmutableList.of(drive.getUuid())); } catch (Exception ex) { if (destroyDrives) { logger.debug(">> rolling back the cloned drive...", drive.getUuid()); destroyDrives(ImmutableList.of(drive.getUuid())); .cpu((int) hardware.getProcessors().get(0).getSpeed()) .memory(BigInteger.valueOf(hardware.getRam()).multiply(BigInteger.valueOf(1024 * 1024))) .drives(ImmutableList.of(drive.toServerDrive(1, "0:1", options.getDeviceEmulationType()))) .nics(nics) .meta(metadata) if (destroyDrives) { logger.debug(">> rolling back the cloned drive..."); destroyDrives(ImmutableList.of(drive.getUuid()));
FluentIterable<DriveInfo> drives = cloudSigmaApi.listDrivesInfo().concat(); for(DriveInfo d : drives){ if(d.getName().contains(vm.getImageId()) && d.getStatus() == DriveStatus.UNMOUNTED){ driveToClone =d; break; if(d.getName().contains(vm.getImageId())){ driveToClone =d; break; .media(MediaType.DISK) .build(); cloudSigmaApi.cloneLibraryDrive(driveToClone.getUuid(), driveProperties); if(d.getName().equals(a.getName() + "-root") && d.getStatus() == DriveStatus.UNMOUNTED){ cloned = d; break; ServerDrive drive=cloned.toServerDrive(1,"0:1", DeviceEmulationType.VIRTIO); NIC nic=new NIC.Builder() .firewallPolicy(p)
@Override public Volume apply(ServerDrive serverDrive) { VolumeBuilder builder = new VolumeBuilder(); DriveInfo driveInfo = api.getDriveInfo(serverDrive.getDriveUuid()); builder.id(driveInfo.getUuid()); builder.size(driveInfo.getSize().floatValue()); builder.durable(true); builder.type(Volume.Type.NAS); builder.bootDevice(serverDrive.getBootOrder() != null); return builder.build(); } }
@Test(dependsOnMethods = {"testCreateDrive"}) public void testCloneDrive() throws Exception { clonedDrive = api.cloneDrive(createdDrive.getUuid(), null); checkDrive(createdDrive, clonedDrive); }
@Test public void testGetDriveInfo() throws Exception { String uuid = "f17cce62-bcc9-4e0b-a57b-a5582b05aff0"; CloudSigma2Api api = requestSendsResponse( getBuilder() .endpoint(endpoint + "drives/" + uuid + "/") .build(), responseBuilder() .payload(payloadFromResourceWithContentType("/drive-info.json", MediaType.APPLICATION_JSON)) .build()); DriveInfo result = api.getDriveInfo(uuid); assertNotNull(result); assertEquals(result.getName(), "test_drive_1"); assertEquals(result.getJobs().get(0).getResourceUri(), "/api/2.0/jobs/ec01d3bc-1ec0-440d-a1c3-0a6421d0d511/"); assertEquals(result.getJobs().get(0).getUuid(), "ec01d3bc-1ec0-440d-a1c3-0a6421d0d511"); assertEquals(result.getJobs().get(2).getResourceUri(), "/api/2.0/jobs/8bacb5b3-6392-4f74-8094-ba3376a3f5f7/"); assertEquals(result.getJobs().get(2).getUuid(), "8bacb5b3-6392-4f74-8094-ba3376a3f5f7"); }
JsonObject driveObject = new JsonObject(); if (input.getName() != null) { driveObject.addProperty("name", input.getName()); if (input.getSize() != null) { driveObject.addProperty("size", "" + input.getSize().toString()); if (input.getMedia() != null) { driveObject.addProperty("media", input.getMedia().toString()); if (input.getAffinities() != null) { driveObject.add("affinities", new JsonParser().parse(new Gson().toJson(input.getAffinities()))); if (input.getMeta() != null) { driveObject.add("meta", new JsonParser().parse(new Gson().toJson(input.getMeta()))); if (input.getTags() != null) { driveObject.add("tags", new JsonParser().parse(new Gson().toJson(input.getTags()))); driveObject.addProperty("allow_multimount", input.isAllowMultimount()); return driveObject;
if (!drive.getMedia().equals(MediaType.CDROM)) { logger.debug(">> cloning library drive %s...", image.getProviderId()); drive = api.getDriveInfo(drive.getUuid()); DriveStatus status = drive.getStatus(); destroyDrives(ImmutableList.of(drive.getUuid())); } catch (Exception ex) { if (destroyDrives) { logger.debug(">> rolling back the cloned drive...", drive.getUuid()); destroyDrives(ImmutableList.of(drive.getUuid())); .cpu((int) hardware.getProcessors().get(0).getSpeed()) .memory(BigInteger.valueOf(hardware.getRam()).multiply(BigInteger.valueOf(1024 * 1024))) .drives(ImmutableList.of(drive.toServerDrive(1, "0:1", options.getDeviceEmulationType()))) .nics(nics) .meta(metadata) if (destroyDrives) { logger.debug(">> rolling back the cloned drive..."); destroyDrives(ImmutableList.of(drive.getUuid()));
@Override public Volume apply(ServerDrive serverDrive) { VolumeBuilder builder = new VolumeBuilder(); DriveInfo driveInfo = api.getDriveInfo(serverDrive.getDriveUuid()); builder.id(driveInfo.getUuid()); builder.size(driveInfo.getSize().floatValue()); builder.durable(true); builder.type(Volume.Type.NAS); builder.bootDevice(serverDrive.getBootOrder() != null); return builder.build(); } }
@Test(dependsOnMethods = {"testCreateDrives"}) public void testDeleteDrives() throws Exception { ImmutableList.Builder<String> stringListBuilder = ImmutableList.builder(); for (DriveInfo driveInfo : createdDrives) { stringListBuilder.add(driveInfo.getUuid()); } ImmutableList<String> uuids = stringListBuilder.build(); api.deleteDrives(uuids); // Verify all deleted drives no longer exist FluentIterable<Drive> drives = api.listDrives().concat(); assertFalse(any(transform(drives, extractUuid()), in(uuids))); }
@Override public boolean apply(DriveInfo input) { DriveInfo drive = api.getDriveInfo(input.getUuid()); switch (drive.getStatus()) { case COPYING: case UNAVAILABLE: return false; case MOUNTED: case UNMOUNTED: return true; default: throw new IllegalStateException("Resource is in invalid status: " + drive.getStatus()); } } }
public static Builder fromDriveInfo(DriveInfo in) { return new Builder() .uuid(in.getUuid()) .name(in.getName()) .resourceUri(in.getResourceUri()) .owner(in.getOwner()) .status(in.getStatus()) .size(in.getSize()) .allowMultimount(in.isAllowMultimount()) .affinities(in.getAffinities()) .jobs(in.getJobs()) .licenses(in.getLicenses()) .media(in.getMedia()) .meta(in.getMeta()) .mountedOn(in.getMountedOn()) .tags(in.getTags()); }
JsonObject driveObject = new JsonObject(); if (input.getName() != null) { driveObject.addProperty("name", input.getName()); if (input.getSize() != null) { driveObject.addProperty("size", "" + input.getSize().toString()); if (input.getMedia() != null) { driveObject.addProperty("media", input.getMedia().toString()); if (input.getAffinities() != null) { driveObject.add("affinities", new JsonParser().parse(new Gson().toJson(input.getAffinities()))); if (input.getMeta() != null) { driveObject.add("meta", new JsonParser().parse(new Gson().toJson(input.getMeta()))); if (input.getTags() != null) { driveObject.add("tags", new JsonParser().parse(new Gson().toJson(input.getTags()))); driveObject.addProperty("allow_multimount", input.isAllowMultimount()); return driveObject;
@Test(dependsOnMethods = {"testCreateDrive"}) public void testEditDrive() throws Exception { DriveInfo editedDrive = new DriveInfo.Builder() .name("Edited Drive") .size(createdDrive.getSize()) .media(MediaType.DISK) .build(); checkDrive(editedDrive, api.editDrive(createdDrive.getUuid(), editedDrive)); }