Skip to content

Instantly share code, notes, and snippets.

appengine_config.py
def webapp_add_wsgi_middleware(app):
from google.appengine.ext.appstats import recording
app = recording.appstats_wsgi_middleware(app)
return app
appstats_SHELL_OK = True
app.yaml
[..]
@feczo
feczo / unmounted.py
Last active August 29, 2015 14:02
unmounted disks on compute engine GCE using gcutil
#!/usr/bin/env python
import os
os.system("gcutil listinstances --filter='status eq RUNNING' --columns=disks --format=csv 2>&1 | grep '/' >/tmp/gcutil.mounted;"
"gcutil listdisks --columns=name --format=names >/tmp/gcutil.disks")
disks = set(open("/tmp/gcutil.disks").read().split())
mounted = set(open("/tmp/gcutil.mounted").read().split())
uniques = disks.difference(mounted).union(mounted.difference(disks))
@feczo
feczo / clone-win-gce.md
Last active August 29, 2015 14:02
How to clone a windows compute engine (GCE) instance from command line using gcutil
  1. gcutil addinstance --image=windows-server-2008-r2-dc-v20140609 --zone=europe-west1-windows --machine_type=n1-standard-1 source-windows

  2. Provide a password for the gceadmin account of your Windows instance(s):

  3. wait about 10-15 minutes

  4. confirm that the instance is completely up: gcutil getserialportoutput source-windows output should end with: ```

@feczo
feczo / large-gce-win-disk.md
Last active August 29, 2015 14:02
Create a large disk for Windows instances on Google Compute Engine - GCE
  1. Take a snapshot of your existing instance. Go to console.developers.google.com/project/[Project Number]/compute/snapshots and click "New snapshot" Name your snapshot (e.g. windows-snapshot) and select the disk of your Windows instance under "SOURCE DISK" Click "Create" to create the instance.
  2. Create a bigger disk and apply the snapshot e.g. gcutil --service_version="v1" --project="modelity-wp" adddisk "mybigwindows" --zone="us-central2-windows" --source_snapshot="windows-snapshot" --disk_type="pd-standard" --size_gb="1300"
  3. Create a new instance and attach the bigger disk e.g. gcutil --service_version="v1" --project="modelity-wp" addinstance "mybigwindows" --zone="us-central2-windows" --machine_type="n1-standard-1" --network="default" --external_ip_address="ephemeral" --disk="mybigwindows,deviceName=mybigwindows,mode=READ_WRITE,boot"
@feczo
feczo / api-clone-gce-instance.md
Last active August 29, 2015 14:02
Clone a GCE instance directly through the API

Section A = cloning the disk

  1. go to the cloud console https://console.developers.google.com
  2. go to snapshots and click on 'New snapshot'
  3. select your source disk
  4. Take note of the Name field and click 'Create'
  5. go to disks click on 'New disk'
  6. flip Source Type to Snapshot
  7. make sure you define the zone matching where the instance is going to be hosted
  8. select source snapshot created at step 4
@feczo
feczo / service-account-dev-prod.py
Created July 3, 2014 13:26
Example of using a service account in both production and development with a .pem key converted from devconsole
import webapp2
from apiclient.discovery import build
from apiclient.errors import HttpError
import httplib2
from oauth2client.client import SignedJwtAssertionCredentials
# Enter your Google Developer Project number
PROJECT_NUMBER = "XXXXXXXXXX"
@feczo
feczo / gcutil_delete.md
Last active August 29, 2015 14:04
Delete ALL your compute engine instances from the default project

delete EVERY instance

gcutil --format=names listinstances | while read inst; do gcutil deleteinstance $inst -f --delete_boot_pd&; done;

Only Unused ones

gcutil listinstances --filter="status ne RUNNING" --format=names | while read inst; do gcutil deleteinstance $inst -f --delete_boot_pd&; done;

apt-get -y update
apt-get -y install nginx; 
echo "<center><h2>Welcome to $HOSTNAME</h2></center>" | sudo tee /usr/share/nginx/www/index.html;
service nginx start

eg.:

--- move_cmds.py 2014-08-06 17:41:47.000000000 +1000
+++ /Users/sub/cloud/platform/gcutil/lib/google_compute_engine/gcutil_lib/move_cmds.py 2014-08-06 18:21:24.000000000 +1000
@@ -291,7 +291,7 @@
self._VerifyOperations(self.MakeListResult(results, 'operationList'))
- def _DeleteInstances(self, instances, zone):
+ def _DeleteInstances(self, instances, zone, raisefatal=True):
"""Deletes the given instances.
@feczo
feczo / migrate-gce-disks.md
Last active August 29, 2015 14:05
Migrate disk between zones
SRC_ZONE="us-central1-a"
DST_ZONE="asia-east1-a"
DISK_NAME="disk1"
SNAP_NAME="snap1"
gcloud compute disks snapshot $DISK_NAME --snapshot-names $SNAP_NAME --zone $SRC_ZONE &&
gcloud compute disks delete $DISK_NAME --zone $SRC_ZONE --quiet &&
gcloud compute disks create $DISK_NAME --zone $DST_ZONE --source-snapshot $SNAP_NAME &&

gcloud compute snapshots delete $SNAP_NAME --quiet