euca2ools usage

目錄

 


euca2ools homepage:

http://www.eucalyptus.com/

Doc:

http://www.eucalyptus.com/docs

V3 doc:

http://www.eucalyptus.com/docs/euca2ools/3.0/euca2ools-guide/

Source:

https://github.com/eucalyptus/euca2ools

 


安裝 (distribution pacakge)

不介意用舊版本的話:

yum install euca2ools

apt-get install euca2ools

新版宮方安裝 (官方只有 Centos repos)

yum install http://downloads.eucalyptus.com/software/euca2ools/3.0/centos/6/i386/epe...

yum install http://downloads.eucalyptus.com/software/euca2ools/3.0/centos/6/i386/euc...

yum install euca2ools

安裝後獲得一堆 binary file:

euca-*

package dependencies:

  • m2crypto
  • python-boto

Check version

server:~# euca-version

euca2ools 3.0.1 (Sparta)

 


 

每 Version 支援的 Eucalyptus

euca2ools           Eucalyptus
3.0.x                  3.3
2.1.1~2.1.3        3.2
2.1.0                  3.1


 

Install from source

http://downloads.eucalyptus.com/software/euca2ools/

python setup.py install

事先準備:

  • python versions 2.6 and 2.7
  • six
  • setuptools
  • requests
  • requestbuilder
  • lxml

pip install six setuptools requests requestbuilder lxml

下載:

http://downloads.eucalyptus.com/software/euca2ools/3.0/source/euca2ools-3.0.1.tar.gz

問題1:

src/lxml/lxml.etree.c:16:20: fatal error: Python.h: No such file or directory

apt-get install python-dev

安裝位置:

/usr/local/bin

# development packages of libxml2 and libxslt

  • libxml2-dev
  • libxslt1-dev

 


 

基本設定

 

Env. Var.

  • EC2_URL
  • EC2_ACCESS_KEY
  • EC2_SECRET_KEY
  • EUCA_REGION
  • S3_URL

Config File:

version3:

