[PATCH v2 compass-ci] lib/sched_client.rb: add some common methods for provider

[why] we have some providers: ipxe, container, libvirt all of them need register testbox info and consume job from scheduler Signed-off-by: Xiao Shenwei <xiaoshenwei96@163.com> --- lib/sched_client.rb | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/lib/sched_client.rb b/lib/sched_client.rb index fec4b14..db60fa2 100644 --- a/lib/sched_client.rb +++ b/lib/sched_client.rb @@ -16,4 +16,43 @@ class SchedClient resource = RestClient::Resource.new("http://#{@host}:#{@port}/submit_job") resource.post(job_json) end + + # scheduler API /boot.:boot_type/:parameter/:value + # boot_type parameter + # 1 ipxe mac + # 2 container hostname + # 3 libvirt mac + def consume_job(boot_type: '', parameter: '', value: '') + RestClient.get "http://#{@host}:#{@port}/boot.#{boot_type}/#{parameter}/#{value}" + end + + # some provider only need register host2queues + # like boot.container + def register_mac2host(hostname, mac) + @hostname = hostname + @mac = mac + RestClient.put( + "http://#{@host}:#{@port}/set_host_mac?hostname=#{@hostname}&mac=#{@mac}", {} + ) + end + + def register_host2queues(hostname, queues) + @hostname = hostname + @queues = queues + RestClient.put( + "http://#{@host}:#{@port}/set_host2queues?host=#{@hostname}&queues=#{@queues}", {} + ) + end + + def delete_mac2host + RestClient.put( + "http://#{@host}:#{@port}/del_host_mac?mac=#{@mac}", {} + ) + end + + def delete_host2queues + RestClient.put( + "http://#{@host}:#{@port}/del_host2queues?host=#{@hostname}", {} + ) + end end -- 2.23.0

providers/qemu.sh also register testbox info, what's dirrerent with this patch, it will be call in libvirt scprit? Thanks, Yinsi On Tue, Jan 26, 2021 at 09:17:04AM +0800, Xiao Shenwei wrote:
[why] we have some providers: ipxe, container, libvirt
all of them need register testbox info and consume job from scheduler
Signed-off-by: Xiao Shenwei <xiaoshenwei96@163.com> --- lib/sched_client.rb | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+)
diff --git a/lib/sched_client.rb b/lib/sched_client.rb index fec4b14..db60fa2 100644 --- a/lib/sched_client.rb +++ b/lib/sched_client.rb @@ -16,4 +16,43 @@ class SchedClient resource = RestClient::Resource.new("http://#{@host}:#{@port}/submit_job") resource.post(job_json) end + + # scheduler API /boot.:boot_type/:parameter/:value + # boot_type parameter + # 1 ipxe mac + # 2 container hostname + # 3 libvirt mac + def consume_job(boot_type: '', parameter: '', value: '') + RestClient.get "http://#{@host}:#{@port}/boot.#{boot_type}/#{parameter}/#{value}" + end + + # some provider only need register host2queues + # like boot.container + def register_mac2host(hostname, mac) + @hostname = hostname + @mac = mac + RestClient.put( + "http://#{@host}:#{@port}/set_host_mac?hostname=#{@hostname}&mac=#{@mac}", {} + ) + end + + def register_host2queues(hostname, queues) + @hostname = hostname + @queues = queues + RestClient.put( + "http://#{@host}:#{@port}/set_host2queues?host=#{@hostname}&queues=#{@queues}", {} + ) + end + + def delete_mac2host + RestClient.put( + "http://#{@host}:#{@port}/del_host_mac?mac=#{@mac}", {} + ) + end + + def delete_host2queues + RestClient.put( + "http://#{@host}:#{@port}/del_host2queues?host=#{@hostname}", {} + ) + end end -- 2.23.0

