1<?php
2/*
3 * Copyright 2014 Google Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6 * use this file except in compliance with the License. You may obtain a copy of
7 * the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 */
17
18namespace Google\Service\SQLAdmin\Resource;
19
20use Google\Service\SQLAdmin\DatabaseInstance;
21use Google\Service\SQLAdmin\InstancesCloneRequest;
22use Google\Service\SQLAdmin\InstancesDemoteMasterRequest;
23use Google\Service\SQLAdmin\InstancesExportRequest;
24use Google\Service\SQLAdmin\InstancesFailoverRequest;
25use Google\Service\SQLAdmin\InstancesImportRequest;
26use Google\Service\SQLAdmin\InstancesListResponse;
27use Google\Service\SQLAdmin\InstancesListServerCasResponse;
28use Google\Service\SQLAdmin\InstancesRestoreBackupRequest;
29use Google\Service\SQLAdmin\InstancesRotateServerCaRequest;
30use Google\Service\SQLAdmin\InstancesTruncateLogRequest;
31use Google\Service\SQLAdmin\Operation;
32
33/**
34 * The "instances" collection of methods.
35 * Typical usage is:
36 *  <code>
37 *   $sqladminService = new Google\Service\SQLAdmin(...);
38 *   $instances = $sqladminService->instances;
39 *  </code>
40 */
41class Instances extends \Google\Service\Resource
42{
43  /**
44   * Adds a new trusted Certificate Authority (CA) version for the specified
45   * instance. Required to prepare for a certificate rotation. If a CA version was
46   * previously added but never used in a certificate rotation, this operation
47   * replaces that version. There cannot be more than one CA version waiting to be
48   * rotated in. (instances.addServerCa)
49   *
50   * @param string $project Project ID of the project that contains the instance.
51   * @param string $instance Cloud SQL instance ID. This does not include the
52   * project ID.
53   * @param array $optParams Optional parameters.
54   * @return Operation
55   */
56  public function addServerCa($project, $instance, $optParams = [])
57  {
58    $params = ['project' => $project, 'instance' => $instance];
59    $params = array_merge($params, $optParams);
60    return $this->call('addServerCa', [$params], Operation::class);
61  }
62  /**
63   * Creates a Cloud SQL instance as a clone of the source instance. Using this
64   * operation might cause your instance to restart. (instances.cloneInstances)
65   *
66   * @param string $project Project ID of the source as well as the clone Cloud
67   * SQL instance.
68   * @param string $instance The ID of the Cloud SQL instance to be cloned
69   * (source). This does not include the project ID.
70   * @param InstancesCloneRequest $postBody
71   * @param array $optParams Optional parameters.
72   * @return Operation
73   */
74  public function cloneInstances($project, $instance, InstancesCloneRequest $postBody, $optParams = [])
75  {
76    $params = ['project' => $project, 'instance' => $instance, 'postBody' => $postBody];
77    $params = array_merge($params, $optParams);
78    return $this->call('clone', [$params], Operation::class);
79  }
80  /**
81   * Deletes a Cloud SQL instance. (instances.delete)
82   *
83   * @param string $project Project ID of the project that contains the instance
84   * to be deleted.
85   * @param string $instance Cloud SQL instance ID. This does not include the
86   * project ID.
87   * @param array $optParams Optional parameters.
88   * @return Operation
89   */
90  public function delete($project, $instance, $optParams = [])
91  {
92    $params = ['project' => $project, 'instance' => $instance];
93    $params = array_merge($params, $optParams);
94    return $this->call('delete', [$params], Operation::class);
95  }
96  /**
97   * Demotes the stand-alone instance to be a Cloud SQL read replica for an
98   * external database server. (instances.demoteMaster)
99   *
100   * @param string $project ID of the project that contains the instance.
101   * @param string $instance Cloud SQL instance name.
102   * @param InstancesDemoteMasterRequest $postBody
103   * @param array $optParams Optional parameters.
104   * @return Operation
105   */
106  public function demoteMaster($project, $instance, InstancesDemoteMasterRequest $postBody, $optParams = [])
107  {
108    $params = ['project' => $project, 'instance' => $instance, 'postBody' => $postBody];
109    $params = array_merge($params, $optParams);
110    return $this->call('demoteMaster', [$params], Operation::class);
111  }
112  /**
113   * Exports data from a Cloud SQL instance to a Cloud Storage bucket as a SQL
114   * dump or CSV file. (instances.export)
115   *
116   * @param string $project Project ID of the project that contains the instance
117   * to be exported.
118   * @param string $instance Cloud SQL instance ID. This does not include the
119   * project ID.
120   * @param InstancesExportRequest $postBody
121   * @param array $optParams Optional parameters.
122   * @return Operation
123   */
124  public function export($project, $instance, InstancesExportRequest $postBody, $optParams = [])
125  {
126    $params = ['project' => $project, 'instance' => $instance, 'postBody' => $postBody];
127    $params = array_merge($params, $optParams);
128    return $this->call('export', [$params], Operation::class);
129  }
130  /**
131   * Initiates a manual failover of a high availability (HA) primary instance to a
132   * standby instance, which becomes the primary instance. Users are then rerouted
133   * to the new primary. For more information, see the [Overview of high
134   * availability](https://cloud.google.com/sql/docs/mysql/high-availability) page
135   * in the Cloud SQL documentation. If using Legacy HA (MySQL only), this causes
136   * the instance to failover to its failover replica instance.
137   * (instances.failover)
138   *
139   * @param string $project ID of the project that contains the read replica.
140   * @param string $instance Cloud SQL instance ID. This does not include the
141   * project ID.
142   * @param InstancesFailoverRequest $postBody
143   * @param array $optParams Optional parameters.
144   * @return Operation
145   */
146  public function failover($project, $instance, InstancesFailoverRequest $postBody, $optParams = [])
147  {
148    $params = ['project' => $project, 'instance' => $instance, 'postBody' => $postBody];
149    $params = array_merge($params, $optParams);
150    return $this->call('failover', [$params], Operation::class);
151  }
152  /**
153   * Retrieves a resource containing information about a Cloud SQL instance.
154   * (instances.get)
155   *
156   * @param string $project Project ID of the project that contains the instance.
157   * @param string $instance Database instance ID. This does not include the
158   * project ID.
159   * @param array $optParams Optional parameters.
160   * @return DatabaseInstance
161   */
162  public function get($project, $instance, $optParams = [])
163  {
164    $params = ['project' => $project, 'instance' => $instance];
165    $params = array_merge($params, $optParams);
166    return $this->call('get', [$params], DatabaseInstance::class);
167  }
168  /**
169   * Imports data into a Cloud SQL instance from a SQL dump or CSV file in Cloud
170   * Storage. (instances.import)
171   *
172   * @param string $project Project ID of the project that contains the instance.
173   * @param string $instance Cloud SQL instance ID. This does not include the
174   * project ID.
175   * @param InstancesImportRequest $postBody
176   * @param array $optParams Optional parameters.
177   * @return Operation
178   */
179  public function import($project, $instance, InstancesImportRequest $postBody, $optParams = [])
180  {
181    $params = ['project' => $project, 'instance' => $instance, 'postBody' => $postBody];
182    $params = array_merge($params, $optParams);
183    return $this->call('import', [$params], Operation::class);
184  }
185  /**
186   * Creates a new Cloud SQL instance. (instances.insert)
187   *
188   * @param string $project Project ID of the project to which the newly created
189   * Cloud SQL instances should belong.
190   * @param DatabaseInstance $postBody
191   * @param array $optParams Optional parameters.
192   * @return Operation
193   */
194  public function insert($project, DatabaseInstance $postBody, $optParams = [])
195  {
196    $params = ['project' => $project, 'postBody' => $postBody];
197    $params = array_merge($params, $optParams);
198    return $this->call('insert', [$params], Operation::class);
199  }
200  /**
201   * Lists instances under a given project. (instances.listInstances)
202   *
203   * @param string $project Project ID of the project for which to list Cloud SQL
204   * instances.
205   * @param array $optParams Optional parameters.
206   *
207   * @opt_param string filter A filter expression that filters resources listed in
208   * the response. The expression is in the form of field:value. For example,
209   * 'instanceType:CLOUD_SQL_INSTANCE'. Fields can be nested as needed as per
210   * their JSON representation, such as 'settings.userLabels.auto_start:true'.
211   * Multiple filter queries are space-separated. For example. 'state:RUNNABLE
212   * instanceType:CLOUD_SQL_INSTANCE'. By default, each expression is an AND
213   * expression. However, you can include AND and OR expressions explicitly.
214   * @opt_param string maxResults The maximum number of results to return per
215   * response.
216   * @opt_param string pageToken A previously-returned page token representing
217   * part of the larger set of results to view.
218   * @return InstancesListResponse
219   */
220  public function listInstances($project, $optParams = [])
221  {
222    $params = ['project' => $project];
223    $params = array_merge($params, $optParams);
224    return $this->call('list', [$params], InstancesListResponse::class);
225  }
226  /**
227   * Lists all of the trusted Certificate Authorities (CAs) for the specified
228   * instance. There can be up to three CAs listed: the CA that was used to sign
229   * the certificate that is currently in use, a CA that has been added but not
230   * yet used to sign a certificate, and a CA used to sign a certificate that has
231   * previously rotated out. (instances.listServerCas)
232   *
233   * @param string $project Project ID of the project that contains the instance.
234   * @param string $instance Cloud SQL instance ID. This does not include the
235   * project ID.
236   * @param array $optParams Optional parameters.
237   * @return InstancesListServerCasResponse
238   */
239  public function listServerCas($project, $instance, $optParams = [])
240  {
241    $params = ['project' => $project, 'instance' => $instance];
242    $params = array_merge($params, $optParams);
243    return $this->call('listServerCas', [$params], InstancesListServerCasResponse::class);
244  }
245  /**
246   * Updates settings of a Cloud SQL instance. This method supports patch
247   * semantics. (instances.patch)
248   *
249   * @param string $project Project ID of the project that contains the instance.
250   * @param string $instance Cloud SQL instance ID. This does not include the
251   * project ID.
252   * @param DatabaseInstance $postBody
253   * @param array $optParams Optional parameters.
254   * @return Operation
255   */
256  public function patch($project, $instance, DatabaseInstance $postBody, $optParams = [])
257  {
258    $params = ['project' => $project, 'instance' => $instance, 'postBody' => $postBody];
259    $params = array_merge($params, $optParams);
260    return $this->call('patch', [$params], Operation::class);
261  }
262  /**
263   * Promotes the read replica instance to be a stand-alone Cloud SQL instance.
264   * Using this operation might cause your instance to restart.
265   * (instances.promoteReplica)
266   *
267   * @param string $project ID of the project that contains the read replica.
268   * @param string $instance Cloud SQL read replica instance name.
269   * @param array $optParams Optional parameters.
270   * @return Operation
271   */
272  public function promoteReplica($project, $instance, $optParams = [])
273  {
274    $params = ['project' => $project, 'instance' => $instance];
275    $params = array_merge($params, $optParams);
276    return $this->call('promoteReplica', [$params], Operation::class);
277  }
278  /**
279   * Deletes all client certificates and generates a new server SSL certificate
280   * for the instance. (instances.resetSslConfig)
281   *
282   * @param string $project Project ID of the project that contains the instance.
283   * @param string $instance Cloud SQL instance ID. This does not include the
284   * project ID.
285   * @param array $optParams Optional parameters.
286   * @return Operation
287   */
288  public function resetSslConfig($project, $instance, $optParams = [])
289  {
290    $params = ['project' => $project, 'instance' => $instance];
291    $params = array_merge($params, $optParams);
292    return $this->call('resetSslConfig', [$params], Operation::class);
293  }
294  /**
295   * Restarts a Cloud SQL instance. (instances.restart)
296   *
297   * @param string $project Project ID of the project that contains the instance
298   * to be restarted.
299   * @param string $instance Cloud SQL instance ID. This does not include the
300   * project ID.
301   * @param array $optParams Optional parameters.
302   * @return Operation
303   */
304  public function restart($project, $instance, $optParams = [])
305  {
306    $params = ['project' => $project, 'instance' => $instance];
307    $params = array_merge($params, $optParams);
308    return $this->call('restart', [$params], Operation::class);
309  }
310  /**
311   * Restores a backup of a Cloud SQL instance. Using this operation might cause
312   * your instance to restart. (instances.restoreBackup)
313   *
314   * @param string $project Project ID of the project that contains the instance.
315   * @param string $instance Cloud SQL instance ID. This does not include the
316   * project ID.
317   * @param InstancesRestoreBackupRequest $postBody
318   * @param array $optParams Optional parameters.
319   * @return Operation
320   */
321  public function restoreBackup($project, $instance, InstancesRestoreBackupRequest $postBody, $optParams = [])
322  {
323    $params = ['project' => $project, 'instance' => $instance, 'postBody' => $postBody];
324    $params = array_merge($params, $optParams);
325    return $this->call('restoreBackup', [$params], Operation::class);
326  }
327  /**
328   * Rotates the server certificate to one signed by the Certificate Authority
329   * (CA) version previously added with the addServerCA method.
330   * (instances.rotateServerCa)
331   *
332   * @param string $project Project ID of the project that contains the instance.
333   * @param string $instance Cloud SQL instance ID. This does not include the
334   * project ID.
335   * @param InstancesRotateServerCaRequest $postBody
336   * @param array $optParams Optional parameters.
337   * @return Operation
338   */
339  public function rotateServerCa($project, $instance, InstancesRotateServerCaRequest $postBody, $optParams = [])
340  {
341    $params = ['project' => $project, 'instance' => $instance, 'postBody' => $postBody];
342    $params = array_merge($params, $optParams);
343    return $this->call('rotateServerCa', [$params], Operation::class);
344  }
345  /**
346   * Starts the replication in the read replica instance. (instances.startReplica)
347   *
348   * @param string $project ID of the project that contains the read replica.
349   * @param string $instance Cloud SQL read replica instance name.
350   * @param array $optParams Optional parameters.
351   * @return Operation
352   */
353  public function startReplica($project, $instance, $optParams = [])
354  {
355    $params = ['project' => $project, 'instance' => $instance];
356    $params = array_merge($params, $optParams);
357    return $this->call('startReplica', [$params], Operation::class);
358  }
359  /**
360   * Stops the replication in the read replica instance. (instances.stopReplica)
361   *
362   * @param string $project ID of the project that contains the read replica.
363   * @param string $instance Cloud SQL read replica instance name.
364   * @param array $optParams Optional parameters.
365   * @return Operation
366   */
367  public function stopReplica($project, $instance, $optParams = [])
368  {
369    $params = ['project' => $project, 'instance' => $instance];
370    $params = array_merge($params, $optParams);
371    return $this->call('stopReplica', [$params], Operation::class);
372  }
373  /**
374   * Truncate MySQL general and slow query log tables MySQL only.
375   * (instances.truncateLog)
376   *
377   * @param string $project Project ID of the Cloud SQL project.
378   * @param string $instance Cloud SQL instance ID. This does not include the
379   * project ID.
380   * @param InstancesTruncateLogRequest $postBody
381   * @param array $optParams Optional parameters.
382   * @return Operation
383   */
384  public function truncateLog($project, $instance, InstancesTruncateLogRequest $postBody, $optParams = [])
385  {
386    $params = ['project' => $project, 'instance' => $instance, 'postBody' => $postBody];
387    $params = array_merge($params, $optParams);
388    return $this->call('truncateLog', [$params], Operation::class);
389  }
390  /**
391   * Updates settings of a Cloud SQL instance. Using this operation might cause
392   * your instance to restart. (instances.update)
393   *
394   * @param string $project Project ID of the project that contains the instance.
395   * @param string $instance Cloud SQL instance ID. This does not include the
396   * project ID.
397   * @param DatabaseInstance $postBody
398   * @param array $optParams Optional parameters.
399   * @return Operation
400   */
401  public function update($project, $instance, DatabaseInstance $postBody, $optParams = [])
402  {
403    $params = ['project' => $project, 'instance' => $instance, 'postBody' => $postBody];
404    $params = array_merge($params, $optParams);
405    return $this->call('update', [$params], Operation::class);
406  }
407}
408
409// Adding a class alias for backwards compatibility with the previous class name.
410class_alias(Instances::class, 'Google_Service_SQLAdmin_Resource_Instances');
411