Skip to content

Commit b848ae3

Browse files
committed
Fixed #121 -- added support for Rackspace open cloud
1 parent f320a77 commit b848ae3

19 files changed

Lines changed: 571 additions & 66 deletions

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ gem 'foodcritic'
55
gem 'berkshelf'
66

77
gem 'knife-ec2'
8+
gem 'knife-rackspace'

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ $ berks upload # upload cookbooks to the chef server
6767

6868
The [Amazon EC2 API Tools](http://aws.amazon.com/developertools/351) will be used to setup basic EC2 infrastructure. The [Knife EC2 plugin](https://github.com/opscode/knife-ec2) will be used to bootstrap the controller.
6969

70-
$ contrib/provision-ec2-controller.sh
70+
$ contrib/aws/provision-ec2-controller.sh
7171

7272
Once the `deis-controller` node exists on the Chef server, you *must* log in to the WebUI add deis-controller to the `admins` group. This is required so the controller can delete node and client records during future scaling operations.
7373

@@ -79,8 +79,8 @@ Install the Deis client using [Pip](http://www.pip-installer.org/en/latest/insta
7979
$ sudo pip install deis
8080
$ deis register http://my-deis-controller.fqdn
8181
username: myuser
82-
password:
83-
password (confirm):
82+
password:
83+
password (confirm):
8484
email: myuser@example.com
8585
Registered myuser
8686
Logged in as myuser
@@ -118,13 +118,13 @@ Use `deis create --formation=dev` to create an application
118118

119119
### 6. Deploy & Scale an Application
120120

121-
Change into your application directory and use ``deis create --formation=dev``
121+
Change into your application directory and use ``deis create --formation=dev``
122122
to create a new application attached to the dev formation.
123123

124124
To deploy the application, use `git push deis master`. Deis will automatically deploy Docker containers and configure Nginx proxies to route requests to your application.
125125

126-
Once your application is deployed, use ``deis scale web=4`` to
127-
scale up web containers. You can also use ``deis logs`` to view
126+
Once your application is deployed, use ``deis scale web=4`` to
127+
scale up web containers. You can also use ``deis logs`` to view
128128
aggregated application logs, or ``deis run`` to run admin
129129
commands inside your application.
130130

@@ -134,7 +134,7 @@ To learn more, use `deis help` or browse [the documentation](http://docs.deis.io
134134
$ deis create --formation=dev
135135
Creating application... done, created peachy-waxworks
136136
Git remote deis added
137-
137+
138138
$ git push deis master
139139
Counting objects: 146, done.
140140
Delta compression using up to 8 threads.
@@ -164,7 +164,7 @@ Scaling containers... but first, coffee!
164164
done in 12s
165165

166166
=== peachy-waxworks Containers
167-
167+
168168
--- web: `node server.js`
169169
web.1 up 2013-09-23T19:02:30.745Z (dev-runtime-1)
170170
web.2 up 2013-09-23T19:36:48.741Z (dev-runtime-1)

api/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ class Provider(UuidAuditedModel):
107107
PROVIDERS = (
108108
('ec2', 'Amazon Elastic Compute Cloud (EC2)'),
109109
('mock', 'Mock Reference Provider'),
110-
('static', 'Static Node Provider'),
110+
('rackspace', 'Rackspace Open Cloud'),
111+
('static', 'Static Node'),
111112
)
112113

113114
owner = models.ForeignKey(settings.AUTH_USER_MODEL)

client/deis.py

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,13 +1569,12 @@ def providers_create(self, args):
15691569
"""
15701570
Create a provider for use by Deis
15711571
1572-
This command is only necessary when adding a duplicate
1573-
set of credentials for a provider like EC2. User accounts
1574-
already come with a default EC2 provider that has empty
1575-
credentials, which should be updated in place.
1572+
This command is only necessary when adding a duplicate set of
1573+
credentials for a provider. User accounts start with empty providers,
1574+
EC2 and Rackspace by default, which should be updated in place.
15761575
1577-
Use `providers:discover` to update credentials of the
1578-
default providers and flavors that come pre-installed.
1576+
Use `providers:discover` to update the credentials for the default
1577+
providers created with your account.
15791578
15801579
Usage: deis providers:create <id> <type> <creds>
15811580
"""
@@ -1586,8 +1585,21 @@ def providers_create(self, args):
15861585
if not k in os.environ:
15871586
msg = "Missing environment variable: {}".format(k)
15881587
raise EnvironmentError(msg)
1589-
creds = {'access_key': os.environ['AWS_ACCESS_KEY'],
1590-
'secret_key': os.environ['AWS_SECRET_KEY']}
1588+
creds = {
1589+
'access_key': os.environ['AWS_ACCESS_KEY'],
1590+
'secret_key': os.environ['AWS_SECRET_KEY'],
1591+
}
1592+
elif type == 'rackspace':
1593+
# read creds from envvars
1594+
for k in ('RACKSPACE_USERNAME', 'RACKSPACE_API_KEY'):
1595+
if not k in os.environ:
1596+
msg = "Missing environment variable: {}".format(k)
1597+
raise EnvironmentError(msg)
1598+
creds = {
1599+
'username': os.environ['RACKSPACE_USERNAME'],
1600+
'api_key': os.environ['RACKSPACE_API_KEY'],
1601+
'identity_type': os.environ.get('CLOUD_ID_TYPE', 'rackspace'),
1602+
}
15911603
else:
15921604
creds = json.loads(args.get('<creds>'))
15931605
id = args.get('<id>') # @ReservedAssignment
@@ -1619,22 +1631,40 @@ def providers_discover(self, args):
16191631
inp = raw_input('Import these credentials? (y/n) : ')
16201632
if inp.lower().strip('\n') != 'y':
16211633
print('Aborting.')
1622-
return
1623-
creds = {'access_key': os.environ['AWS_ACCESS_KEY'],
1624-
'secret_key': os.environ['AWS_SECRET_KEY']}
1625-
body = {'creds': json.dumps(creds)}
1626-
sys.stdout.write('Uploading EC2 credentials... ')
1627-
sys.stdout.flush()
1628-
response = self._dispatch('patch', '/api/providers/ec2',
1629-
json.dumps(body))
1630-
if response.status_code == requests.codes.ok: # @UndefinedVariable
1631-
print('done')
16321634
else:
1633-
raise ResponseError(response)
1634-
1635+
creds = {'access_key': os.environ['AWS_ACCESS_KEY'],
1636+
'secret_key': os.environ['AWS_SECRET_KEY']}
1637+
body = {'creds': json.dumps(creds)}
1638+
sys.stdout.write('Uploading EC2 credentials... ')
1639+
sys.stdout.flush()
1640+
response = self._dispatch('patch', '/api/providers/ec2',
1641+
json.dumps(body))
1642+
if response.status_code == requests.codes.ok: # @UndefinedVariable
1643+
print('done')
1644+
else:
1645+
raise ResponseError(response)
16351646
else:
16361647
print('No credentials discovered, did you install the EC2 Command Line tools?')
1637-
return
1648+
if 'RACKSPACE_API_KEY' in os.environ and 'RACKSPACE_USERNAME' in os.environ:
1649+
print("Found Rackspace credentials: {}".format(os.environ['RACKSPACE_API_KEY']))
1650+
inp = raw_input('Import these credentials? (y/n) : ')
1651+
if inp.lower().strip('\n') != 'y':
1652+
print('Aborting.')
1653+
else:
1654+
creds = {'username': os.environ['RACKSPACE_USERNAME'],
1655+
'api_key': os.environ['RACKSPACE_API_KEY'],
1656+
'identity_type': os.environ.get('CLOUD_ID_TYPE', 'rackspace')}
1657+
body = {'creds': json.dumps(creds)}
1658+
sys.stdout.write('Uploading Rackspace credentials... ')
1659+
sys.stdout.flush()
1660+
response = self._dispatch('patch', '/api/providers/rackspace',
1661+
json.dumps(body))
1662+
if response.status_code == requests.codes.ok: # @UndefinedVariable
1663+
print('done')
1664+
else:
1665+
raise ResponseError(response)
1666+
else:
1667+
print('No Rackspace credentials discovered')
16381668

16391669
def providers_info(self, args):
16401670
"""

client/setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838
author='OpDemand',
3939
author_email='info@opdemand.com',
4040
url='https://github.com/opdemand/deis',
41-
keywords=['opdemand', 'deis', 'cloud', 'chef', 'docker', 'heroku', 'aws', 'ec2'],
41+
keywords=[
42+
'opdemand', 'deis', 'cloud', 'chef', 'docker', 'heroku', 'aws', 'ec2', 'rackspace'
43+
],
4244
classifiers=[
4345
'Development Status :: 4 - Beta',
4446
'Environment :: Console',

contrib/ec2/README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
Provision a Deis Controller on Amazon EC2
2+
=========================================
3+
4+
1. Install [knife-ec2][knifec2] with `gem install knife-ec2` or just
5+
`bundle install` from the root directory of your deis repository:
6+
```console
7+
$ cd $HOME/projects/deis
8+
$ gem install knife-ec2
9+
Fetching: knife-ec2-0.6.4.gem (100%)
10+
Successfully installed knife-ec2-0.6.4
11+
1 gem installed
12+
Installing ri documentation for knife-ec2-0.6.4...
13+
Installing RDoc documentation for knife-ec2-0.6.4...
14+
```
15+
16+
2. Export your EC2 credentials as environment variables and edit knife.rb
17+
to read them:
18+
```console
19+
$ cat <<'EOF' >> $HOME/.bash_profile
20+
export AWS_ACCESS_KEY=<your_aws_access_key>
21+
export AWS_SECRET_KEY=<your_aws_secret_key>
22+
EOF
23+
$ source $HOME/.bash_profile
24+
$ cat <<'EOF' >> $HOME/.chef/knife.rb
25+
knife[:aws_access_key_id] = "#{ENV['AWS_ACCESS_KEY']}"
26+
knife[:aws_secret_access_key] = "#{ENV['AWS_SECRET_KEY']}"
27+
EOF
28+
$ knife ec2 server list
29+
Instance ID Name Public IP Private IP Flavor Image SSH Key Security Groups State
30+
```
31+
32+
3. Download and install the [EC2 Command Line Tools][ec2cli] as described in
33+
[AWS' documentation][ec2cli] and ensure they are available in your $PATH:
34+
```console
35+
$ ec2-describe-group
36+
GROUP sg-33d1045a 693041077886 default default group
37+
PERMISSION 693041077886 default ALLOWS tcp 0 65535 FROM USER 693041077886 NAME default ID sg-33d1045a ingress
38+
PERMISSION 693041077886 default ALLOWS udp 0 65535 FROM USER 693041077886 NAME default ID sg-33d1045a ingress
39+
PERMISSION 693041077886 default ALLOWS icmp -1 -1 FROM USER 693041077886 NAME default ID sg-33d1045a ingress
40+
```
41+
42+
4. Run the provisioning script to create a new Deis controller:
43+
```console
44+
$ ./contrib/ec2/provision-ec2-controller.sh us-west-2
45+
Creating security group: deis-controller
46+
+ ec2-create-group deis-controller -d 'Created by Deis'
47+
GROUP sg-3c3a1c0c deis-controller Created by Deis
48+
+ set +x
49+
Authorizing TCP ports 22,80,443,514 from 0.0.0.0/0...
50+
+ ec2-authorize deis-controller -P tcp -p 22 -s 0.0.0.0/0
51+
...
52+
ec2-203.0.113.33.us-west-2.compute.amazonaws.com
53+
ec2-203-0-113-33.us-west-2.compute.amazonaws.com Chef Client finished, 74 resources updated
54+
55+
Instance ID: i-31c8d106
56+
Flavor: m1.large
57+
Image: ami-72e27c42
58+
Region: us-west-2
59+
Public DNS Name: ec2-203-0-113-33.us-west-2.compute.amazonaws.com
60+
Public IP Address: 203.0.113.33
61+
Run List: recipe[deis::controller]
62+
+ set +x
63+
```
64+
65+
[knifec2]: http://docs.opscode.com/plugin_knife_ec2.html
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# 6. Distribute the AMI to other regions using `ec2-copy-image`
1515
# 7. Create/update your Deis flavors to use your new AMIs
1616
#
17+
apt-get install python-software-properties -y
1718

1819
# Add the Docker repository key to your local keychain
1920
# using apt-key finger you can check the fingerprint matches 36A1 D786 9245 C895 0F96 6E92 D857 6A8B A88D 21E9
@@ -50,7 +51,7 @@ rm -rf /var/lib/cloud
5051

5152
# purge SSH authorized keys
5253
rm -f /home/ubuntu/.ssh/authorized_keys
53-
rm -f /root/.ssh/authorized_keys
54+
# rm -f /root/.ssh/authorized_keys
5455

5556
# ssh host keys are automatically regenerated
5657
# on system boot by ubuntu cloud init
Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@ if [ -z $1 ]; then
55
exit 1
66
fi
77

8+
function echo_color {
9+
echo -e "\033[1m$1\033[0m"
10+
}
11+
12+
THIS_DIR=$(cd $(dirname $0); pwd) # absolute path
13+
CONTRIB_DIR=$(dirname $THIS_DIR)
14+
815
# check for Deis' general dependencies
9-
thisdir=`dirname $0`
10-
if ! $thisdir/check-deis-deps.sh; then
16+
if ! $CONTRIB_DIR/check-deis-deps.sh; then
1117
echo 'Deis is missing some dependencies.'
1218
exit 1
1319
fi
1420

15-
1621
# check for EC2 API tools in $PATH
1722
if ! which ec2-describe-group > /dev/null; then
1823
echo 'Please install the EC2 API command-line tools and ensure they are in your $PATH.'
@@ -23,8 +28,17 @@ fi
2328
: ${AWS_ACCESS_KEY:?'Please set AWS_ACCESS_KEY in your environment for EC2 API access.'}
2429
: ${AWS_SECRET_KEY:?'Please set AWS_SECRET_KEY in your environment for EC2 API access.'}
2530

26-
region=$1
31+
#################
32+
# chef settings #
33+
#################
34+
node_name=deis-controller
35+
run_list="recipe[deis::controller]"
36+
chef_version=11.4.4
2737

38+
#######################
39+
# Amazon EC2 settings #
40+
#######################
41+
region=$1
2842
# see contrib/prepare-ubuntu-ami.sh for instructions
2943
# on creating your own deis-optmized AMIs
3044
if [ "$region" == "ap-northeast-1" ]; then
@@ -47,28 +61,19 @@ else
4761
echo "Cannot find AMI for region: $region"
4862
exit 1
4963
fi
50-
51-
# ec2 settings
5264
flavor="m1.large"
5365
ebs_size=100
5466
sg_name=deis-controller
5567
sg_src=0.0.0.0/0
56-
key_name=deis-controller
5768
export EC2_URL=https://ec2.$region.amazonaws.com/
5869

59-
# ssh settings
70+
################
71+
# SSH settings #
72+
################
73+
key_name=deis-controller
6074
ssh_key_path=~/.ssh/$key_name
6175
ssh_user="ubuntu"
6276

63-
# chef settings
64-
node_name="deis-controller"
65-
run_list="recipe[deis::controller]"
66-
chef_version=11.4.4
67-
68-
function echo_color {
69-
echo -e "\033[1m$1\033[0m"
70-
}
71-
7277
# create security group and authorize ingress
7378
if ! ec2-describe-group | grep -q "$sg_name"; then
7479
echo_color "Creating security group: $sg_name"
@@ -93,9 +98,9 @@ if ! test -e $ssh_key_path; then
9398
ec2-create-keypair $key_name > $ssh_key_path
9499
chmod 600 $ssh_key_path
95100
set +x
96-
echo "Saved to $ssh_key_path"
101+
echo_color "Saved to $ssh_key_path"
97102
else
98-
echo_color "SSH key $ssh_key_path exists"
103+
echo_color "WARNING: SSH key $ssh_key_path exists"
99104
fi
100105

101106
# create data bags

0 commit comments

Comments
 (0)