Sha256: 724e518745aedf11eec10d0e62164cd4c019e8974db4fb68025c6769b3fbd55f

Contents?: true

Size: 1.88 KB

Versions: 22

Compression:

Stored size: 1.88 KB

Contents

# frozen_string_literal: true

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

22 entries across 20 versions & 2 rubygems

Version Path
fog-aliyun-0.4.0 lib/fog/aliyun/models/compute/vswitch.rb
fog-aliyun-0.3.19 lib/fog/aliyun/models/compute/vswitch.rb
fog-aliyun-0.3.18 lib/fog/aliyun/models/compute/vswitch.rb
fog-aliyun-0.3.17 lib/fog/aliyun/models/compute/vswitch.rb
fog-aliyun-0.3.16 lib/fog/aliyun/models/compute/vswitch.rb
fog-aliyun-0.3.15 lib/fog/aliyun/models/compute/vswitch.rb
fog-aliyun-0.3.13 lib/fog/aliyun/models/compute/vswitch.rb
fog-aliyun-0.3.12 lib/fog/aliyun/models/compute/vswitch.rb
fog-aliyun-0.3.11 lib/fog/aliyun/models/compute/vswitch.rb
fog-aliyun-0.3.10 lib/fog/aliyun/models/compute/vswitch.rb
fog-aliyun-0.3.9 lib/fog/aliyun/models/compute/vswitch.rb
fog-aliyun-0.3.8 lib/fog/aliyun/models/compute/vswitch.rb
fog-aliyun-0.3.7 lib/fog/aliyun/models/compute/vswitch.rb
fog-aliyun-0.3.6 lib/fog/aliyun/models/compute/vswitch.rb
fog-aliyun-0.3.5 lib/fog/aliyun/models/compute/vswitch.rb
fog-aliyun-0.3.4 lib/fog/aliyun/models/compute/vswitch.rb
fog-aliyun-0.3.3 lib/fog/aliyun/models/compute/vswitch.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/fog-aliyun-0.3.2/lib/fog/aliyun/models/compute/vswitch.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/fog-aliyun-0.3.2/lib/fog/aliyun/models/compute/vswitch.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/fog-aliyun-0.3.2/lib/fog/aliyun/models/compute/vswitch.rb