@@ -292,6 +292,27 @@ public Page<Snapshot> nextPage() {
292292 }
293293 }
294294
295+ private static class ImagePageFetcher implements NextPageFetcher <Image > {
296+
297+ private static final long serialVersionUID = 6403679803137922023L ;
298+ private final Map <ComputeRpc .Option , ?> requestOptions ;
299+ private final ComputeOptions serviceOptions ;
300+ private final String project ;
301+
302+ ImagePageFetcher (String project , ComputeOptions serviceOptions , String cursor ,
303+ Map <ComputeRpc .Option , ?> optionMap ) {
304+ this .requestOptions =
305+ PageImpl .nextRequestOptions (ComputeRpc .Option .PAGE_TOKEN , cursor , optionMap );
306+ this .serviceOptions = serviceOptions ;
307+ this .project = project ;
308+ }
309+
310+ @ Override
311+ public Page <Image > nextPage () {
312+ return listImages (project , serviceOptions , requestOptions );
313+ }
314+ }
315+
295316 private final ComputeRpc computeRpc ;
296317
297318 ComputeImpl (ComputeOptions options ) {
@@ -1026,6 +1047,120 @@ public com.google.api.services.compute.model.Operation call() {
10261047 }
10271048 }
10281049
1050+ @ Override
1051+ public Operation create (ImageInfo image , OperationOption ... options ) {
1052+ final ImageInfo completeImage = image .setProjectId (options ().projectId ());
1053+ final Map <ComputeRpc .Option , ?> optionsMap = optionMap (options );
1054+ try {
1055+ com .google .api .services .compute .model .Operation answer =
1056+ runWithRetries (new Callable <com .google .api .services .compute .model .Operation >() {
1057+ @ Override
1058+ public com .google .api .services .compute .model .Operation call () {
1059+ return computeRpc .createImage (completeImage .toPb (), optionsMap );
1060+ }
1061+ }, options ().retryParams (), EXCEPTION_HANDLER );
1062+ return answer == null ? null : Operation .fromPb (this , answer );
1063+ } catch (RetryHelper .RetryHelperException e ) {
1064+ throw ComputeException .translateAndThrow (e );
1065+ }
1066+ }
1067+
1068+ @ Override
1069+ public Image get (ImageId imageId , ImageOption ... options ) {
1070+ final ImageId completeImageId = imageId .setProjectId (options ().projectId ());
1071+ final Map <ComputeRpc .Option , ?> optionsMap = optionMap (options );
1072+ try {
1073+ com .google .api .services .compute .model .Image answer =
1074+ runWithRetries (new Callable <com .google .api .services .compute .model .Image >() {
1075+ @ Override
1076+ public com .google .api .services .compute .model .Image call () {
1077+ return computeRpc .getImage (completeImageId .project (), completeImageId .image (),
1078+ optionsMap );
1079+ }
1080+ }, options ().retryParams (), EXCEPTION_HANDLER );
1081+ return answer == null ? null : Image .fromPb (this , answer );
1082+ } catch (RetryHelper .RetryHelperException e ) {
1083+ throw ComputeException .translateAndThrow (e );
1084+ }
1085+ }
1086+
1087+ @ Override
1088+ public Page <Image > listImages (String project , ImageListOption ... options ) {
1089+ return listImages (project , options (), optionMap (options ));
1090+ }
1091+
1092+ @ Override
1093+ public Page <Image > listImages (ImageListOption ... options ) {
1094+ return listImages (options ().projectId (), options (), optionMap (options ));
1095+ }
1096+
1097+ private static Page <Image > listImages (final String project , final ComputeOptions serviceOptions ,
1098+ final Map <ComputeRpc .Option , ?> optionsMap ) {
1099+ try {
1100+ ComputeRpc .Tuple <String , Iterable <com .google .api .services .compute .model .Image >> result =
1101+ runWithRetries (new Callable <ComputeRpc .Tuple <String ,
1102+ Iterable <com .google .api .services .compute .model .Image >>>() {
1103+ @ Override
1104+ public ComputeRpc .Tuple <String ,
1105+ Iterable <com .google .api .services .compute .model .Image >> call () {
1106+ return serviceOptions .rpc ().listImages (project , optionsMap );
1107+ }
1108+ }, serviceOptions .retryParams (), EXCEPTION_HANDLER );
1109+ String cursor = result .x ();
1110+ Iterable <Image > images = Iterables .transform (
1111+ result .y () == null ? ImmutableList .<com .google .api .services .compute .model .Image >of ()
1112+ : result .y (),
1113+ new Function <com .google .api .services .compute .model .Image , Image >() {
1114+ @ Override
1115+ public Image apply (com .google .api .services .compute .model .Image image ) {
1116+ return Image .fromPb (serviceOptions .service (), image );
1117+ }
1118+ });
1119+ return new PageImpl <>(new ImagePageFetcher (project , serviceOptions , cursor , optionsMap ),
1120+ cursor , images );
1121+ } catch (RetryHelper .RetryHelperException e ) {
1122+ throw ComputeException .translateAndThrow (e );
1123+ }
1124+ }
1125+
1126+ @ Override
1127+ public Operation delete (ImageId image , OperationOption ... options ) {
1128+ final ImageId completeId = image .setProjectId (options ().projectId ());
1129+ final Map <ComputeRpc .Option , ?> optionsMap = optionMap (options );
1130+ try {
1131+ com .google .api .services .compute .model .Operation answer =
1132+ runWithRetries (new Callable <com .google .api .services .compute .model .Operation >() {
1133+ @ Override
1134+ public com .google .api .services .compute .model .Operation call () {
1135+ return computeRpc .deleteImage (completeId .project (), completeId .image (), optionsMap );
1136+ }
1137+ }, options ().retryParams (), EXCEPTION_HANDLER );
1138+ return answer == null ? null : Operation .fromPb (this , answer );
1139+ } catch (RetryHelper .RetryHelperException e ) {
1140+ throw ComputeException .translateAndThrow (e );
1141+ }
1142+ }
1143+
1144+ @ Override
1145+ public Operation deprecate (ImageId image ,
1146+ final DeprecationStatus <ImageId > deprecationStatus , OperationOption ... options ) {
1147+ final ImageId completeId = image .setProjectId (options ().projectId ());
1148+ final Map <ComputeRpc .Option , ?> optionsMap = optionMap (options );
1149+ try {
1150+ com .google .api .services .compute .model .Operation answer =
1151+ runWithRetries (new Callable <com .google .api .services .compute .model .Operation >() {
1152+ @ Override
1153+ public com .google .api .services .compute .model .Operation call () {
1154+ return computeRpc .deprecateImage (completeId .project (), completeId .image (),
1155+ deprecationStatus .toPb (), optionsMap );
1156+ }
1157+ }, options ().retryParams (), EXCEPTION_HANDLER );
1158+ return answer == null ? null : Operation .fromPb (this , answer );
1159+ } catch (RetryHelper .RetryHelperException e ) {
1160+ throw ComputeException .translateAndThrow (e );
1161+ }
1162+ }
1163+
10291164 private Map <ComputeRpc .Option , ?> optionMap (Option ... options ) {
10301165 Map <ComputeRpc .Option , Object > optionMap = Maps .newEnumMap (ComputeRpc .Option .class );
10311166 for (Option option : options ) {
0 commit comments