@@ -821,6 +821,54 @@ public static AddressFilter notEquals(AddressField field, String value) {
821821 }
822822 }
823823
824+ /**
825+ * Class for filtering snapshot lists.
826+ */
827+ class SnapshotFilter extends ListFilter {
828+
829+ private static final long serialVersionUID = 8757711630092406747L ;
830+
831+ SnapshotFilter (SnapshotField field , ComparisonOperator operator , Object value ) {
832+ super (field .selector (), operator , value );
833+ }
834+
835+ /**
836+ * Returns an equality filter for the given field and string value. For string fields,
837+ * {@code value} is interpreted as a regular expression using RE2 syntax. {@code value} must
838+ * match the entire field.
839+ *
840+ * @see <a href="https://github.com/google/re2/wiki/Syntax">RE2</a>
841+ */
842+ public static SnapshotFilter equals (SnapshotField field , String value ) {
843+ return new SnapshotFilter (checkNotNull (field ), ComparisonOperator .EQ , checkNotNull (value ));
844+ }
845+
846+ /**
847+ * Returns a not-equals filter for the given field and string value. For string fields,
848+ * {@code value} is interpreted as a regular expression using RE2 syntax. {@code value} must
849+ * match the entire field.
850+ *
851+ * @see <a href="https://github.com/google/re2/wiki/Syntax">RE2</a>
852+ */
853+ public static SnapshotFilter notEquals (SnapshotField field , String value ) {
854+ return new SnapshotFilter (checkNotNull (field ), ComparisonOperator .NE , checkNotNull (value ));
855+ }
856+
857+ /**
858+ * Returns an equality filter for the given field and long value.
859+ */
860+ public static SnapshotFilter equals (SnapshotField field , long value ) {
861+ return new SnapshotFilter (checkNotNull (field ), ComparisonOperator .EQ , value );
862+ }
863+
864+ /**
865+ * Returns a not-equals filter for the given field and long value.
866+ */
867+ public static SnapshotFilter notEquals (SnapshotField field , long value ) {
868+ return new SnapshotFilter (checkNotNull (field ), ComparisonOperator .NE , value );
869+ }
870+ }
871+
824872 /**
825873 * Class for specifying disk type get options.
826874 */
@@ -1344,6 +1392,73 @@ public static AddressAggregatedListOption pageToken(String pageToken) {
13441392 }
13451393 }
13461394
1395+ /**
1396+ * Class for specifying snapshot get options.
1397+ */
1398+ class SnapshotOption extends Option {
1399+
1400+ private static final long serialVersionUID = -3505179459035500945L ;
1401+
1402+ private SnapshotOption (ComputeRpc .Option option , Object value ) {
1403+ super (option , value );
1404+ }
1405+
1406+ /**
1407+ * Returns an option to specify the snapshot's fields to be returned by the RPC call. If this
1408+ * option is not provided, all snapshot's fields are returned. {@code SnapshotOption.fields} can
1409+ * be used to specify only the fields of interest. {@link Snapshot#snapshotId()} is always
1410+ * returned, even if not specified.
1411+ */
1412+ public static SnapshotOption fields (SnapshotField ... fields ) {
1413+ return new SnapshotOption (ComputeRpc .Option .FIELDS , SnapshotField .selector (fields ));
1414+ }
1415+ }
1416+
1417+ /**
1418+ * Class for specifying snapshot list options.
1419+ */
1420+ class SnapshotListOption extends Option {
1421+
1422+ private static final long serialVersionUID = 8278588147660831257L ;
1423+
1424+ private SnapshotListOption (ComputeRpc .Option option , Object value ) {
1425+ super (option , value );
1426+ }
1427+
1428+ /**
1429+ * Returns an option to specify a filter on the snapshots being listed.
1430+ */
1431+ public static SnapshotListOption filter (SnapshotFilter filter ) {
1432+ return new SnapshotListOption (ComputeRpc .Option .FILTER , filter .toPb ());
1433+ }
1434+
1435+ /**
1436+ * Returns an option to specify the maximum number of snapshots returned per page.
1437+ */
1438+ public static SnapshotListOption pageSize (long pageSize ) {
1439+ return new SnapshotListOption (ComputeRpc .Option .MAX_RESULTS , pageSize );
1440+ }
1441+
1442+ /**
1443+ * Returns an option to specify the page token from which to start listing snapshots.
1444+ */
1445+ public static SnapshotListOption pageToken (String pageToken ) {
1446+ return new SnapshotListOption (ComputeRpc .Option .PAGE_TOKEN , pageToken );
1447+ }
1448+
1449+ /**
1450+ * Returns an option to specify the snapshot's fields to be returned by the RPC call. If this
1451+ * option is not provided, all snapshot's fields are returned. {@code SnapshotListOption.fields}
1452+ * can be used to specify only the fields of interest. {@link Snapshot#snapshotId()} is always
1453+ * returned, even if not specified.
1454+ */
1455+ public static SnapshotListOption fields (SnapshotField ... fields ) {
1456+ StringBuilder builder = new StringBuilder ();
1457+ builder .append ("items(" ).append (SnapshotField .selector (fields )).append ("),nextPageToken" );
1458+ return new SnapshotListOption (ComputeRpc .Option .FIELDS , builder .toString ());
1459+ }
1460+ }
1461+
13471462 /**
13481463 * Returns the requested disk type or {@code null} if not found.
13491464 *
@@ -1525,4 +1640,53 @@ public static AddressAggregatedListOption pageToken(String pageToken) {
15251640 * @throws ComputeException upon failure
15261641 */
15271642 Operation delete (AddressId addressId , OperationOption ... options );
1643+
1644+ /**
1645+ * Creates a new snapshot.
1646+ *
1647+ * @return a zone operation if the create request was issued correctly, {@code null} if
1648+ * {@code snapshot.sourceDisk} was not found
1649+ * @throws ComputeException upon failure
1650+ */
1651+ Operation create (SnapshotInfo snapshot , OperationOption ... options );
1652+
1653+ /**
1654+ * Returns the requested snapshot or {@code null} if not found.
1655+ *
1656+ * @throws ComputeException upon failure
1657+ */
1658+ Snapshot getSnapshot (String snapshot , SnapshotOption ... options );
1659+
1660+ /**
1661+ * Lists all snapshots.
1662+ *
1663+ * @throws ComputeException upon failure
1664+ */
1665+ Page <Snapshot > listSnapshots (SnapshotListOption ... options );
1666+
1667+ /**
1668+ * Deletes the requested snapshot. Keep in mind that deleting a single snapshot might not
1669+ * necessarily delete all the data for that snapshot. If any data for the snapshot that is marked
1670+ * for deletion is needed for subsequent snapshots, the data will be moved to the next snapshot.
1671+ *
1672+ * @return a global operation if the request was issued correctly, {@code null} if the snapshot
1673+ * was not found
1674+ * @throws ComputeException upon failure
1675+ * @see <a href="https://cloud.google.com/compute/docs/disks/persistent-disks#deleting_snapshot>
1676+ * Deleting a snapshot</a>
1677+ */
1678+ Operation deleteSnapshot (SnapshotId snapshot , OperationOption ... options );
1679+
1680+ /**
1681+ * Deletes the requested snapshot. Keep in mind that deleting a single snapshot might not
1682+ * necessarily delete all the data for that snapshot. If any data on the snapshot that is marked
1683+ * for deletion is needed for subsequent snapshots, the data will be moved to the next snapshot.
1684+ *
1685+ * @return a global operation if the request was issued correctly, {@code null} if the snapshot
1686+ * was not found
1687+ * @throws ComputeException upon failure
1688+ * @see <a href="https://cloud.google.com/compute/docs/disks/persistent-disks#deleting_snapshot>
1689+ * Deleting a snapshot</a>
1690+ */
1691+ Operation deleteSnapshot (String snapshot , OperationOption ... options );
15281692}
0 commit comments