Ruby:使用脚本内的外部脚本进行比较
所以我得到了一个脚本 (A),它为新的虚拟服务器找到合适的 IP 地址。首先,它会查看数据库,看看他选择的第一个 IP 是否尚未被其他服务器占用。如果该 IP 尚未使用,脚本会对其执行 ping 操作。如果 ping 没有响应,那么我们将进入下一步,这就是我遇到问题的地方。
在下一步中,我必须检查 IP 地址是否已在 Netscaler(路由器)中注册。为此,我必须在同一台计算机上使用另一个脚本 (B)。这个其他脚本返回 netscaler 中定义的所有 ip 的列表。当我运行它时,输出看起来像这样,
x.x.x.x
x.x.x.x
x.x.x.x (and so on..).
我发现了很多从脚本 A 中执行脚本 B 的方法,但我发现的方法都不允许我做我想做的事情。
我的目标是将我的脚本找到的 IP 与列出的所有 IP 进行比较,而不将最后的 IP 打印在屏幕上。
因此,为了更清楚一点,假设脚本 A 找到了 IP: 1.2.3.4
然后它会调用脚本 B,脚本 B 将这个列表返回给脚本 A
1.2.3.5 1.2.4.5 1.2.5.1 等等。
然后 A 会将 1.2.3.4 与脚本 B 返回的所有内容进行比较,而不实际将它们显示在屏幕上。
非常感谢!
So I got a script (A) that finds a suitable IP address for a new virtual server. At first, it takes a look in the database to see if the first ip he chose isn't already taken by another server. If the IP is not already in use, the script pings it. If there is no response from the ping, then we get to the next step and this is where I'm having a problem.
In the next step, I have to check if the IP address is already registred in the netscaler (router) or not. To do this, I must use another script on the same machine (B). This other script return the list of all the ips defined in the netscaler. When I run it, the output looks like this
x.x.x.x
x.x.x.x
x.x.x.x (and so on..).
I found many ways to execute the script B from whiting the script A, but none of what I found allow me to do what I'd like to.
My goal is to compare the ip my script found with all of those that are listed, without having those last ones printed on the screen.
So, to make it a bit clearer, let's say that the scrip A found the IP : 1.2.3.4
It would then call script B that would return to script A this list
1.2.3.5
1.2.4.5
1.2.5.1
and so on.
and then A would compare 1.2.3.4 with all those returned by script B without actually showing them on screen.
Thank you very much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

我会将
scriptB
业务逻辑与scriptB
ui (CLI) 逻辑分开:将 netscaler 中定义的所有 ip 列表提取到单独的类中 逻辑/方法:
I would separate
scriptB
business logic fromscriptB
ui (CLI) logic:Extract your
list of all the ips defined in the netscaler
logic into separate class/method: