Sha256: 0198d39a69cc65f6a08b0711ad043420396fafc65fb6fc3bcf3d713b9261ec7e

Contents?: true

Size: 1.94 KB

Versions: 6

Compression:

Stored size: 1.94 KB

Contents

require 'fog/core/model'
module Fog
  module Compute
    class Aliyun
      class Vswitch < Fog::Model
        identity  :id,                  aliases: 'VSwitchId'
        attribute :vpc_id,              aliases: 'VpcId'
        attribute :zone_id,             aliases: 'ZoneId'
        attribute :name,                aliases: 'VSwitchName'
        attribute :available_ip_count,  aliases: 'AvailableIpAddressCount'
        attribute :state,               aliases: 'Status'
        attribute :cidr_block,          aliases: 'CidrBlock'
        attribute :description,      aliases: 'Description'
        attribute :region_id,        aliases: 'RegionId'
        attribute :create_at, aliases: 'CreationTime'
        def initialize(attributes = {})
          super
        end

        def ready?
          requires :state
          state == 'Available'
        end

        # Removes an existing vpc
        #
        # vpc.destroy
        #
        # ==== Returns
        #
        # True or false depending on the result
        #

        def destroy
          requires :id

          service.delete_vswitch(id)
          true
        end

        # Create a vpc
        #
        # >> g = Aliyun.vpcs.new(:cidr_block => "10.1.2.0/24")
        # >> g.save
        #
        # == Returns:
        #
        # True or an exception depending on the result. Keep in mind that this *creates* a new vpc.
        # As such, it yields an InvalidGroup.Duplicate exception if you attempt to save an existing vpc.
        #

        def save(options = {})
          requires :vpc, :cidr_block
          options[:name] = name if name
          options[:description] = description if description
          Fog::JSON.decode(service.create_vswitch(vpc.id, cidr_block, options).body)
          true
        end

        def vpc
          $vpc
        end

        def all
          Fog::JSON.decode(service.list_vswitchs(vpc_id).body)['VSwitches']['VSwitch']
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
fog-aliyun-0.3.0 lib/fog/aliyun/models/compute/vswitch.rb
fog-aliyun-0.2.2 lib/fog/aliyun/models/compute/vswitch.rb
fog-xiaozhu-0.2.2 lib/fog/aliyun/models/compute/vswitch.rb
fog-xiaozhu-0.2.1 lib/fog/aliyun/models/compute/vswitch.rb
fog-aliyun-0.2.1 lib/fog/aliyun/models/compute/vswitch.rb
fog-aliyun-0.2.0 lib/fog/aliyun/models/compute/vswitch.rb