Skip to content

Commit f01d6d6

Browse files
author
Ranjan Kumar
committed
Initial Commit
0 parents  commit f01d6d6

30 files changed

+933
-0
lines changed

.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
*.gem
2+
*.rbc
3+
.bundle
4+
.config
5+
.yardoc
6+
Gemfile.lock
7+
InstalledFiles
8+
_yardoc
9+
coverage
10+
doc/
11+
lib/bundler/man
12+
pkg
13+
rdoc
14+
spec/reports
15+
test/tmp
16+
test/version_tmp
17+
tmp
18+
*.bundle
19+
*.so
20+
*.o
21+
*.a
22+
mkmf.log
23+
gemfiles/*.lock

CONTRIBUTING.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## Getting Involved
2+
3+
New contributors are always welcome, when it doubt please ask questions. We strive to be an open and welcoming community. Please be nice to one another.
4+
5+
### Coding
6+
7+
* Pick a task:
8+
* Offer feedback on open [pull requests](https://github.com/fog/fog-azure/pulls).
9+
* Review open [issues](https://github.com/fog/fog-azure/issues) for things to help on.
10+
* [Create an issue](https://github.com/fog/fog-azure/issues/new) to start a discussion on additions or features.
11+
* Fork the project, add your changes and tests to cover them in a topic branch.
12+
* Commit your changes and rebase against `fog/fog-azure` to ensure everything is up to date.
13+
* [Submit a pull request](https://github.com/fog/fog-azure/compare/)
14+
15+
### Non-Coding
16+
17+
* Offer feedback on open [issues](https://github.com/fog/fog-azure/issues).
18+
* Organize or volunteer at events.

CONTRIBUTORS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
* Jeff Mendoza <[email protected]>
2+
* Ranjan Kumar <[email protected]>
3+
4+

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source 'https://rubygems.org'
2+
3+
# Specify your gem's dependencies in fog-azure.gemspec
4+
gemspec

LICENSE.md

Whitespace-only changes.

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Fog::Azure
2+
3+
Module for the 'fog' gem to support Windows Azure
4+
5+
## Help Needed
6+
7+
This gem needs a maintainer. If you want to work on it, please contact
8+
[@jeffmendoza](mailto:[email protected]) or [@ranjan](mailto:[email protected])
9+
10+
## Installation
11+
12+
Add this line to your application's Gemfile:
13+
14+
```ruby
15+
gem 'fog-azure'
16+
```
17+
18+
And then execute:
19+
20+
$ bundle
21+
22+
Or install it yourself as:
23+
24+
$ gem install fog-azure
25+
26+
## Usage
27+
28+
TODO: Write usage instructions here
29+
30+
## Contributing
31+
32+
1. Fork it ( https://github.com/fog/fog-azure/fork )
33+
2. Create your feature branch (`git checkout -b my-new-feature`)
34+
3. Commit your changes (`git commit -am 'Add some feature'`)
35+
4. Push to the branch (`git push origin my-new-feature`)
36+
5. Create a new Pull Request

Rakefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require 'bundler/gem_tasks'
2+
require 'rake/testtask'
3+
4+
Rake::TestTask.new do |t|
5+
t.libs.push %w(spec)
6+
t.test_files = FileList['spec/**/*_spec.rb']
7+
t.verbose = true
8+
end
9+
10+
desc 'Default Task'
11+
task :default => :test

fog-azure.gemspec

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# coding: utf-8
2+
lib = File.expand_path('../lib', __FILE__)
3+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4+
require 'fog/azure/version'
5+
6+
Gem::Specification.new do |spec|
7+
spec.name = "fog-azure"
8+
spec.version = Fog::AZURE::VERSION
9+
spec.authors = ["Jeff Mendoza", "Ranjan Kumar"]
10+
11+
spec.summary = %q{Module for the 'fog' gem to support Azure cloud services.}
12+
spec.description = %q{This library can be used as a module for `fog` or as standalone provider
13+
to use the Azure cloud services in applications..}
14+
spec.homepage = "http://github.com/fog/fog-azure"
15+
spec.license = "MIT"
16+
17+
spec.files = `git ls-files -z`.split("\x0")
18+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20+
spec.require_paths = ["lib"]
21+
22+
spec.add_development_dependency 'bundler', '~> 1.6'
23+
spec.add_development_dependency 'rake', '~> 10.0'
24+
spec.add_development_dependency 'shindo', '~> 0.3'
25+
spec.add_development_dependency('azure', '~>0.6')
26+
27+
spec.add_dependency 'fog-core', '~> 1.27'
28+
spec.add_dependency 'fog-json', '~> 1.0'
29+
spec.add_dependency 'fog-xml', '~> 0.1'
30+
end

lib/fog/azure.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require 'fog/azure/version'
2+
3+
module Fog
4+
module AZURE
5+
end
6+
end
7+
8+
require 'fog/azure/core'
9+
require 'fog/azure/compute'