On Tue, Jan 26, 2021 at 10:03:20AM +0800, Liu Yinsi wrote:
providers/qemu.sh also register testbox info, what's dirrerent with this patch, it will be call in libvirt scprit?
this is shell script, libvirt will need operate erb xml libvirt-api, use ruby may be better also, boot.container have the same demand Thanks, Shenwei
Thanks, Yinsi
On Tue, Jan 26, 2021 at 09:17:04AM +0800, Xiao Shenwei wrote:
[why] we have some providers: ipxe, container, libvirt
all of them need register testbox info and consume job from scheduler
Signed-off-by: Xiao Shenwei <xiaoshenwei96@163.com> --- lib/sched_client.rb | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+)
diff --git a/lib/sched_client.rb b/lib/sched_client.rb index fec4b14..db60fa2 100644 --- a/lib/sched_client.rb +++ b/lib/sched_client.rb @@ -16,4 +16,43 @@ class SchedClient resource = RestClient::Resource.new("http://#{@host}:#{@port}/submit_job") resource.post(job_json) end + + # scheduler API /boot.:boot_type/:parameter/:value + # boot_type parameter + # 1 ipxe mac + # 2 container hostname + # 3 libvirt mac + def consume_job(boot_type: '', parameter: '', value: '') + RestClient.get "http://#{@host}:#{@port}/boot.#{boot_type}/#{parameter}/#{value}" + end + + # some provider only need register host2queues + # like boot.container + def register_mac2host(hostname, mac) + @hostname = hostname + @mac = mac + RestClient.put( + "http://#{@host}:#{@port}/set_host_mac?hostname=#{@hostname}&mac=#{@mac}", {} + ) + end + + def register_host2queues(hostname, queues) + @hostname = hostname + @queues = queues + RestClient.put( + "http://#{@host}:#{@port}/set_host2queues?host=#{@hostname}&queues=#{@queues}", {} + ) + end + + def delete_mac2host + RestClient.put( + "http://#{@host}:#{@port}/del_host_mac?mac=#{@mac}", {} + ) + end + + def delete_host2queues + RestClient.put( + "http://#{@host}:#{@port}/del_host2queues?host=#{@hostname}", {} + ) + end end -- 2.23.0

On Tue, Jan 26, 2021 at 09:17:04AM +0800, Xiao Shenwei wrote:
[why] we have some providers: ipxe, container, libvirt
all of them need register testbox info and consume job from scheduler
Signed-off-by: Xiao Shenwei <xiaoshenwei96@163.com> --- lib/sched_client.rb | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+)
diff --git a/lib/sched_client.rb b/lib/sched_client.rb index fec4b14..db60fa2 100644 --- a/lib/sched_client.rb +++ b/lib/sched_client.rb @@ -16,4 +16,43 @@ class SchedClient resource = RestClient::Resource.new("http://#{@host}:#{@port}/submit_job") resource.post(job_json) end + + # scheduler API /boot.:boot_type/:parameter/:value + # boot_type parameter + # 1 ipxe mac + # 2 container hostname + # 3 libvirt mac + def consume_job(boot_type: '', parameter: '', value: '') + RestClient.get "http://#{@host}:#{@port}/boot.#{boot_type}/#{parameter}/#{value}" + end + + # some provider only need register host2queues + # like boot.container + def register_mac2host(hostname, mac) + @hostname = hostname + @mac = mac + RestClient.put( + "http://#{@host}:#{@port}/set_host_mac?hostname=#{@hostname}&mac=#{@mac}", {} + ) + end + + def register_host2queues(hostname, queues) + @hostname = hostname + @queues = queues + RestClient.put( + "http://#{@host}:#{@port}/set_host2queues?host=#{@hostname}&queues=#{@queues}", {} + ) + end
这可以封装成类: 因为这样子就不需要调用确定的函数 ==> Update.delete(queues) ==> Update.delete(mac) 尽量避免重复 class Update: @queues @mac def delete def register
+ def delete_mac2host + RestClient.put( + "http://#{@host}:#{@port}/del_host_mac?mac=#{@mac}", {} + ) + end + + def delete_host2queues + RestClient.put( + "http://#{@host}:#{@port}/del_host2queues?host=#{@hostname}", {} + ) + end end -- 2.23.0

+ ) + end + + def register_host2queues(hostname, queues) + @hostname = hostname + @queues = queues + RestClient.put( + "http://#{@host}:#{@port}/set_host2queues?host=#{@hostname}&queues=#{@queues}", {} + ) + end
这可以封装成类: 因为这样子就不需要调用确定的函数 ==> Update.delete(queues) ==> Update.delete(mac) 尽量避免重复
class Update: @queues @mac
def delete def register
good idea, i will consider it later Thanks, Shenwei
+ def delete_mac2host + RestClient.put( + "http://#{@host}:#{@port}/del_host_mac?mac=#{@mac}", {} + ) + end + + def delete_host2queues + RestClient.put( + "http://#{@host}:#{@port}/del_host2queues?host=#{@hostname}", {} + ) + end end -- 2.23.0
participants (3)
-
Li Ping
-
Liu Yinsi
-
Xiao Shenwei