Class: Fog::Compute::QingCloud::Addresses
- Inherits:
-
Fog::Collection
- Object
- Fog::Collection
- Fog::Compute::QingCloud::Addresses
- Defined in:
- lib/fog/qingcloud/models/compute/addresses.rb
Constant Summary collapse
- ACTIVE_STATUS =
%w[pending available associated suspended]
Instance Method Summary collapse
-
#all(filters = filters) ⇒ Object
QingCloud.addresses.all.
-
#get(public_ip) ⇒ Object
Used to retrieve an IP address.
-
#initialize(attributes) ⇒ Addresses
constructor
Used to create an IP address The IP address can be retrieved by running QingCloud.addresses.get(“test”).
- #new(attributes = {}) ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Addresses
Used to create an IP address The IP address can be retrieved by running QingCloud.addresses.get(“test”). See get method below.
21 22 23 24 25 |
# File 'lib/fog/qingcloud/models/compute/addresses.rb', line 21 def initialize(attributes) self.filters ||= {} filters['status'] = ACTIVE_STATUS unless filters['status'] super end |
Instance Method Details
#all(filters = filters) ⇒ Object
QingCloud.addresses.all
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/fog/qingcloud/models/compute/addresses.rb', line 29 def all(filters = filters) self.filters = filters data = service.describe_addresses(filters).body load(data['eip_set'].map do |eip| if res = eip.delete('resource') eip['server_id'] = res['resource_id'] if res['resource_type'] == 'instance' eip['router_id'] = res['resource_id'] if res['resource_type'] == 'router' end eip end ) if server self.replace(self.select {|address| address.server_id == server.id}) end self end |
#get(public_ip) ⇒ Object
Used to retrieve an IP address
public_ip or eip-id is required to get the associated IP information.
You can run the following command to get the details: QingCloud.addresses.get(“76.7.46.54”) or with eip_id: QingCloud.addresses.get(“eip-zpvk9pq7”)
55 56 57 58 59 60 61 |
# File 'lib/fog/qingcloud/models/compute/addresses.rb', line 55 def get(public_ip) if public_ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/ self.class.new(:service => service).all('public-ip' => public_ip).find {|x| x.public_ip == public_ip} elsif public_ip self.class.new(:service => service).all('eip-id' => public_ip).first end end |
#new(attributes = {}) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/fog/qingcloud/models/compute/addresses.rb', line 63 def new(attributes = {}) if server super({ :server => server }.merge!(attributes)) else super(attributes) end end |