简体   繁体   English

Ruby - 资源不能重复使用

[英]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.network_sg.create之后,除非我创建一个新的network_sg资源,否则我不能将network_sg用于其他目的。

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 ,但在创建新 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.将 network_sg 设置为常量有效。 It can be re-used.它可以重复使用。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 watir 浏览器对象可以在以后的 Ruby 进程中重用吗? - Can a watir browser object be re-used in a later Ruby process? 在Ruby中添加图片和资源后我无法保存图书 - I can't save a book after adding image and resource in Ruby 当我不知道使用哪个程序来安装 Ruby 时,如何升级 Ruby 版本? - How to upgrade Ruby version when I can't figure out which program was used to install Ruby? Ruby中的所有内容都可以在Rails中使用吗? - Is everything in Ruby can be used in Rails? 如何重新申请红宝石? - How can I re-require in ruby? 与||一起使用时,为什么此Ruby case语句返回“无法将nil转换为String(TypeError)”? - Why does this Ruby case statement return “can't convert nil into String (TypeError)” when used with ||? 即使使用“打印”,也无法在红宝石的同一行上打印数据。应使用什么? - Can't print data on same line in ruby, even with 'print'.What should be used? Unix套接字可以用于节俭的红宝石客户端吗? - Can unix socket be used for thrift ruby client? Ruby:在以下示例中如何使用Enumerator? - Ruby: how can Enumerator be used in the following example? proc可以与Ruby 2.0中的case语句一起使用吗? - Can procs be used with case statements in Ruby 2.0?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM