Skip to content
This repository has been archived by the owner on Nov 12, 2021. It is now read-only.

Commit

Permalink
modify comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tacyan committed Mar 7, 2016
1 parent 757ebe0 commit 9451997
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
21 changes: 10 additions & 11 deletions lib/openstack/compute/connection.rb
Expand Up @@ -33,7 +33,8 @@ def get_server(id)

# Returns an array of hashes, one for each server that exists under this account. The hash keys are :name and :id.
#
# You can also provide :limit and :offset parameters to handle pagination.
# You can also provide :limit and :offset and :"changes-since" and :image and :flavor and :name and :status
# and :host and :limit and :marker parameters to handle pagination.
# http://developer.openstack.org/api-ref-compute-v2.1.html
#
# >> cs.list_servers
Expand All @@ -44,8 +45,7 @@ def get_server(id)
# {:name=>"demo-aicache1", :id=>187853}]
def list_servers(options = {})
anti_cache_param="cacheid=#{Time.now.to_i}"
options = options.to_query
path = options.empty? ? "#{@connection.service_path}/servers?#{anti_cache_param}" : "#{@connection.service_path}/servers?#{options}&#{anti_cache_param}"
path = options.empty? ? "#{@connection.service_path}/servers?#{anti_cache_param}" : "#{@connection.service_path}/servers?#{options.to_query}&#{anti_cache_param}"
response = @connection.csreq("GET",@connection.service_host,path,@connection.service_port,@connection.service_scheme)
OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/)
OpenStack.symbolize_keys(JSON.parse(response.body)["servers"])
Expand All @@ -56,7 +56,8 @@ def list_servers(options = {})
# includes public and private IP addresses, status, hostID, and more. All hash keys are symbols except for the metadata
# hash, which are verbatim strings.
#
# You can also provide :limit and :offset parameters to handle pagination.
# You can also provide :limit and :offset and :"changes-since" and :image and :flavor and :name and :status and :host
# and :limit and :marker parameters to handle pagination.
# http://developer.openstack.org/api-ref-compute-v2.1.html
# >> cs.list_servers_detail
# => [{:name=>"MyServer", :addresses=>{:public=>["67.23.42.37"], :private=>["10.176.241.237"]}, :metadata=>{"MyData" => "Valid"}, :imageRef=>10, :progress=>100, :hostId=>"36143b12e9e48998c2aef79b50e144d2", :flavorRef=>1, :id=>110917, :status=>"ACTIVE"}]
Expand All @@ -65,8 +66,7 @@ def list_servers(options = {})
# => [{:status=>"ACTIVE", :imageRef=>10, :progress=>100, :metadata=>{}, :addresses=>{:public=>["x.x.x.x"], :private=>["x.x.x.x"]}, :name=>"demo-standingcloud-lts", :id=>168867, :flavorRef=>1, :hostId=>"xxxxxx"},
# {:status=>"ACTIVE", :imageRef=>8, :progress=>100, :metadata=>{}, :addresses=>{:public=>["x.x.x.x"], :private=>["x.x.x.x"]}, :name=>"demo-aicache1", :id=>187853, :flavorRef=>3, :hostId=>"xxxxxx"}]
def list_servers_detail(options = {})
options = options.to_query
path = options.empty? ? "#{@connection.service_path}/servers/detail" : "#{@connection.service_path}/servers/detail?#{options}"
path = options.empty? ? "#{@connection.service_path}/servers/detail" : "#{@connection.service_path}/servers/detail?#{options.to_query}"
response = @connection.csreq("GET",@connection.service_host,path,@connection.service_port,@connection.service_scheme)
OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/)
json_server_list = JSON.parse(response.body)["servers"]
Expand Down Expand Up @@ -131,7 +131,8 @@ def create_server(options)
# Returns an array of hashes listing available server images that you have access too,
# including stock OpenStack Compute images and any that you have created. The "id" key
# in the hash can be used where imageRef is required. You can also provide :limit and
# :offset parameters to handle pagination.
# :offset and :"changes-since" and :server and :name and :status :minDisk and :minRam
# and :type and :limit and :marker parameters to handle pagination.
#
# >> cs.list_images
# => [{:name=>"CentOS 5.2", :id=>2, :updated=>"2009-07-20T09:16:57-05:00", :status=>"ACTIVE", :created=>"2009-07-20T09:16:57-05:00"},
Expand All @@ -142,8 +143,7 @@ def create_server(options)
# {:status=>"ACTIVE", :name=>"CentOS 5.3", :updated=>"2009-08-26T14:59:52-05:00", :id=>7},
# {:status=>"ACTIVE", :name=>"CentOS 5.4", :updated=>"2009-12-16T01:02:17-06:00", :id=>187811}]
def list_images(options = {})
options = options.to_query
path = options.empty? ? "#{@connection.service_path}/images/detail" : "#{@connection.service_path}/images/detail?#{options}"
path = options.empty? ? "#{@connection.service_path}/images/detail" : "#{@connection.service_path}/images/detail?#{options.to_query}"
response = @connection.csreq("GET",@connection.service_host,path,@connection.service_port,@connection.service_scheme)
OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/)
OpenStack.symbolize_keys(JSON.parse(response.body)['images'])
Expand Down Expand Up @@ -173,8 +173,7 @@ def get_image(id)
# {:ram=>2048, :disk=>80, :name=>"2GB server", :id=>4},
# {:ram=>4096, :disk=>160, :name=>"4GB server", :id=>5}]
def list_flavors(options = {})
options = options.to_query
path = options.empty? ? "#{@connection.service_path}/flavors/detail" : "#{@connection.service_path}/flavors/detail?#{options}"
path = options.empty? ? "#{@connection.service_path}/flavors/detail" : "#{@connection.service_path}/flavors/detail?#{options.to_query}"
response = @connection.csreq("GET",@connection.service_host,path,@connection.service_port,@connection.service_scheme)
OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/)
OpenStack.symbolize_keys(JSON.parse(response.body)['flavors'])
Expand Down
2 changes: 1 addition & 1 deletion test/unit/flavors_test.rb
Expand Up @@ -66,7 +66,7 @@ def test_list_flavors
response = mock()
response.stubs(:code => "200", :body => json_response)
@comp.connection.stubs(:csreq).returns(response)
flavor = @comp.list_flavors(tenant_id: "5a978754183d4765bf96aaf847e5d463", limit: 1)
flavor = @comp.list_flavors(limit: 1)
assert_equal flavor[0][:id], '1'
assert_equal flavor[0][:name], 'm1.tiny'
assert_equal flavor[0][:ram], 512
Expand Down
5 changes: 3 additions & 2 deletions test/unit/servers_test.rb
Expand Up @@ -74,14 +74,15 @@ def test_filters_name_list_servers
end

def test_list_servers_detail
json_response = list_servers_detail_json("SHUTOFF")
json_response = list_servers_detail_json_response("SHUTOFF")

response = mock()
response.stubs(:code => "200", :body => json_response)
@comp.connection.stubs(:csreq).returns(response)

servers = @comp.list_servers_detail(status: "SHUTOFF")
assert_equal "SHUTOFF", servers[0][:status]
assert_equal "new-server-test", servers[0][:name]
end

def test_get_server
Expand Down Expand Up @@ -247,7 +248,7 @@ def list_servers
@comp.list_servers(name: "new-server-test")
end

def list_servers_detail_json(status= "ACTIVE")
def list_servers_detail_json_response(status= "ACTIVE")
%{{
"servers": [
{
Expand Down

0 comments on commit 9451997

Please sign in to comment.