Class: MrMurano::Product
- Inherits:
-
ProductBase
- Object
- ProductBase
- MrMurano::Product
- Defined in:
- lib/MrMurano/Product.rb
Instance Method Summary collapse
-
#convert(specFile) ⇒ Object
Converts an exoline style spec file into a Murano style one.
-
#convertit(fin) ⇒ Object
Converts an exoline style spec file into a Murano style one.
-
#enable(sn) ⇒ Object
Enable a serial number This creates the device and opens the activation window.
-
#info ⇒ Object
Get info about the product.
-
#list(offset = 0, limit = 50) ⇒ Object
List enabled devices.
-
#update(specFile) ⇒ Object
Upload a spec file.
-
#write(sn, values) ⇒ Object
Write a value to an alias on a device.
Methods inherited from ProductBase
Methods included from Verbose
#debug, #error, #outf, #tabularize, #verbose, #warning
Methods included from Http
#curldebug, #delete, #get, #http, #http_reset, #isJSON, #json_opts, #post, #postf, #put, #set_def_headers, #showHttpError, #token, #workit
Constructor Details
This class inherits a constructor from MrMurano::ProductBase
Instance Method Details
#convert(specFile) ⇒ Object
Converts an exoline style spec file into a Murano style one
139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/MrMurano/Product.rb', line 139 def convert(specFile) if specFile == '-' then convertit($stdin).to_yaml else specFile = Pathname.new(specFile) unless specFile.kind_of? Pathname out = '' specFile.open() do |fin| out = convertit(fin).to_yaml end out end end |
#convertit(fin) ⇒ Object
Converts an exoline style spec file into a Murano style one
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/MrMurano/Product.rb', line 120 def convertit(fin) specOut = {'resources'=>[]} spec = YAML.load(fin) if spec.has_key?('dataports') and spec['dataports'].kind_of?(Array) then dps = spec['dataports'].map do |dp| dp.delete_if{|k,v| k != 'alias' and k != 'format' and k != 'initial'} dp['format'] = 'string' if (dp['format']||'')[0..5] == 'string' dp end specOut['resources'] = dps else raise "No dataports section found, or not an array" end specOut end |
#enable(sn) ⇒ Object
Enable a serial number This creates the device and opens the activation window.
88 89 90 |
# File 'lib/MrMurano/Product.rb', line 88 def enable(sn) post("/device/#{sn.to_s}") end |
#info ⇒ Object
Get info about the product
77 78 79 |
# File 'lib/MrMurano/Product.rb', line 77 def info get('/info') end |
#list(offset = 0, limit = 50) ⇒ Object
List enabled devices
82 83 84 |
# File 'lib/MrMurano/Product.rb', line 82 def list(offset=0, limit=50) get("/device/?offset=#{offset}&limit=#{limit}") end |
#update(specFile) ⇒ Object
Upload a spec file.
Note that this will fail if any of the resources already exist.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/MrMurano/Product.rb', line 95 def update(specFile) specFile = Pathname.new(specFile) unless specFile.kind_of? Pathname uri = endPoint('/definition') request = Net::HTTP::Post.new(uri) ret = nil specFile.open do |io| request.body_stream = io request.content_length = specFile.size set_def_headers(request) request.content_type = 'text/yaml' ret = workit(request) end ret end |
#write(sn, values) ⇒ Object
Write a value to an alias on a device
113 114 115 |
# File 'lib/MrMurano/Product.rb', line 113 def write(sn, values) post("/write/#{sn}", values) unless $cfg['tool.dry'] end |