lib/fog/azure/compute.rb

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
require "fog/azure/core"
2+
3+
module Fog
4+
module Compute
5+
class Azure < Fog::Service
6+
requires :azure_sub_id
7+
requires :azure_pem
8+
9+
recognizes :azure_api_url
10+
11+
request_path "fog/azure/requests/compute"
12+
request :list_virtual_machines
13+
request :create_virtual_machine
14+
request :delete_virtual_machine
15+
request :get_storage_account
16+
request :create_storage_account
17+
request :list_storage_accounts
18+
request :delete_storage_account
19+
request :reboot_server
20+
request :shutdown_server
21+
request :start_server
22+
request :list_images
23+
24+
model_path "fog/azure/models/compute"
25+
model :server
26+
collection :servers
27+
model :storage_account
28+
collection :storage_accounts
29+
model :image
30+
collection :images
31+
32+
class Mock
33+
def initialize(options={})
34+
begin
35+
require "azure"
36+
rescue LoadError => e
37+
retry if require("rubygems")
38+
raise e.message
39+
end
40+
end
41+
end
42+
43+
class Real
44+
def initialize(options)
45+
begin
46+
require "azure"
47+
rescue LoadError => e
48+
retry if require("rubygems")
49+
raise e.message
50+
end
51+
::Azure.configure do |cfg|
52+
cfg.management_certificate = options[:azure_pem]
53+
cfg.subscription_id = options[:azure_sub_id]
54+
cfg.management_endpoint = options[:azure_api_url] || \
55+
"https://management.core.windows.net"
56+
end
57+
@vm_svc = ::Azure::VirtualMachineManagementService.new
58+
@stg_svc = ::Azure::StorageManagementService.new
59+
@image_svc = ::Azure::VirtualMachineImageManagementService.new
60+
end
61+
end
62+
end
63+
end
64+
end

lib/fog/azure/core.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
require "fog/core"
2+
3+
module Fog
4+
module Azure
5+
extend Fog::Provider
6+
service(:compute, "Compute")
7+
end
8+
end

lib/fog/azure/docs/getting_started.md

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
# Getting started with Fog::Compute and Azure (2014/11/21)
2+
3+
You'll need a [ Management Portal](https://manage.windowsazure.com/) account and API key
4+
to use this.
5+
6+
See http://msdn.microsoft.com/en-us/library/azure/ee460799.aspx.
7+
8+
9+
## Setting credentials
10+
11+
Fog uses `~/.fog` to store credentials. To add Azure as your default provider, simply add the following:
12+
13+
:default:
14+
:azure_sub_id: subscription id
15+
:azure_pem: path-to-certificate
16+
17+
## Connecting, retrieving and managing server objects
18+
19+
```ruby
20+
require 'fog'
21+
require 'pp'
22+
23+
azure = Fog::Compute.new(
24+
:provider => 'Azure',
25+
:azure_sub_id => '35a2461c-22ac-1111-5ed2-11165d755ba4',
26+
:azure_pem => 'c:/path/abc.pem',
27+
:azure_api_url => 'usnorth.management.core.windows.net'
28+
)
29+
```
30+
31+
## Listing servers
32+
33+
Listing servers and attributes:
34+
35+
```ruby
36+
azure.servers.each do |server|
37+
server.cloud_service_name
38+
server.vm_name
39+
server.status
40+
server.ipaddress
41+
server.image
42+
server.disk_name
43+
server.os_type
44+
end
45+
```
46+
47+
## Server creation and life-cycle management
48+
49+
Creating a new server:
50+
51+
```ruby
52+
server = azure.servers.create(
53+
:image => '604889f8753c3__OpenLogic-CentOS',
54+
:location => 'West US',
55+
:vm_name => 'fog-server',
56+
:vm_user => "foguser",
57+
:password => "ComplexPassword!123",
58+
:storage_account_name => 'fogstorage'
59+
)
60+
```
61+
62+
63+
## Retrieve a single record
64+
65+
Get a single server record:
66+
67+
```ruby
68+
server = azure.servers.get('vm-name')
69+
server.cloud_service_name
70+
server.vm_name
71+
server.status
72+
server.ipaddress
73+
server.image
74+
server.disk_name
75+
server.os_type
76+
```
77+
78+
Rebooting a server:
79+
80+
```ruby
81+
server.reboot
82+
```
83+
84+
Start a server:
85+
86+
```ruby
87+
server.start
88+
```
89+
90+
Shutdown a server:
91+
92+
```ruby
93+
server.shutdown
94+
```
95+
96+
Destroying the server:
97+
98+
```ruby
99+
server.destroy
100+
```
101+
102+
## Storage accounts creation and life-cycle management
103+
104+
Creating a new storage account:
105+
106+
```ruby
107+
azure.storage_accounts.create(
108+
:name => 'storageaccountname',
109+
:location => 'West US'
110+
)
111+
```
112+
113+
## Listing storage accounts
114+
115+
Listing storage accounts and attributes:
116+
117+
```ruby
118+
azure.storage_accounts.each do |storage_acc|
119+
storage_acc.name
120+
storage_acc.location
121+
end
122+
```
123+
124+
## Retrieve a single record
125+
126+
Get a single storage account record:
127+
128+
```ruby
129+
storage_acc = azure.storage_accounts.get('storageaccountname')
130+
server.name
131+
server.location
132+
server.endpoints
133+
```
134+
135+
Destroying the storage account:
136+
137+
```ruby
138+
storage_acc.destroy
139+
```
140+
141+
## Listing images
142+
143+
Listing images and attributes:
144+
145+
```ruby
146+
azure.images.each do |image|
147+
image.name
148+
image.os_type
149+
image.category
150+
image.locations
151+
end
152+
```
153+
154+
## Retrieve a single record
155+
156+
Get a single image record:
157+
158+
```ruby
159+
image = azure.image.get('image_name')
160+
image.name
161+
image.locations
162+
image.category
163+
image.os_type
164+
```

lib/fog/azure/models/compute/image.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
require "fog/core/model"
2+
3+
module Fog
4+
module Compute
5+
class Azure
6+
class Image < Fog::Model
7+
identity :name
8+
attribute :os_type
9+
attribute :category
10+
attribute :locations
11+
end
12+
end
13+
end
14+
end

0 commit comments

Comments
 (0)