-
Notifications
You must be signed in to change notification settings - Fork 452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[OHAI-458] Include Joyent SmartOS specific attributes in Ohai #133
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
7336194
[OHAI-458] Include Joyent SmartOS specific attributes in Ohai
sawanoboly 3581232
change license mit to apache2
sawanoboly b55bbc4
Merge branch 'master' into OHAI-458
sawanoboly c52ea8e
update syntax from ohai6 to ohai7
sawanoboly 9f9c9ca
fill provides
sawanoboly 04bc046
define method for collect product information
sawanoboly d3818aa
new method collect pkgsrc for test
sawanoboly 744ba09
update method collect pkgsrc for test
sawanoboly 96176c0
update spec for plugin/joyent
sawanoboly ab35c8b
remove comment from spec
sawanoboly 0f8b84b
move .collect_guest_id from joyent to solaris2/virtualization
sawanoboly 9a7de5a
Merge branch 'OHAI-458' of github.com:ZCloud-Firstserver/ohai into OH…
sawanoboly 8d557b5
update spec
sawanoboly db924e6
Merge branch 'master' into OHAI-458
sawanoboly 6905611
updates by reviwes.
sawanoboly File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# | ||
# Author: sawanoboriyu@higanworks.com | ||
# Copyright (C) 2014 HiganWorks LLC | ||
# License:: Apache License, Version 2.0 | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# | ||
|
||
# Reference from: sm-summary command | ||
|
||
Ohai.plugin(:Joyent) do | ||
provides 'joyent' | ||
provides 'virtualization/guest_id' | ||
depends 'os', 'platform', 'virtualization' | ||
|
||
def collect_product_file | ||
lines = [] | ||
if ::File.exists?("/etc/product") | ||
::File.open("/etc/product") do |file| | ||
while line = file.gets | ||
lines << line | ||
end | ||
end | ||
end | ||
lines | ||
end | ||
|
||
def collect_pkgsrc | ||
if File.exist?('/opt/local/etc/pkg_install.conf') | ||
sm_pkgsrc = ::File.read("/opt/local/etc/pkg_install.conf").split("=") | ||
sm_pkgsrc[1].chomp | ||
else | ||
nil | ||
end | ||
end | ||
|
||
def is_smartos? | ||
platform == 'smartos' | ||
end | ||
|
||
collect_data do | ||
if is_smartos? | ||
joyent Mash.new | ||
|
||
# copy uuid | ||
joyent[:sm_uuid] = virtualization[:guest_uuid] | ||
|
||
# get zone id unless globalzone | ||
unless joyent[:sm_uuid] == "global" | ||
joyent[:sm_id] = virtualization[:guest_id] | ||
end | ||
|
||
# retrieve image name and pkgsrc | ||
collect_product_file.each do |line| | ||
case line | ||
when /^Image/ | ||
sm_image = line.split(" ") | ||
joyent[:sm_image_id] = sm_image[1] | ||
joyent[:sm_image_ver] = sm_image[2] | ||
when /^Base Image/ | ||
sm_baseimage = line.split(" ") | ||
joyent[:sm_baseimage_id] = sm_baseimage[2] | ||
joyent[:sm_baseimage_ver] = sm_baseimage[3] | ||
end | ||
end | ||
|
||
## retrieve pkgsrc | ||
joyent[:sm_pkgsrc] = collect_pkgsrc if collect_pkgsrc | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
require 'spec_helper' | ||
|
||
|
||
describe Ohai::System, "plugin joyent" do | ||
before(:each) do | ||
@plugin = get_plugin('joyent') | ||
end | ||
|
||
describe "without joyent" do | ||
before(:each) do | ||
@plugin.stub(:is_smartos?).and_return(false) | ||
end | ||
|
||
it "should NOT create joyent" do | ||
@plugin.run | ||
@plugin[:joyent].should be_nil | ||
end | ||
end | ||
|
||
describe "with joyent" do | ||
before(:each) do | ||
@plugin.stub(:is_smartos?).and_return(true) | ||
@plugin[:virtualization] = Mash.new | ||
@plugin[:virtualization][:guest_uuid] = "global" | ||
end | ||
|
||
it "should create joyent" do | ||
@plugin.run | ||
@plugin[:joyent].should_not be_nil | ||
end | ||
|
||
describe "under global zone" do | ||
before(:each) do | ||
@plugin.run | ||
end | ||
|
||
it "should ditect global zone" do | ||
@plugin[:joyent][:sm_uuid].should eql 'global' | ||
end | ||
|
||
it "should NOT create sm_id" do | ||
@plugin[:joyent][:sm_id].should be_nil | ||
end | ||
end | ||
|
||
describe "under smartmachine" do | ||
before(:each) do | ||
@plugin[:virtualization][:guest_uuid] = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx' | ||
@plugin[:virtualization][:guest_id] = '30' | ||
@plugin.stub(:collect_product_file).and_return(["Name: Joyent Instance", "Image: base64 13.4.2", "Documentation: http://wiki.joyent.com/jpc2/SmartMachine+Base"]) | ||
@plugin.stub(:collect_pkgsrc).and_return('http://pkgsrc.joyent.com/packages/SmartOS/2013Q4/x86_64/All') | ||
@plugin.run | ||
end | ||
|
||
it "should retrive zone uuid" do | ||
@plugin[:joyent][:sm_uuid].should eql 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx' | ||
end | ||
|
||
it "should collect sm_id" do | ||
@plugin[:joyent][:sm_id].should eql '30' | ||
end | ||
|
||
it "should collect images" do | ||
@plugin[:joyent][:sm_image_id].should_not be_nil | ||
@plugin[:joyent][:sm_image_ver].should_not be_nil | ||
end | ||
|
||
it "should collect pkgsrc" do | ||
@plugin[:joyent][:sm_pkgsrc].should eql 'http://pkgsrc.joyent.com/packages/SmartOS/2013Q4/x86_64/All' | ||
end | ||
end | ||
end | ||
end | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not personally familiar with SmartOS, but if
::RbConfig::CONFIG['host_os']
matches SmartOS you can add a line that determines that here (https://github.com/opscode/ohai/blob/master/lib%2Fohai%2Fmixin%2Fos.rb#L26) and then writecollect_data(:smartos) do
instead of wrapping the code in an if-statement.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for tell me usage for collect_data!
But
::RbConfig::CONFIG['host_os']
returnssolaris2.11
on smartos.