Custom Search

Tuesday, July 23, 2013

Howto boto vm-import-export@amazon.com WRITE READ_ACL permission S3 bucket

Error
=====
Client.AuthFailure: vm-import-export@amazon.com must have WRITE and READ_ACL permission on the S3 bucket

Solution
=======
import boto
from pprint import pprint

conn = boto.connect_s3(aws_access_key_id="xxxxxxxx", aws_secret_access_key="xxxxxxxxx")

b = conn.get_bucket("my-bucket")

b.add_email_grant("READ_ACP", "vm-import-export@amazon.com")
b.add_email_grant("WRITE", "vm-import-export@amazon.com")

grants = b.list_grants()

for gr in grants:
    print "=====gr======", pprint(vars(gr))

Monday, July 15, 2013

How to Connect RDP to Imported EC2 Windows Instance

How to Connect Remote Desktop to Imported EC2 Windows Instance

1)
Prepare a Windows VM to import to Amazon EC2

http://fosshelp.blogspot.in/2013/07/prepare-windows-vm-import-amazon-ec2.html

2)
Download Vitual Machine from ESXi node in ovf format

#ovftool vi://root:welcome@192.168.12.154/windows_2003_server_32 windows_2003_server_32.ovf
3)
Create EC2 Instance using *.vmdk

#ec2-import-instance windows_2003_server_32-disk1.vmdk -f VMDK -t m1.small -a x86_64 -b import-export -o $AWS_ACCESS_KEY -w $AWS_SECRET_KEY --region us-west-1

4)
Check the Progress of the task

#ec2-describe-conversion-tasks import-i-ffm2nty0 -O $AWS_ACCESS_KEY -W $AWS_SECRET_KEY --region us-west-1

5)
Start Imported EC2 Instance


6)
Edit Security Group

* Add RDP Group Permission to "default" Security Group.
* Add ICMP Group Permission to "default" Security Group (Optional, For test Ping).

7)
Connect RDP to VM

#rdesktop ip-of-imported-ec2-instance

How to Prepare a Windows VM to import to Amazon EC2

1)
Create a VM and Install Windows 2003 Server
(I used Windows Server 2003 R2 Standard x32).

2)
Start Windows 2003 Server VM and Enable Remote Desktop.

Goto MyComputer --> Properties --> Remote --> (Select Check Box) Enable Remote Desktop on this computer.
3)
Find the IP of windows machine using the command "ipconfig" and check locally whether Remote Desktop (RDP) working or not, before importing the VM to EC2.
#rdesktop ip-of-windows-machine

4)
Shut-down the VM


5)
Import to Amazon EC2


6)
Security Group Settings
* Add RDP Group Permission to Security Group.
* Add ICMP Group Permission to Security Group (Optional, For test Ping).

7)
Connect to VM

#rdesktop ip-of-imported-ec2-instance

How to fix could not load the gnu linux shared library tvwine.dll.so

Install the following package.
#sudo apt-get install libxtst6:i386 wine

Thursday, July 11, 2013

How to Create a new Amazon EC2 AMI from VMware VM or VMDK file

1)
Download vmdk file from ESXi Server
#ovftool vi://root:welcome@192.168.12.154/sm_win3_test2 sm_win3_test2.ovf

2)
Export

export AWS_ACCESS_KEY=XXXXXXXXXXXXXXXX
export AWS_SECRET_KEY=XXXXXXXXXXXXXXXX
export AMS_USER_ID=4471-9218-2508


3)
Convert VMDK file to RAW

#qemu-img convert -O raw sm_win3_test2-disk1.vmdk  output.raw
4)
Bundle this RAW into an AMI using ec2-bundle-image

#ec2-bundle-image -i output.raw -r x86_64 -c cert-XXXXXXXXXXXXXXXX.pem -k pk-XXXXXXXXXXXXXXXX.pem --user $AMS_USER_ID

5)
#ls /tmp
#vim /tmp/output.raw.manifest.xml


6)
Upload the bundle to an S3 bucket.

#ec2-upload-bundle -b import_export -m /tmp/output.raw.manifest.xml -a $AWS_ACCESS_KEY -s $AWS_SECRET_KEY

7)
#ec2-describe-images

8)
Register the image

#ec2-register import_export/output.raw.manifest.xml

9)
The AMI should then appear when you request a list of your images.

#ec2-describe-images

Notes
====

1)
How to Upload the bundle to an S3 bucket in the us-west-1 region.
#ec2-upload-bundle -b import-export-us-west-1 -m /tmp/output.raw.manifest.xml -a $AWS_ACCESS_KEY -s $AWS_SECRET_KEY --location us-west-1


2)
How to Register the image in us-west-1 region.
#ec2-register import_export/output.raw.manifest.xml --region us-west-1


3)
How to describe images in the us-west-1 region.
#ec2-describe-images --region us-west-1

Wednesday, July 10, 2013

How to Install Amazon EC2 VM Import Connector Plugin for VMware vCenter

1)
Download the Amazon EC2 VM Import Connector for VMware vCenter OVA "Amazon-EC2-VM-Import-Connector.ova".
http://aws.amazon.com/developertools
http://aws.amazon.com/developertools/2759763385083070
https://s3.amazonaws.com/ec2-vm-import-connector-appliance/Amazon-EC2-VM-Import-Connector-1.2.0.ova