1.  /etc/euca2ools/euca2ools.ini
2.  /etc/euca2ools/conf.d/*.ini
3.  ~/.euca/*.ini

Example:

[user ExampleUser]
key-id = ??????????
secret-key = ???????????????????????????

[global]
default-region = aws:ap-southeast-1

[region aws:ap-southeast-1]
; AWS (Singapore)
user = ExampleUser
ec2-url = https://ec2.ap-southeast-1.amazonaws.com/
s3-url = https://s3-ap-southeast-1.amazonaws.com/

; 非必要
autoscaling-url = https://autoscaling.ap-southeast-1.amazonaws.com/
elasticloadbalancing-url = https://elasticloadbalancing.ap-southeast-1.amazonaws.com/
monitoring-url = https://monitoring.ap-southeast-1.amazonaws.com/

 

version2.0:

~/.eucarc

EC2_URL=https://ec2.amazonaws.com/
EC2_ACCESS_KEY=????????????????
EC2_SECRET_KEY=?????????????????????????????????
EUCA_REGION=ap-southeast-1

# 如果沒 env varible, 那指令內必須加入以下 args

  • -I ACCESS_KEY_ID
  • -S SECRET_KEY
  • -U URL
  •  

P.S.

有用的 Options --debug

 


 

regions and zones

 

regions

euca-describe-regions

REGION  eu-west-1       ec2.eu-west-1.amazonaws.com
REGION  sa-east-1       ec2.sa-east-1.amazonaws.com
REGION  us-east-1       ec2.us-east-1.amazonaws.com
REGION  ap-northeast-1  ec2.ap-northeast-1.amazonaws.com
REGION  us-west-2       ec2.us-west-2.amazonaws.com
REGION  us-west-1       ec2.us-west-1.amazonaws.com
REGION  ap-southeast-1  ec2.ap-southeast-1.amazonaws.com
REGION  ap-southeast-2  ec2.ap-southeast-2.amazonaws.com

zones

euca-describe-availability-zones [--region]

AVAILABILITYZONE        ap-southeast-1a available
AVAILABILITYZONE        ap-southeast-1b available

 


 

EIP address

 

euca-describe-addresses

# ADDRESS 86.75.30.9  available
# ADDRESS 86.75.30.10 i-E7AC420A
# ADDRESS 86.75.30.11 nobody  standard

#  Acquires an Elastic IP address for your account.

euca-allocate-address

# Releases an Elastic IP address allocated to your account.

euca-release-address 86.75.30.9

----------------------

# Associates an Elastic IP address with an instance or a network interface.

euca-associate-address  -i  i-3C66428A  86.75.30.9

# Disassociate

euca-disassociate-address ip

 

By default, all AWS accounts are limited to 5 EIPs

  • small hourly charge when they are not associated with a running instance, or when they are associated with a stopped instance
  • Additional EIPs ssociated with that instance are only available in Amazon VPC
     

20130918

  • $0.005 per additional Elastic IP address associated with a running instance per hour on a pro rata basis
  • $0.005 per Elastic IP address not associated with a running instance per hour on a pro rata basis (month: us$3.6)
  • $0.00 per Elastic IP address remap for the first 100 remaps per month
  • $0.10 per Elastic IP address remap for additional remaps over 100 per month

 


 

Group

建立:

# -d,--description
euca-create-group mytestgroup -d "This is a test"

output:

GROUP   sg-0c698863     542828552986    labgroup        for testing usage       vpc-0528836d
PERMISSION      542828552986    labgroup        ALLOWS  tcp     22      22      FROM    CIDR    123.202.???.??/32       ingress
PERMISSION      542828552986    labgroup        ALLOWS  -1                      TO      CIDR    0.0.0.0/0       egress

查看 Group:

euca-describe-group [group_name]

output

GROUP   sg-0c698863     542828552986    labgroup        for testing usage       vpc-0528836d
PERMISSION      542828552986    labgroup        ALLOWS  -1                      TO      CIDR     0.0.0.0/0       egress
  • Output type identifier ("GROUP")
  • Account ID of the security group owner
  • Security group name
  • Security group description
  • Output type identifier ("PERMISSION")
  • Account ID of the security group owner
  • Group name that is granting permission
  • Rule type (only ALLOWS is supported)
  • Protocol
  • Port range start
  • Port range end
  • Source

刪除:

euca-delete-group group_name

output:

RETURN  true

 


 

authorize (firewall)

 

建立 allow rule:

# euca-authorize  group_name  [-P {tcp,udp} -p port_range] [-s cidr_range]

euca-authorize default -p 80

euca-authorize default -P tcp -p 80 -s 0.0.0.0/0

euca-authorize labgroup -P tcp -p 6697-7000 -s 1.2.3.0/24

 

刪除 rule:

euca-revoke default -P tcp -p 80 -s 0.0.0.0/0

 


 

image

euca-describe-images [--filter "name=value"]
# name: Name of the EMI name

running:

IMAGE   ami-2c206b7e    609491361539/20130830a  609491361539    available       private i386    machine aki-f81354aa                    ebs     paravirtual     xen
BLOCKDEVICEMAPPING      /dev/sda        snap-d20385e7   8       false
BLOCKDEVICEMAPPING      /dev/sdb

 

# Default: response includes information for only certain images
# -a, --all

euca-describe-images -a --filter architecture=i386  --filter image-type=machine --filter root-device-type=ebs --filter

description=\*Debian\*

  • manifest-location
  • owner-alias=aws-marketplace
IMAGE   ami-26a4eb74    379101102735/debian-wheezy-i386-20130505        379101102735    available       public  i386    machine aki-f81354aa                    ebs     paravirtual     xen
BLOCKDEVICEMAPPING      /dev/sda1       snap-e97460db   8       true
IMAGE   ami-7a773e28    379101102735/debian-wheezy-i386-20130705        379101102735    available       public  i386    machine aki-f81354aa                    ebs     paravirtual     xen
BLOCKDEVICEMAPPING      /dev/sda1       snap-99b971ac   8       true
IMAGE   ami-7e4b052c    aws-marketplace/debian-wheezy-i386-20130507-e4554303-3a9d-412e-9604-eae67dde7b76-ami-e17c1088.1 aws-marketplace available       public  i386    machine aki-f81354aa                    ebs     paravirtual     xen
BLOCKDEVICEMAPPING      /dev/sda1       snap-7550bf40   8       true
IMAGE   ami-9aaae7c8    aws-marketplace/debian-squeeze-i386-20130224-e4554303-3a9d-412e-9604-eae67dde7b76-ami-2ae17343.1        aws-marketplace available       public  i386    machine aki-f81354aa                    ebs     paravirtualxen
BLOCKDEVICEMAPPING      /dev/sda1       snap-48efde7b   8       true
IMAGE   ami-b02d54e2    944964708905/rightimage_debian_6.0.1_i386_20110405.1_ebs        944964708905    available       public  i386    machine aki-6fd5aa3d                    ebs     paravirtual     xen
BLOCKDEVICEMAPPING      /dev/sda        snap-2b37e940   8       true
IMAGE   ami-ec9ed3be    379101102735/debian-squeeze-i386-20130224       379101102735    available       public  i386    machine aki-f81354aa                    ebs     paravirtual     xen

 

Output:

  • Output type identifier ("IMAGE")
  • Image ID
  • Manifest path
  • Account ID that registered the image
  • Image status (available, pending, failed)
  • Image visibility (public or private)
  • Product codes, if any, attached to the instance
  • Image architecture (i386 or x86_64)
  • Image type (machine, kernel, or ramdisk)
  • Kernel ID of the kernel (machine images only)
  • RAM ID associated with the image (machine images only)
  • Root device type (ebs or instance-store)
  • Virtualization type (paravirtual or hvm)
  • Output type identifier ("BLOCKDEVICEMAPPING") for EMIs that use one or more EBS volumes
  • Any tags assigned to the image
  • Hypervisor type (xen or kvm)

 

IMAGE   ami-42f5bb10    aws-marketplace/CentOS-6.4-i386-GA-EBS-45fb1c34-bfe7-4940-a246-c1d8864a9d18-ami-2f9af146.1aws-marketplace  available       public  i386    machine aki-f81354aa                    ebs     paravirtual     xen
IMAGE   ami-46f5bb14    aws-marketplace/CentOS-6.4-x86_64-GA-EBS-9ededd96-9ff7-4ba1-ae15-2c99f7e93990-ami-d79bf0be.1       aws-marketplace available       public  x86_64  machine aki-fe1354ac                    ebs     paravirtualxen

 

ebs or instance-store

EBS-backed AMI (created from an Amazon EBS snapshot)
( State: Stopped )

S3-backed AMI (volumes persists only during the life of the instance)
(running or terminated)
(Boot Time: Usually less than 5 minutes)

 

euca-describe-image-attribute

  • -l, --launch-permission
  • -B, --block-device-mapping

euca-modify-image-attribute -l -a all emi-15A1386E
# -l, --launch-permission
# -a, --add entity

# image file is uploade

euca-bundle-image --arch i386 -i test.img

euca-reset-image-attribute -l emi-15A1386E

# register

#  the registered image by default is set to private

euca-register -a i386 --description  'My new image'  --name 'myimage'

euca-deregister image_id

 


 

keypair

建立:

# euca-create-keypair keypair_name [ -f filename ]
euca-create-keypair mykey

output:

KEYPAIR firstkey        32:61:3e:57:37:00:b7:95:3f:c0:2a:5d:73:85:86:36:ba:57:7c:2f
-----BEGIN RSA PRIVATE KEY-----
..........................................

-----END RSA PRIVATE KEY-----

查看:

euca-describe-keypairs

output:

KEYPAIR firstkey        32:61:3e:57:37:00:b7:95:3f:c0:2a:5d:73:85:86:36:ba:57:7c:2f

 

euca-delete-keypair keypair_name

euca-import-keypair -f file KEYPAIR

# encoded version of the password, which you then need to decrypt using the private key.
euca-get-password-data instance_id

 


 

instance

 

euca-describe-instance-types    <--(amazon 沒有)

# INSTANCETYPE Name         CPUs  Memory (MB)  Disk (GB)
# INSTANCETYPE m1.small        1          256          5

 

# m1.medium instance type so that it has 16 GB of disk space

euca-modify-instance-type m1.medium --disk 16 <--(amazon 沒有)

 

查看:

euca-describe-instances [--region ecc]

RESERVATION     r-d4500983      542828552986
INSTANCE        i-cb59169d      ami-26a4eb74                    terminated      firstkey        0               m1.small        2013-09-18T03:45:22.000Z    ap-southeast-1a  aki-f81354aa                    monitoring-disabled                                     ebs                                     paravirtual xen                      default false

Output:

running:

RESERVATION     r-9a9b73cc      542828552986
INSTANCE        i-5b6ce80d      ami-42f5bb10    ec2-54-251-186-111.ap-southeast-1.compute.amazonaws.com ip-172-31-16-136.ap-southeast-1.compute.internal        running     labkey  0       455dlx2t2m0noxeymztl0uc60       t1.micro        2013-09-18T09:24:41.000Z        ap-southeast-1b aki-f81354aa                    monitoring-disabled 54.251.186.111  172.31.16.136   vpc-0528836d    subnet-0728836f ebs                                     paravirtual     xen     7140a30b-b255-4b42-97a3-1630ac20b1d3        sg-116d8c7e     default false
BLOCKDEVICE     /dev/sda        vol-56fc0b01    2013-09-18T08:29:29.000Z        false
BLOCKDEVICE     /dev/sdf        vol-f7fb0ca0    2013-09-18T09:04:55.000Z        false
NIC     eni-2bec4643    subnet-0728836f vpc-0528836d    542828552986    in-use  172.31.16.136   ip-172-31-16-136.ap-southeast-1.compute.internal        true
NICATTACHMENT           0       attached        2013-09-18T08:29:26.000Z        true
NICASSOCIATION  54.251.186.111  amazon  {'privateDnsName': 'ip-172-31-16-136.ap-southeast-1.compute.internal', 'association': {'publicIp': '54.251.186.111', 'publicDnsName': 'ec2-54-251-186-111.ap-southeast-1.compute.amazonaws.com', 'ipOwnerId': 'amazon'}, 'primary': 'true', 'privateIpAddress': '172.31.16.136'}
GROUP   sg-116d8c7e     CentOS 6-4 -i386- - Release Media-6-4 - 2013-03-09-AutogenByAWSMP-
PRIVATEIPADDRESS        172.31.16.136

stopped

RESERVATION     r-9a9b73cc      542828552986
INSTANCE        i-5b6ce80d      ami-42f5bb10            ip-172-31-16-136.ap-southeast-1.compute.internal        stopped labkey  0       455dlx2t2m0noxeymztl0uc60  t1.micro 2013-09-18T09:24:41.000Z        ap-southeast-1b aki-f81354aa                    monitoring-disabled             172.31.16.136   vpc-0528836d    subnet-0728836f     ebs                                     paravirtual     xen     7140a30b-b255-4b42-97a3-1630ac20b1d3    sg-116d8c7e     default false
BLOCKDEVICE     /dev/sda        vol-56fc0b01    2013-09-18T08:29:29.000Z        false
BLOCKDEVICE     /dev/sdf        vol-f7fb0ca0    2013-09-18T09:04:55.000Z        false
NIC     eni-2bec4643    subnet-0728836f vpc-0528836d    542828552986    in-use  172.31.16.136   ip-172-31-16-136.ap-southeast-1.compute.internal        true
NICATTACHMENT           0       attached        2013-09-18T08:29:26.000Z        true
GROUP   sg-116d8c7e     CentOS 6-4 -i386- - Release Media-6-4 - 2013-03-09-AutogenByAWSMP-
PRIVATEIPADDRESS        172.31.16.136

 

  • Output type identifier ("RESERVATION")
  • Reservation ID
  • Account ID
  • Security group name
  • Output type identifier ("INST ANCE")
  • Instance ID
  • EMI ID that the instance is based on
  • Instance state
  • Product codes attached to the instance
  • Instance type
  • Instance launch time
  • Availability Zone
  • Kernel ID
  • RAM disk ID
  • Public IP address
  • Private IP address
  • Type of root device (ebs or instance-store)
  • Placement group the cluster instance is in
  • Output type identifier ("BLOCKDEVICE") for each EBS v olume the instance is using
  • Block device name
  • Volume ID
  • Timestamp

P.S.

You can't apply a keypair to a running instance. You can only use the new keypair to launch a new instance.

After you launch an instance in EC2-Classic, you can't change its security groups.

 

# run

# -t       instance_type
# -g      Security group to run the instance in

euca-run-instances  -t t1.micro -k firstkey -g labgroup ami-26a4eb74

output:

RESERVATION     r-52d08d05      542828552986
INSTANCE        i-915832c7      ami-26a4eb74            ip-172-31-14-116.ap-southeast-1.compute.internal        pending    firstkey        0               t1.micro        2013-09-18T06:45:48.000Z        ap-southeast-1a aki-f81354aa                       monitoring-disabled             172.31.14.116   vpc-0528836d    subnet-0628836e ebs       paravirtual      xen             sg-0c698863     default false
NIC     eni-2619b24e    subnet-0628836e vpc-0528836d    542828552986    in-use  172.31.14.116   ip-172-31-14-116.ap-southeast-1.compute.internal   true
NICATTACHMENT           0       attaching       2013-09-18T06:45:48.000Z        true
GROUP   sg-0c698863     labgroup
PRIVATEIPADDRESS        172.31.14.116

 

instances type:

Default create: m1.small

m1.small:
Ram: 1.7 G
Instance Storage:160 GB

t1.micro:
Ram: 0.615G
EBS only

Link:

http://aws.amazon.com/ec2/instance-types/instance-details/

 

# describe

euca-describe-instances i-915832c7

RESERVATION     r-52d08d05      542828552986
INSTANCE        i-915832c7      ami-26a4eb74    ec2-54-254-153-155.ap-southeast-1.compute.amazonaws.com ip-172-31-14-116.ap-southeast-1.compute.internal   running firstkey        0               t1.micro        2013-09-18T06:45:48.000Z   ap-southeast-1a aki-f81354aa                    monitoring-disabled     54.254.153.155  172.31.14.116   vpc-0528836d       subnet-0628836e ebs                                     paravirtual     xen             sg-0c698863default false
BLOCKDEVICE     /dev/sda1       vol-2fe4e57b    2013-09-18T06:45:52.000Z        true
NIC     eni-2619b24e    subnet-0628836e vpc-0528836d    542828552986    in-use  172.31.14.116   ip-172-31-14-116.ap-southeast-1.compute.internal   true
NICATTACHMENT           0       attached        2013-09-18T06:45:48.000Z        true
NICASSOCIATION  54.254.153.155  amazon  {'privateDnsName': 'ip-172-31-14-116.ap-southeast-1.compute.internal', 'association': {'publicIp': '54.254.153.155', 'publicDnsName': 'ec2-54-254-153-155.ap-southeast-1.compute.amazonaws.com', 'ipOwnerId': 'amazon'}, 'primary': 'true', 'privateIpAddress': '172.31.14.116'}
GROUP   sg-0c698863     labgroup
PRIVATEIPADDRESS        172.31.14.116

 

# EBS-based instance

# create instance 由 run 開始

euca-start-instances instance_id
euca-stop-instances instance_id [-f]
# -f,--force

example:

root@home:~/amazon# euca-start-instances i-5b6ce80d
INSTANCE        i-5b6ce80d      stopped pending
root@home:~/amazon# euca-start-instances i-5b6ce80d
INSTANCE        i-5b6ce80d      running running

 

# reboot

euca-reboot-instances instance_id

# terminate

euca-terminate-instances instance_id

euca-describe-instances instance_id

RESERVATION     r-e2f504b4      609491361539    CentOS 6-4 -i386- - Release Media-6-4 - 2013-03-09-AutogenByAWSMP-
INSTANCE        i-ee1b2bb9      ami-42f5bb10                    terminated      test20130830    0               m1.small        2013-08-30T02:37:46.000Z        ap-southeast-1b aki-f81354aa                      monitoring-disabled                                     ebs                                     paravirtual     xen     5d67e28e-8e26-4f7c-8266-32206c76503c    sg-8aafb2d8       default false

P.S.

Terminated instances will go away after a few hours. There is nothing you can do to manually remove them.

Terminated instances 不會刪除它本身的 EBS

 


 

volume (EBS)

查看:

euca-describe-volumes

Output:

                        ID                   size

VOLUME  vol-2fe4e57b    8       snap-e97460db   ap-southeast-1a in-use  2013-09-18T06:45:51.000Z        standard
ATTACHMENT      vol-2fe4e57b    i-915832c7      /dev/sda1       attached        2013-09-18T06:45:52.000Z
  • Output type identifier ("VOLUME")
  • Volume ID
  • Volume size, in GiBs
  • Snapshot the volume was created from, if applicable
  • Availability zone that the volume was launched in
  • Volume state
  • Time stamp when volume creation initiated

 

VOLUME  vol-56fc0b01    8       snap-69fb015c   ap-southeast-1b in-use  2013-09-18T08:29:29.000Z        standard
ATTACHMENT      vol-56fc0b01    i-5b6ce80d      /dev/sda        attached        2013-09-18T08:29:29.000Z
VOLUME  vol-5af2f30e    1               ap-southeast-1a available       2013-09-18T08:58:18.000Z        standard

建立:

# create

euca-create-volume -z ap-southeast-1a -s 5

# created from a snapshot

euca-create-volume -z zone00 --snapshot snap-5E313F37

output:

VOLUME  vol-5deaeb09    5               ap-southeast-1a creating        2013-09-18T07:29:22.420Z

 

Attach:

euca-attach-volume  -i i-3C66428A  -d /dev/sdf  vol-639C3E6C

Error:

euca-attach-volume: error (InvalidVolume.ZoneMismatch): The volume 'vol-5af2f30e' is not in the same availability zone as instance 'i-5b6ce80d'

Normal:

ATTACHMENT      vol-f7fb0ca0    i-5b6ce80d      /dev/sdf        attaching       2013-09-18T09:04:55.829Z

 

[root@ip-172-31-16-136 ~]# dmesg

  alloc irq_desc for 246 on node 0
  alloc kstat_irqs on node 0
blkfront: xvdj: barriers disabled
 xvdj: unknown partition table

[root@ip-172-31-16-136 ~]# ll /dev/sd*
lrwxrwxrwx. 1 root root 4 Sep 18 08:31 /dev/sda -> xvde
lrwxrwxrwx. 1 root root 4 Sep 18 09:05 /dev/sdj -> xvdj

 

Detach:

euca-detach-volume volume_id

 

刪除:

euca-delete-volume  volume_id

Example:

euca-delete-volume vol-5deaeb09

VOLUME  vol-5deaeb09

 

# default configuration (using iSCSI), this creates a logical volume on the storage controller (SC) and exports it using the iSCSI target daemon.

 


 

Snapshot

euca-describe-snapshots

euca-create-snapshot  volume_id  [ -d description ]

euca-delete-snapshot snapshot_id

 


 

Console view

 

# This works if you are using KVM. It does not work with VMware.

euca-get-console-output  [-r] instance_id

 


 

Bundle

 

euca-bundle-vol -d /mnt/ebsvol -p myimage -s 2048 --arch x86_64
-s,--size size_in_mb
-d,--destination

euca-bundle-instance -b mah-bukkit -p windows   i-E7AC420A
# -b bucket
# -p prefix

# -b,--bucket bucket
# -m,--manifest
euca-delete-bundle -b mah-bukkit -m myimage.img.manifest.xml

euca-unbundle -m /tmp/myimage.img.manifest.xml

# upload, download
euca-download-bundle -b mah-bukkit -m myimage.img.manifest.xml
euca-upload-bundle -b bucket_name -m manifest_file

 

#### bundle-tasks

euca-describe-bundle-tasks
euca-cancel-bundle-task bundle_id

 

 


 

Tags

 

euca-describe-tags

# euca-create-tags  resource_id --tag key[=value] [--tag key[=value] ...]

euca-create-tags emi-1e2b3c4d i-7d3e5a2f --tag appserver --tag "stack=dev"

euca-delete-tags snap-4dfg39a --tag "Owner="

 


monitor

 

euca-monitor-instances instance_id

euca-unmonitor-instances instance_id

 


eustore-describe-images

#  have administrator credentials
eustore-install-image -t /tmp/euca-centos-5.8-2012.05.14-x86_64.tgz  -b images  -s "centos 5.8 image" -k kvm -a x86_64

# -b bucket
# -s description
# -k kernel_type (XEN | KVM)

 

Creative Commons license icon Creative Commons license icon