简体   繁体   中英

Ruby - Resource can't be re-used

After the network_sg.create I can't use the network_sg for other purpose unless I create a new network_sg resource.

Is there a way to get past this? I tried freeze network_sg but I get a Frozen Error while creating a new SG.

network_sg = Azure::Armrest::Network::NetworkSecurityGroupService.new(conf)

options = {
  :location => 'eastus',
}

network_sg.create('test-network_sg-4', rg, options)    
  
# Can't re-use the `network_sg` anymore. 
# And I have to recreate `network_sg = Azure::Armrest::Network::NetworkSecurityGroupService.new(conf)` before I can use it again.

network_sg.list_all.each do |network_sg|
    $evm.log('info', "azure network_sg test is: #{network_sg.name} ")  
end

Setting the network_sg as constant worked. It can be re-used.

NETWORK_SG = Azure::Armrest::Network::NetworkSecurityGroupService.new(conf)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM