request api: http://$SCHED_HOST:$SCHED_PORT/boot.libvirt/mac/$mac
Signed-off-by: Xiao Shenwei xiaoshenwei96@163.com --- providers/libvirt/run.rb | 67 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 providers/libvirt/run.rb
diff --git a/providers/libvirt/run.rb b/providers/libvirt/run.rb new file mode 100755 index 0000000..0ff0d4f --- /dev/null +++ b/providers/libvirt/run.rb @@ -0,0 +1,67 @@ +#!/usr/bin/env ruby +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# frozen_string_literal: true + +require 'json' +require 'digest/md5' +require_relative "#{ENV['CCI_SRC']}/lib/log" +require_relative "#{ENV['CCI_SRC']}/lib/sched_client" +require_relative "#{ENV['CCI_SRC']}/providers/lib/context" + +def create_logger(hostname) + filename = "#{hostname}.log" + File.delete(filename) if FileTest.exist?(filename) + Log.new filename +end + +def compute_mac(string) + /(..)(..)(..)(..)(..)/ =~ Digest::MD5.hexdigest(string) + "0a:#{$1}:#{$2}:#{$3}:#{$4}:#{$5}" +end + +def nojob?(response) + flag = false + if response['job_id'].empty? + puts '----------' + puts 'No job now' + puts '----------' + flag = true + end + return flag +end + +def request(context, sched_client, logger) + mac = context.info['mac'] + hostname = context.info['hostname'] + queues = context.info['queues'] + sched_client.register_mac2host(hostname, mac) + sched_client.register_host2queues(hostname, queues) + response = JSON.parse(sched_client.consume_job('libvirt', 'mac', mac)) + if nojob?(response) + logger.info('No job now') + sched_client.delete_mac2host(mac) + sched_client.delete_host2queues(hostname) + response = nil + end + return response +end + +def main(hostname, queues) + logger = create_logger(hostname) + mac = compute_mac hostname + context = Context.new(mac, hostname, queues) + sched_client = SchedClient.new + response = request(context, sched_client, logger) + return if response.nil? + + # TODO + # based on response load file + # TODO + # generate domain.xml + # TODO + # use ruby-libvirt api start a vm + # clean env + sched_client.delete_mac2host(mac) + sched_client.delete_host2queues(hostname) +end
On Tue, Jan 26, 2021 at 04:07:17PM +0800, Xiao Shenwei wrote:
request api: http://$SCHED_HOST:$SCHED_PORT/boot.libvirt/mac/$mac
Signed-off-by: Xiao Shenwei xiaoshenwei96@163.com
providers/libvirt/run.rb | 67 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 providers/libvirt/run.rb
diff --git a/providers/libvirt/run.rb b/providers/libvirt/run.rb new file mode 100755 index 0000000..0ff0d4f --- /dev/null +++ b/providers/libvirt/run.rb @@ -0,0 +1,67 @@ +#!/usr/bin/env ruby +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# frozen_string_literal: true
+require 'json' +require 'digest/md5' +require_relative "#{ENV['CCI_SRC']}/lib/log" +require_relative "#{ENV['CCI_SRC']}/lib/sched_client" +require_relative "#{ENV['CCI_SRC']}/providers/lib/context"
+def create_logger(hostname)
- filename = "#{hostname}.log"
- File.delete(filename) if FileTest.exist?(filename)
- Log.new filename
+end
+def compute_mac(string)
- /(..)(..)(..)(..)(..)/ =~ Digest::MD5.hexdigest(string)
- "0a:#{$1}:#{$2}:#{$3}:#{$4}:#{$5}"
+end
+def nojob?(response)
- flag = false
- if response['job_id'].empty?
- puts '----------'
- puts 'No job now'
- puts '----------'
- flag = true
- end
- return flag
+end
+def request(context, sched_client, logger)
- mac = context.info['mac']
- hostname = context.info['hostname']
- queues = context.info['queues']
- sched_client.register_mac2host(hostname, mac)
- sched_client.register_host2queues(hostname, queues)
- response = JSON.parse(sched_client.consume_job('libvirt', 'mac', mac))
- if nojob?(response)
- logger.info('No job now')
- sched_client.delete_mac2host(mac)
- sched_client.delete_host2queues(hostname)
- response = nil
- end
- return response
+end
+def main(hostname, queues)
- logger = create_logger(hostname)
- mac = compute_mac hostname
- context = Context.new(mac, hostname, queues)
- sched_client = SchedClient.new
- response = request(context, sched_client, logger)
- return if response.nil?
- # TODO
- # based on response load file
- # TODO
- # generate domain.xml
- # TODO
- # use ruby-libvirt api start a vm
- # clean env
- sched_client.delete_mac2host(mac)
Don't put any "todo" in code.
Thanks, Xijian
- sched_client.delete_host2queues(hostname)
+end
2.23.0
On Tue, Jan 26, 2021 at 04:07:17PM +0800, Xiao Shenwei wrote:
request api: http://$SCHED_HOST:$SCHED_PORT/boot.libvirt/mac/$mac
Signed-off-by: Xiao Shenwei xiaoshenwei96@163.com
providers/libvirt/run.rb | 67 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 providers/libvirt/run.rb
diff --git a/providers/libvirt/run.rb b/providers/libvirt/run.rb new file mode 100755 index 0000000..0ff0d4f --- /dev/null +++ b/providers/libvirt/run.rb @@ -0,0 +1,67 @@ +#!/usr/bin/env ruby +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# frozen_string_literal: true
+require 'json' +require 'digest/md5' +require_relative "#{ENV['CCI_SRC']}/lib/log" +require_relative "#{ENV['CCI_SRC']}/lib/sched_client" +require_relative "#{ENV['CCI_SRC']}/providers/lib/context"
+def create_logger(hostname)
- filename = "#{hostname}.log"
- File.delete(filename) if FileTest.exist?(filename)
- Log.new filename
+end
+def compute_mac(string)
- /(..)(..)(..)(..)(..)/ =~ Digest::MD5.hexdigest(string)
- "0a:#{$1}:#{$2}:#{$3}:#{$4}:#{$5}"
+end
+def nojob?(response)
how about nojob => exist_job ?
- flag = false
- if response['job_id'].empty?
- puts '----------'
- puts 'No job now'
- puts '----------'
- flag = true
- end
- return flag
+end
+def request(context, sched_client, logger)
how about request => request_job ?
- mac = context.info['mac']
- hostname = context.info['hostname']
- queues = context.info['queues']
- sched_client.register_mac2host(hostname, mac)
- sched_client.register_host2queues(hostname, queues)
- response = JSON.parse(sched_client.consume_job('libvirt', 'mac', mac))
- if nojob?(response)
- logger.info('No job now')
- sched_client.delete_mac2host(mac)
- sched_client.delete_host2queues(hostname)
- response = nil
- end
- return response
+end
+def main(hostname, queues)
- logger = create_logger(hostname)
- mac = compute_mac hostname
- context = Context.new(mac, hostname, queues)
- sched_client = SchedClient.new
- response = request(context, sched_client, logger)
- return if response.nil?
- # TODO
- # based on response load file
- # TODO
- # generate domain.xml
- # TODO
- # use ruby-libvirt api start a vm
- # clean env
perhaps you should define some interfaces here, these inetfaces can be realize later.
Thanks, Liushaofei
- sched_client.delete_mac2host(mac)
- sched_client.delete_host2queues(hostname)
+end
2.23.0
On Tue, Jan 26, 2021 at 05:51:12PM +0800, Liu Shaofei wrote:
On Tue, Jan 26, 2021 at 04:07:17PM +0800, Xiao Shenwei wrote:
request api: http://$SCHED_HOST:$SCHED_PORT/boot.libvirt/mac/$mac
Signed-off-by: Xiao Shenwei xiaoshenwei96@163.com
providers/libvirt/run.rb | 67 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 providers/libvirt/run.rb
diff --git a/providers/libvirt/run.rb b/providers/libvirt/run.rb new file mode 100755 index 0000000..0ff0d4f --- /dev/null +++ b/providers/libvirt/run.rb @@ -0,0 +1,67 @@ +#!/usr/bin/env ruby +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# frozen_string_literal: true
+require 'json' +require 'digest/md5' +require_relative "#{ENV['CCI_SRC']}/lib/log" +require_relative "#{ENV['CCI_SRC']}/lib/sched_client" +require_relative "#{ENV['CCI_SRC']}/providers/lib/context"
+def create_logger(hostname)
- filename = "#{hostname}.log"
- File.delete(filename) if FileTest.exist?(filename)
- Log.new filename
+end
+def compute_mac(string)
- /(..)(..)(..)(..)(..)/ =~ Digest::MD5.hexdigest(string)
- "0a:#{$1}:#{$2}:#{$3}:#{$4}:#{$5}"
+end
+def nojob?(response)
how about nojob => exist_job ?
job_exist?
- flag = false
- if response['job_id'].empty?
- puts '----------'
- puts 'No job now'
- puts '----------'
- flag = true
- end
- return flag
+end
+def request(context, sched_client, logger)
how about request => request_job ?
ok
- # use ruby-libvirt api start a vm
- # clean env
perhaps you should define some interfaces here, these inetfaces can be realize later.
ok
Thanks, Shenwei
Thanks, Liushaofei
- sched_client.delete_mac2host(mac)
- sched_client.delete_host2queues(hostname)
+end
2.23.0