Skip to content

Instantly share code, notes, and snippets.

@nickkaranatsios
Last active December 14, 2015 13:58
Show Gist options
  • Save nickkaranatsios/5097049 to your computer and use it in GitHub Desktop.
Save nickkaranatsios/5097049 to your computer and use it in GitHub Desktop.
vlinks

Currently trema-switch configuration looks like the following:

trema_switch( "lsw" ) {
  datapath_id "0xabc"
  ports "trema0-0,trema1-0"
}

vhost ("host1") {
  ip "192.168.0.1"
  netmask "255.255.0.0"
  mac "00:00:00:01:00:01"
}

vhost ("host2") {
  ip "192.168.0.2"
  netmask "255.255.0.0"
  mac "00:00:00:01:00:02"
}

link "host1", "lsw"
link "host2", "lsw"

In link.rb the link name is hardcoded to trema name. I would like to use as link names trema-switch's ports attribute.
Is there a simple way of achieving this somehow copy those values to @stanza or?

@nickkaranatsios
Copy link
Author

require "docile"

class GroupAction
  attr_reader :group_id
  def initialize group_id
    @group_id = group_id
  end
end

class DecMplsTtl
  def initialize
  end
end

class ActionBuilder
  attr_accessor :actions
  def initialize
    @actions = []
  end
  def group group_id
    ga = GroupAction.new group_id
    @actions << ga
    puts ga.inspect
  end
  def dec_mpls_ttl
    dttl = DecMplsTtl.new
    puts dttl.inspect
    @actions << dttl
  end
end


def actions( &block )
  builder = ActionBuilder.new
  Docile.dsl_eval( builder, &block )
  puts builder.actions.inspect
end


actions do
  group 1
  dec_mpls_ttl
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment