def CreateInstanceWithNewPersistentBootDisk(
      self, instance_name, network, machine_type, image, startup_script='',
      service_accounts=None, metadata=None):
    # Use the instance name as the disk name.
    disk_name = instance_name
    if not self._CreatePersistentBootDisk(disk_name, image):
      return False
    # Wait until the new persistent disk is READY.
    for _ in xrange(self.DEFAULT_OPERATION_WAIT_TIMEOUT):
      logging.info('Waiting for boot disk %s getting ready...', disk_name)
      time.sleep(self.OPERATION_WAIT_INTERVAL)
      disk_status = self.GetDisk(disk_name)
      if disk_status.get('status', None) == 'READY':
        logging.info('Disk %s created successfully.', disk_name)
        break
    else:
      logging.error('Persistent disk %s creation timed out.', disk_name)
      return False

    params = {
        'kind': 'compute#instance',
        'name': instance_name,
        'zone': self.ResourceUrl('zones', self._zone, ResourceZoning.NONE),
        'machineType': machine_type,
        'disks': [
            {
                'boot': True,
                'deviceName': disk_name,
                'kind': 'compute#attachedDisk',
                'mode': 'READ_WRITE',
                'source': self.ResourceUrl('disks', disk_name),
                'type': 'PERSISTENT',
                'zone':
                    self.ResourceUrl('zones', self._zone, ResourceZoning.NONE),
            },
        ],
        'metadata': {
            'kind': 'compute#metadata',
            'items': [
                {
                    'key': 'startup-script',
                    'value': startup_script,
                },
            ],
        },
        'networkInterfaces': [
            {
                'kind': 'compute#instanceNetworkInterface',
                'accessConfigs': [
                    {
                        'kind': 'compute#accessConfig',
                        'type': 'ONE_TO_ONE_NAT',
                        'name': 'External NAT',
                    }
                ],
                'network': network,
            },
        ],
        'serviceAccounts': [
            {
                'kind': 'compute#serviceAccount',
                'email': 'default',
                'scopes': service_accounts or [],
            },
        ],
    }

    # Add metadata.
    if metadata:
      for key, value in metadata.items():
        params['metadata']['items'].append({'key': key, 'value': value})

    operation = self.GetApi().instances().insert(
        project=self._project, zone=self._zone,
        body=params).execute()

    return self._ParseOperation(
        operation, 'Instance creation: %s' % instance_name)
In-sample prediction and out-of-sample forecasting
dataset/ETHPy150Open GoogleCloudPlatform/Data-Pipeline/app/src/hadoop/gce_api.py/GceApi.CreateInstanceWithNewPersistentBootDisk--crossover with--dataset/ETHPy150Open statsmodels/statsmodels/statsmodels/tsa/statespace/mlemodel.py/MLEResults.get_prediction