2)
Deploy the OVF Template and create a VM



3)
Power On the VM

4)
Open the Browser and goto the IP showing In the VM's Console and login.

5)
Register vCenter

6)
Open vSphere Client and Login to vCenter. Then Select a VM and in right side you can see a new Tab

How to use Remote Desktop rdesktop to connect from Ubuntu to Windows

1) First Enable RDP in your windows Machine

2) Then from Ubuntu machine run following command
#rdesktop Ip-of-your-windows-macine
#rdesktop 192.168.1.22



Friday, July 5, 2013

How to create my first migration script using south

How to created my first migration script using south

1)
Create Migration script for create tables for models
#python manage.py schemamigration myapp --initial

2)
Execute Migration Script
#python manage.py migrate myapp

3)
Check status
#python manage.py migrate --list

4)
Create a new Migration script "000x_add_content_type.py" for add entry to contenttype for new model
#python manage.py datamigration app_settings add_content_type --freeze=contenttypes --freeze=auth

5)
Edit the Migration script "000x_add_content_type.py" and override forward() method.
I added following line method forward()
ct, created = orm['contenttypes.ContentType'].objects.get_or_create(model='ielabexcludeyear', app_label='app_settings')

6)
Execute Migration Script
#python manage.py migrate myapp

7)
Add Permissions for new app and models
The command "add_group_permissions" is not the part of "south" tool
The command "add_group_permissions" is created using django' custom-management-commands feature.
https://docs.djangoproject.com/en/dev/howto/custom-management-commands/
#python manage.py add_group_permissions

8)
http://fosshelp.blogspot.in/2013/07/how-to-use-django-south.html

Thursday, July 4, 2013

How to use django south

Install south
==========

http://south.readthedocs.org/en/latest/installation.html#using-easy-install

1)
Install south
---------------
#easy_install South

2)
Setting
----------
a) Add "south" to "settings.INSTALLED_APPS" and comment out all other apps
b) Then run "python manage.py syncdb"
c) Then uncomment all apps in the "settings.INSTALLED_APPS"
d) Then run "python manage.py runserver 8009" for testing

3)
Checking
----------
* Run "python manage.py --help" and you can see following commands provided by the "south" app.
[south]
    convert_to_south
    datamigration
    graphmigrations
    migrate
    migrationcheck
    schemamigration
    startmigration
    syncdb
    test
    testserver

4)
Note
---------------
http://south.readthedocs.org/en/latest/migrationstructure.html
When South loads migrations, it loads all the python files inside your app’s migrations/ directory in ASCII sort order (e.g. 1 is before 10 is before 2), and expects to find a class called Migration inside each one, with at least a forwards() and backwards() method.
When South wants to apply a migration, it simply calls the forwards() method, and similarly when it wants to roll back a migration it calls backwards()

Schema Migrations
===============

http://south.readthedocs.org/en/latest/tutorial/part1.html

1)
First step: Create a migrations directory inside our app.
---------------
* Run the command
#python manage.py schemamigration myapp --initial

*This command will create a migrations directory for us, and made a new migration inside it.

2)
How to apply/run our new migration script created by the command "python manage.py schemamigration myapp --initial"
How to create the tables
-----------------------------------
* Run the commmand
#python manage.py migrate myapp

* This command will create new tables for our models in the app "myapp"
* So we create a table witout using the command "python manage.py syncdb" <====

3)
How to update the tables
-------------------------
a) First change the moel definition (Eg: add a new column)
b) Create a new migration script using the option "--auto"
#python manage.py schemamigration myapp ----auto
c) Apply/Run the migration script created by the previous command
#python manage.py migrate myapp

4)
How to check the applied and not applied migration scripts
------------------------------------------------------------
#python manage.py migrate --list
* The output has an asterisk (*) next to a migration name if it has been applied, and an empty space ( ) if not

Data migrations
===============

* http://south.readthedocs.org/en/latest/tutorial/part3.html
* Data migrations are used to change the data stored in your database to match a new schema, or feature.

1)
Create an empty data migration script file
------------------------------------------
# python manage.py datamigration myapp my_script_file

2)
Open the data migration script file
-----------------------------------
#vim my_script_file.py
* In that file we can see models definitions, the forwards() and backwards() functions.
* Override the method "forwards()"

3)
Apply/Run the migration script
-------------------------------
#python manage.py migrate myapp

django how to fix Exception Value: 'int' object has no attribute '__getitem__'

django how to fix Exception Value: 'int' object has no attribute '__getitem__'

Solution
======
your model's __unicode__ method should return a unicode string

Django How to make entries into ContentType for new app

Django How to make entries into ContentType for new app
 

How to fix following errors
---------------------------

a) 
DoesNotExist: ContentType matching query does not exist. Lookup parameters were {'model': 'years', 'app_label': 'setting'}

b)

DoesNotExist: Permission matching query does not exist. Lookup parameters were {'codename': 'add_years', 'content_type': }

Solution
======

1)
Goto "settings.py" and keep only following lines in "INSTALLED_APPS".
INSTALLED_APPS = ['django.contrib.auth',
'django.contrib.contenttypes',
'iekb.mynewapp']

2)
Run syncdb
#python manage.py syncdb