-
Notifications
You must be signed in to change notification settings - Fork 16
/
golden_image.rb
97 lines (82 loc) · 4.42 KB
/
golden_image.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# (C) Copyright 2017 Hewlett Packard Enterprise Development LP
#
# 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.
require_relative '../../_client_i3s' # Gives access to @client
# Supported APIs:
# - 300, 500, 600
# Resources that can be created according to parameters:
# api_version = 300 & variant = Synergy to OneviewSDK::ImageStreamer::API300::GoldenImage
# api_version = 500 & variant = Synergy to OneviewSDK::ImageStreamer::API500::GoldenImage
# api_version = 600 & variant = Synergy to OneviewSDK::ImageStreamer::API600::GoldenImage
# Example: Create a golden image for an Image Streamer
# NOTE: This will create a golden images named 'Golden_Image_1' and 'Golden_Image_2', and then, it will delete them.
# NOTE: You'll need to add the following instance variables to the _client_i3s.rb file with valid URIs for your environment:
# @golden_image_download_path
# @golden_image_upload_path
# @golden_image_log_path
os_volume_class = OneviewSDK::ImageStreamer.resource_named('OSVolume', @client.api_version)
os_volume = os_volume_class.find_by(@client, {}).first
build_plan_class = OneviewSDK::ImageStreamer.resource_named('BuildPlan', @client.api_version)
build_plan = build_plan_class.find_by(@client, oeBuildPlanType: 'capture').first
golden_image_class = OneviewSDK::ImageStreamer.resource_named('GoldenImage', @client.api_version)
options = {
type: 'GoldenImage',
name: 'Golden_Image_1',
description: 'Any_Description',
imageCapture: true
}
# Creating a golden image
item = golden_image_class.new(@client, options)
item.set_os_volume(os_volume)
item.set_build_plan(build_plan)
puts "\n#Creating a golden image with name #{options[:name]}."
item.create!
item.retrieve!
puts "\n#Golden Image with name #{item['name']} and uri #{item['uri']} created successfully."
# List all golden images
list = golden_image_class.get_all(@client)
puts "\n#Listing all:"
list.each { |p| puts " #{p['name']}" }
id = list.first['uri']
# Gets a golden image by id
puts "\n#Gets a golden image by id #{id}:"
item2 = golden_image_class.find_by(@client, uri: id).first
puts "\n#Golden Image with id #{item2['uri']} was found."
# Gets a golden image by name
puts "\n#Gets a golden image by name #{options[:name]}:"
item3 = golden_image_class.find_by(@client, name: options[:name]).first
puts "\n#Golden Image with name #{item2['name']} was found."
# Updates a golden image
puts "\n#Updating a golden image with id #{item3['uri']} and name #{item3['name']}:"
item3['name'] = 'Golden_Image_Updated'
item3.update
item3.retrieve!
puts "\n#Golden Image updated successfully with id #{item3['uri']} and new name #{item3['name']}."
# Gets details of the golden image capture logs
puts "\nGetting details of the golden image capture logs with id #{item3['uri']} and name #{item3['name']}"
item3.download_details_archive(@golden_image_log_path)
puts "\nDetails of the golden image save successfully."
# Adds a golden image resource from the file that is uploaded from a local drive
puts "\nAdds a golden image resource from the file that is uploaded from a local drive"
options2 = { name: 'Golden_Image_2', description: 'Any_Description' }
puts "\nAdding a golden image with name #{options2[:name]}."
item4 = golden_image_class.add(@client, @golden_image_upload_path, options2)
puts "\nGolden Image with uri #{item4['uri']} and name #{item4['name']} added successfully."
# Downloads the content of the selected golden image
puts "\nDownloads the content of the selected golden image with id #{item3['uri']} and name #{item3['name']}"
item3.download(@golden_image_download_path)
puts "\nDownload done successfully."
# Removes all golden images
puts "\n#Removing a golden image with id #{item3['uri']} and name #{item3['name']}:"
item3.delete
puts "\n#Golden Image with id #{item3['uri']} and name #{item3['name']} was removed successfully."
puts "\n#Removing a golden image with id #{item4['uri']} and name #{item4['name']}:"
item4.delete
puts "\n#Golden Image with id #{item4['uri']} and name #{item4['name']} was removed successfully."