input
stringlengths
109
5.2k
output
stringlengths
7
509
Summarize the following code: def delete(id) id = id.id if id.is_a?(Parse::Pointer) if id.present? && permissions.has_key?(id) will_change! permissions.delete(id) end end
Removes a permission for an objectId or user .
Summarize the following code: def all_read! will_change! permissions.keys.each do |perm| permissions[perm].read! true end end
Grants read permission on all existing users and roles attached to this object .
Summarize the following code: def all_write! will_change! permissions.keys.each do |perm| permissions[perm].write! true end end
Grants write permission on all existing users and roles attached to this object .
Summarize the following code: def no_read! will_change! permissions.keys.each do |perm| permissions[perm].read! false end end
Denies read permission on all existing users and roles attached to this object .
Summarize the following code: def no_write! will_change! permissions.keys.each do |perm| permissions[perm].write! false end end
Denies write permission on all existing users and roles attached to this object .
Summarize the following code: def batch_responses return [@result] unless @batch_response # if batch response, generate array based on the response hash. @result.map do |r| next r unless r.is_a?(Hash) hash = r[SUCCESS] || r[ERROR] Parse::Response.new hash end end
If it is a batch respnose we ll create an array of Response objects for each of the ones in the batch .
Summarize the following code: def parse_result!(h) @result = {} return unless h.is_a?(Hash) @code = h[CODE] @error = h[ERROR] if h[RESULTS].is_a?(Array) @result = h[RESULTS] @count = h[COUNT] || @result.count else @result = h @count = 1 end ...
This method takes the result hash and determines if it is a regular parse query result object result or a count result . The response should be a hash either containing the result data or the error .
Summarize the following code: def link_auth_data!(service_name, **data) response = client.set_service_auth_data(id, service_name, data) raise Parse::Client::ResponseError, response if response.error? apply_attributes!(response.result) end
Adds the third - party authentication data to for a given service .
Summarize the following code: def signup!(passwd = nil) self.password = passwd || password if username.blank? raise Parse::Error::UsernameMissingError, "Signup requires a username." end if password.blank? raise Parse::Error::PasswordMissingError, "Signup requires a password." ...
You may set a password for this user when you are creating them . Parse never returns a
Summarize the following code: def login!(passwd = nil) self.password = passwd || self.password response = client.login(username.to_s, password.to_s) apply_attributes! response.result self.session_token.present? end
Login and get a session token for this user .
Summarize the following code: def logout return true if self.session_token.blank? client.logout session_token self.session_token = nil true rescue => e false end
Invalid the current session token for this logged in user .
Summarize the following code: def first_or_create(query_attrs = {}, resource_attrs = {}) conditions(query_attrs) klass = Parse::Model.find_class self.table if klass.blank? raise ArgumentError, "Parse model with class name #{self.table} is not registered." end hash_constraints = con...
Supporting the first_or_create class method to be used in scope chaining with queries .
Summarize the following code: def save_all(expressions = {}) conditions(expressions) klass = Parse::Model.find_class self.table if klass.blank? raise ArgumentError, "Parse model with class name #{self.table} is not registered." end hash_constraints = constraints(true) klass....
Supporting the save_all method to be used in scope chaining with queries .
Summarize the following code: def add(font) if font.instance_of?(Font) @fonts.push(font) if @fonts.index(font).nil? end self end
This method adds a font to a FontTable instance . This method returns a reference to the FontTable object updated .
Summarize the following code: def to_rtf(indent=0) prefix = indent > 0 ? ' ' * indent : '' text = StringIO.new text << "#{prefix}{\\fonttbl" @fonts.each_index do |index| text << "\n#{prefix}{\\f#{index}#{@fonts[index].to_rtf}}" end text << "\n#{...
This method generates the RTF text for a FontTable object .
Summarize the following code: def previous_node peer = nil if !parent.nil? and parent.respond_to?(:children) index = parent.children.index(self) peer = index > 0 ? parent.children[index - 1] : nil end peer end
Constructor for the Node class .
Summarize the following code: def next_node peer = nil if !parent.nil? and parent.respond_to?(:children) index = parent.children.index(self) peer = parent.children[index + 1] end peer end
This method retrieves a Node objects next peer node returning nil if the Node has no previous peer .
Summarize the following code: def insert(text, offset) if !@text.nil? @text = @text[0, offset] + text.to_s + @text[offset, @text.length] else @text = text.to_s end end
This method inserts a String into the existing text within a TextNode object . If the TextNode contains no text then it is simply set to the text passed in . If the offset specified is past the end of the nodes text then it is simply appended to the end .
Summarize the following code: def to_rtf rtf=(@text.nil? ? '' : @text.gsub("{", "\\{").gsub("}", "\\}").gsub("\\", "\\\\")) # This is from lfarcy / rtf-extensions # I don't see the point of coding different 128<n<256 range #f1=lambda { |n| n < 128 ? n.chr : n < 256 ? "\\'#{n.to_s(16)}" ...
This method generates the RTF equivalent for a TextNode object . This method escapes any special sequences that appear in the text .
Summarize the following code: def store(node) if !node.nil? @children.push(node) if !@children.include?(Node) node.parent = self if node.parent != self end node end
This is the constructor for the ContainerNode class .
Summarize the following code: def <<(text) if !last.nil? and last.respond_to?(:text=) last.append(text) else self.store(TextNode.new(self, text)) end end
This is the constructor for the CommandNode class .
Summarize the following code: def to_rtf text = StringIO.new text << '{' if wrap? text << @prefix if @prefix self.each do |entry| text << "\n" if split? text << entry.to_rtf end text << "\n" if split? text << @suffix if...
This method generates the RTF text for a CommandNode object .
Summarize the following code: def paragraph(style=nil) node = ParagraphNode.new(self, style) yield node if block_given? self.store(node) end
This method provides a short cut means of creating a paragraph command node . The method accepts a block that will be passed a single parameter which will be a reference to the paragraph node created . After the block is complete the paragraph node is appended to the end of the child nodes on the object that the method...
Summarize the following code: def list(kind=:bullets) node = ListNode.new(self) yield node.list(kind) self.store(node) end
This method provides a short cut means of creating a new ordered or unordered list . The method requires a block that will be passed a single parameter that ll be a reference to the first level of the list . See the + ListLevelNode + doc for more information .
Summarize the following code: def footnote(text) if !text.nil? and text != '' mark = CommandNode.new(self, '\fs16\up6\chftn', nil, false) note = CommandNode.new(self, '\footnote {\fs16\up6\chftn}', nil, false) note.paragraph << text self.store(mark) s...
This method inserts a footnote at the current position in a node .
Summarize the following code: def apply(style) # Check the input style. if !style.is_character_style? RTFError.fire("Non-character style specified to the "\ "CommandNode#apply() method.") end # Store fonts and colours. root.colours << s...
This method provides a short cut means for applying multiple styles via single command node . The method accepts a block that will be passed a reference to the node created . Once the block is complete the new node will be append as the last child of the CommandNode the method is called on .
Summarize the following code: def bold style = CharacterStyle.new style.bold = true if block_given? apply(style) {|node| yield node} else apply(style) end end
This method provides a short cut means of creating a bold command node . The method accepts a block that will be passed a single parameter which will be a reference to the bold node created . After the block is complete the bold node is appended to the end of the child nodes on the object that the method is call agains...
Summarize the following code: def italic style = CharacterStyle.new style.italic = true if block_given? apply(style) {|node| yield node} else apply(style) end end
This method provides a short cut means of creating an italic command node . The method accepts a block that will be passed a single parameter which will be a reference to the italic node created . After the block is complete the italic node is appended to the end of the child nodes on the object that the method is call...
Summarize the following code: def underline style = CharacterStyle.new style.underline = true if block_given? apply(style) {|node| yield node} else apply(style) end end
This method provides a short cut means of creating an underline command node . The method accepts a block that will be passed a single parameter which will be a reference to the underline node created . After the block is complete the underline node is appended to the end of the child nodes on the object that the metho...
Summarize the following code: def subscript style = CharacterStyle.new style.subscript = true if block_given? apply(style) {|node| yield node} else apply(style) end end
This method provides a short cut means of creating a subscript command node . The method accepts a block that will be passed a single parameter which will be a reference to the subscript node created . After the block is complete the subscript node is appended to the end of the child nodes on the object that the method...
Summarize the following code: def superscript style = CharacterStyle.new style.superscript = true if block_given? apply(style) {|node| yield node} else apply(style) end end
This method provides a short cut means of creating a superscript command node . The method accepts a block that will be passed a single parameter which will be a reference to the superscript node created . After the block is complete the superscript node is appended to the end of the child nodes on the object that the ...
Summarize the following code: def strike style = CharacterStyle.new style.strike = true if block_given? apply(style) {|node| yield node} else apply(style) end end
This method provides a short cut means of creating a strike command node . The method accepts a block that will be passed a single parameter which will be a reference to the strike node created . After the block is complete the strike node is appended to the end of the child nodes on the object that the method is call ...
Summarize the following code: def font(font, size=nil) style = CharacterStyle.new style.font = font style.font_size = size root.fonts << font if block_given? apply(style) {|node| yield node} else apply(style) end ...
This method provides a short cut means of creating a font command node . The method accepts a block that will be passed a single parameter which will be a reference to the font node created . After the block is complete the font node is appended to the end of the child nodes on the object that the method is called agai...
Summarize the following code: def foreground(colour) style = CharacterStyle.new style.foreground = colour root.colours << colour if block_given? apply(style) {|node| yield node} else apply(style) end end
This method provides a short cut means of creating a foreground colour command node . The method accepts a block that will be passed a single parameter which will be a reference to the foreground colour node created . After the block is complete the foreground colour node is appended to the end of the child nodes on th...
Summarize the following code: def colour(fore, back) style = CharacterStyle.new style.foreground = fore style.background = back root.colours << fore root.colours << back if block_given? apply(style) {|node| yield node} else ...
This method provides a short cut menas of creating a colour node that deals with foreground and background colours . The method accepts a block that will be passed a single parameter which will be a reference to the colour node created . After the block is complete the colour node is append to the end of the child node...
Summarize the following code: def table(rows, columns, *widths) node = TableNode.new(self, rows, columns, *widths) yield node if block_given? store(node) node end
This method creates a new table node and returns it . The method accepts a block that will be passed the table as a parameter . The node is added to the node the method is called upon after the block is complete .
Summarize the following code: def list(kind=@kind) node = ListLevelNode.new(self, @template, kind, @level.level+1) yield node self.store(node) end
Creates a new + ListLevelNode + to implement nested lists
Summarize the following code: def column_shading_colour(index, colour) self.each do |row| cell = row[index] cell.shading_colour = colour if cell != nil end end
This method assigns a shading colour to a specified column within a TableNode object .
Summarize the following code: def shading_colour(colour) if block_given? 0.upto(self.size - 1) do |x| row = self[x] 0.upto(row.size - 1) do |y| apply = yield row[y], x, y row[y].shading_colour = colour if apply end ...
This method provides a means of assigning a shading colour to a selection of cells within a table . The method accepts a block that takes three parameters - a TableCellNode representing a cell within the table an integer representing the x offset of the cell and an integer representing the y offset of the cell . If the...
Summarize the following code: def to_rtf text = StringIO.new temp = StringIO.new offset = 0 text << "\\trowd\\tgraph#{parent.cell_margin}" self.each do |entry| widths = entry.border_widths colour = entry.shading_colour text << "\n" ...
This method overloads the store method inherited from the ContainerNode class to forbid addition of further nodes .
Summarize the following code: def border_width=(width) size = width.nil? ? 0 : width if size > 0 @borders[TOP] = @borders[RIGHT] = @borders[BOTTOM] = @borders[LEFT] = size.to_i else @borders = [nil, nil, nil, nil] end end
This method assigns a width in twips for the borders on all sides of the cell . Negative widths will be ignored and a width of zero will switch the border off .
Summarize the following code: def top_border_width=(width) size = width.nil? ? 0 : width if size > 0 @borders[TOP] = size.to_i else @borders[TOP] = nil end end
This method assigns a border width to the top side of a table cell . Negative values are ignored and a value of 0 switches the border off .
Summarize the following code: def right_border_width=(width) size = width.nil? ? 0 : width if size > 0 @borders[RIGHT] = size.to_i else @borders[RIGHT] = nil end end
This method assigns a border width to the right side of a table cell . Negative values are ignored and a value of 0 switches the border off .
Summarize the following code: def bottom_border_width=(width) size = width.nil? ? 0 : width if size > 0 @borders[BOTTOM] = size.to_i else @borders[BOTTOM] = nil end end
This method assigns a border width to the bottom side of a table cell . Negative values are ignored and a value of 0 switches the border off .
Summarize the following code: def left_border_width=(width) size = width.nil? ? 0 : width if size > 0 @borders[LEFT] = size.to_i else @borders[LEFT] = nil end end
This method assigns a border width to the left side of a table cell . Negative values are ignored and a value of 0 switches the border off .
Summarize the following code: def border_widths widths = [] @borders.each {|entry| widths.push(entry.nil? ? 0 : entry)} widths end
This method retrieves an array with the cell border width settings . The values are inserted in top right bottom left order .
Summarize the following code: def get_file_type type = nil read = [] open_file do |file| # Check if the file is a JPEG. read_source(file, read, 2) if read[0,2] == [255, 216] type = JPEG else # Check if it's a PNG. ...
This method attempts to determine the image type associated with a file returning nil if it fails to make the determination .
Summarize the following code: def to_rtf text = StringIO.new count = 0 #text << '{\pard{\*\shppict{\pict' text << '{\*\shppict{\pict' text << "\\picscalex#{@x_scaling}" if @x_scaling != nil text << "\\picscaley#{@y_scaling}" if @y_scaling != nil text << "\\pic...
This method generates the RTF for an ImageNode object .
Summarize the following code: def to_integer(array, signed=false) from = nil to = nil data = [] if array.size == 2 data.concat(get_endian == BIG_ENDIAN ? array.reverse : array) from = 'C2' to = signed ? 's' : 'S' else data...
This method converts an array to an integer . The array must be either two or four bytes in length .
Summarize the following code: def read_source(file, read, size=nil) if block_given? done = false while !done and !file.eof? read << file.getbyte done = yield read[-1] end else if size != nil if size > 0 ...
This method loads the data for an image from its source . The method accepts two call approaches . If called without a block then the method considers the size parameter it is passed . If called with a block the method executes until the block returns true .
Summarize the following code: def get_dimensions dimensions = nil open_file do |file| file.pos = DIMENSIONS_OFFSET[@type] read = [] # Check the image type. if @type == JPEG # Read until we can't anymore or we've found what we're looking for. ...
This method fetches details of the dimensions associated with an image .
Summarize the following code: def header=(header) if header.type == HeaderNode::UNIVERSAL @headers[0] = header elsif header.type == HeaderNode::LEFT_PAGE @headers[1] = header elsif header.type == HeaderNode::RIGHT_PAGE @headers[2] = header elsif he...
This method assigns a new header to a document . A Document object can have up to four header - a default header a header for left pages a header for right pages and a header for the first page . The method checks the header type and stores it appropriately .
Summarize the following code: def footer=(footer) if footer.type == FooterNode::UNIVERSAL @footers[0] = footer elsif footer.type == FooterNode::LEFT_PAGE @footers[1] = footer elsif footer.type == FooterNode::RIGHT_PAGE @footers[2] = footer elsif fo...
This method assigns a new footer to a document . A Document object can have up to four footers - a default footer a footer for left pages a footer for right pages and a footer for the first page . The method checks the footer type and stores it appropriately .
Summarize the following code: def header(type=HeaderNode::UNIVERSAL) index = 0 if type == HeaderNode::LEFT_PAGE index = 1 elsif type == HeaderNode::RIGHT_PAGE index = 2 elsif type == HeaderNode::FIRST_PAGE index = 3 end @headers[i...
This method fetches a header from a Document object .
Summarize the following code: def footer(type=FooterNode::UNIVERSAL) index = 0 if type == FooterNode::LEFT_PAGE index = 1 elsif type == FooterNode::RIGHT_PAGE index = 2 elsif type == FooterNode::FIRST_PAGE index = 3 end @footers[i...
This method fetches a footer from a Document object .
Summarize the following code: def to_rtf text = StringIO.new text << "{#{prefix}\\#{@character_set.id2name}" text << "\\deff#{@default_font}" text << "\\deflang#{@language}" if !@language.nil? text << "\\plain\\fs24\\fet1" text << "\n#{@fonts.to_rtf}" text...
This method generates the RTF text for a Document object .
Summarize the following code: def add(colour) if colour.instance_of?(Colour) @colours.push(colour) if @colours.index(colour).nil? end self end
This method adds a new colour to a ColourTable object . If the colour already exists within the table or is not a Colour object then this method does nothing .
Summarize the following code: def to_s(indent=0) prefix = indent > 0 ? ' ' * indent : '' text = StringIO.new text << "#{prefix}Colour Table (#{@colours.size} colours)" @colours.each {|colour| text << "\n#{prefix} #{colour}"} text.string end
This method generates a textual description for a ColourTable object .
Summarize the following code: def created=(setting) if setting.instance_of?(Time) @created = setting else datetime = Date._parse(setting.to_s).values_at(:year, :mon, :mday, :hour, :min, :sec, :zone, :wday) if datetime == nil RTFError.fire("Invali...
This is the constructor for the Information class .
Summarize the following code: def to_s(indent=0) prefix = indent > 0 ? ' ' * indent : '' text = StringIO.new text << "#{prefix}Information" text << "\n#{prefix} Title: #{@title}" unless @title.nil? text << "\n#{prefix} Author: #{@author}" unless @autho...
This method creates a textual description for an Information object .
Summarize the following code: def to_rtf(indent=0) prefix = indent > 0 ? ' ' * indent : '' text = StringIO.new text << "#{prefix}{\\info" text << "\n#{prefix}{\\title #{@title}}" unless @title.nil? text << "\n#{prefix}{\\author #{@author}}" unless @author....
This method generates the RTF text for an Information object .
Summarize the following code: def process_request(data, client) validated = @validated.include?(client) parser = @validating[client.object_id] if validated parser.process data else result = parser.signal(data) case result ...
The server processes requests here
Summarize the following code: def log(error, context, trace = nil) msg = String.new if error.respond_to?(:backtrace) msg << "unhandled exception: #{error.message} (#{context})" backtrace = error.backtrace msg << "\n#{backtrace.join("\n")}" if backt...
This is an unhandled error on the Libuv Event loop
Summarize the following code: def ready load_promise = load_applications load_promise.then do # Check a shutdown request didn't occur as we were loading if @running @logger.verbose "All gazelles running" # This happends on ...
Load gazelles and make the required bindings
Summarize the following code: def enumerate(vendor_id = 0, product_id = 0, options = {}) raise HIDAPI::HidApiError, 'not initialized' unless @context if vendor_id.is_a?(Hash) || (vendor_id.is_a?(String) && options.empty?) options = vendor_id vendor_id = 0 product_id = 0 end ...
Creates a new engine .
Summarize the following code: def get_device(vendor_id, product_id, serial_number = nil, options = {}) raise ArgumentError, 'vendor_id must be provided' if vendor_id.to_i == 0 raise ArgumentError, 'product_id must be provided' if product_id.to_i == 0 if serial_number.is_a?(Hash) options = ser...
Gets the first device with the specified vendor_id product_id and optionally serial_number .
Summarize the following code: def open(vendor_id, product_id, serial_number = nil, options = {}) dev = get_device(vendor_id, product_id, serial_number, options) dev.open if dev end
Opens the first device with the specified vendor_id product_id and optionally serial_number .
Summarize the following code: def get_device_by_path(path, options = {}) # Our linux setup routine creates convenient /dev/hidapi/* links. # If the user wants to open one of those, we can simple parse the link to generate # the path that the library expects. if File.exist?(path) hidapi...
Gets the device with the specified path .
Summarize the following code: def open_path(path, options = {}) dev = get_device_by_path(path, options) dev.open if dev end
Opens the device with the specified path .
Summarize the following code: def usb_code_for_current_locale @usb_code_for_current_locale ||= begin locale = I18n.locale if locale locale = locale.to_s.partition('.')[0] # remove encoding result = HIDAPI::Language.get_by_code(locale) un...
Gets the USB code for the current locale .
Summarize the following code: def open if open? self.open_count += 1 if open_count < 1 HIDAPI.debug "open_count for open device #{path} is #{open_count}" self.open_count = 1 end return self end self.open_count = 0 begin self.handle = us...
Opens the device .
Summarize the following code: def read_timeout(milliseconds) raise DeviceNotOpen unless open? mutex.synchronize do if input_reports.count > 0 data = input_reports.delete_at(0) HIDAPI.debug "read data from device #{path}: #{data.inspect}" return data end ...
Attempts to read from the device waiting up to + milliseconds + before returning .
Summarize the following code: def send_feature_report(data) raise ArgumentError, 'data must not be blank' if data.nil? || data.length < 1 raise HIDAPI::DeviceNotOpen unless open? data, report_number, skipped_report_id = clean_output_data(data) mutex.synchronize do handle.control_transf...
Sends a feature report to the device .
Summarize the following code: def get_feature_report(report_number, buffer_size = nil) buffer_size ||= input_ep_max_packet_size mutex.synchronize do handle.control_transfer( bmRequestType: LIBUSB::REQUEST_TYPE_CLASS | LIBUSB::RECIPIENT_INTERFACE | LIBUSB::ENDPOINT_IN, bRequ...
Gets a feature report from the device .
Summarize the following code: def read_string(index, on_failure = '') begin # does not require an interface, so open from the usb_dev instead of using our open method. data = mutex.synchronize do if open? handle.string_descriptor_ascii(index) else usb_de...
Reads a string descriptor from the USB device .
Summarize the following code: def delta(other_audit) return self.change_log if other_audit.nil? {}.tap do |d| # first for keys present only in this audit (self.change_log.keys - other_audit.change_log.keys).each do |k| d[k] = [nil, self.change_log[k]] end...
Computes the differences of the change logs between two audits .
Summarize the following code: def render_audits(audited_model) return '' unless audited_model.respond_to?(:audits) audits = (audited_model.audits || []).dup.sort{|a,b| b.created_at <=> a.created_at} res = '' audits.each_with_index do |audit, index| older_audit = audits[index + 1] ...
Render the change log for the given audited model
Summarize the following code: def _output_paths(file) input_file_dir = File.dirname(file) file_name = _output_filename(file) file_name = "#{file_name}.html" if _append_html_ext_to_output_path?(file_name) input_file_dir = input_file_dir.gsub(Regexp.new("#{options[:input]}(\/){0,1}"), '') if optio...
Get the file path to output the html based on the file being built . The output path is relative to where guard is being run .
Summarize the following code: def _output_filename(file) sub_strings = File.basename(file).split('.') base_name, extensions = sub_strings.first, sub_strings[1..-1] if extensions.last == 'haml' extensions.pop if extensions.empty? [base_name, options[:default_ext]].j...
Generate a file name based on the provided file path . Provide a logical extension .
Summarize the following code: def get_vapp_by_name(organization, vdcName, vAppName) result = nil get_vdc_by_name(organization, vdcName)[:vapps].each do |vapp| if vapp[0].downcase == vAppName.downcase result = get_vapp(vapp[1]) end end result end
Friendly helper method to fetch a vApp by name - Organization object - Organization VDC Name - vApp name
Summarize the following code: def poweroff_vapp(vAppId) builder = Nokogiri::XML::Builder.new do |xml| xml.UndeployVAppParams( "xmlns" => "http://www.vmware.com/vcloud/v1.5") { xml.UndeployPowerAction 'powerOff' } end params = { 'method' => :post, 'command' ...
Shutdown a given vapp
Summarize the following code: def create_vapp_from_template(vdc, vapp_name, vapp_description, vapp_templateid, poweron=false) builder = Nokogiri::XML::Builder.new do |xml| xml.InstantiateVAppTemplateParams( "xmlns" => "http://www.vmware.com/vcloud/v1.5", "xmlns:xsi" => "http://www.w3.org/200...
Create a vapp starting from a template
Summarize the following code: def compose_vapp_from_vm(vdc, vapp_name, vapp_description, vm_list={}, network_config={}) builder = Nokogiri::XML::Builder.new do |xml| xml.ComposeVAppParams( "xmlns" => "http://www.vmware.com/vcloud/v1.5", "xmlns:ovf" => "http://schemas.dmtf.org/ovf/envelope/1"...
Compose a vapp using existing virtual machines
Summarize the following code: def add_vm_to_vapp(vapp, vm, network_config={}) builder = Nokogiri::XML::Builder.new do |xml| xml.RecomposeVAppParams( "xmlns" => "http://www.vmware.com/vcloud/v1.5", "xmlns:ovf" => "http://schemas.dmtf.org/ovf/envelope/1", "name" => vapp[:name])...
Create a new virtual machine from a template in an existing vApp .
Summarize the following code: def clone_vapp(vdc_id, source_vapp_id, name, deploy="true", poweron="false", linked="false", delete_source="false") params = { "method" => :post, "command" => "/vdc/#{vdc_id}/action/cloneVApp" } builder = Nokogiri::XML::Builder.new do |xml| xml...
Clone a vapp in a given VDC to a new Vapp
Summarize the following code: def set_vapp_network_config(vappid, network, config={}) params = { 'method' => :get, 'command' => "/vApp/vapp-#{vappid}/networkConfigSection" } netconfig_response, headers = send_request(params) picked_network = netconfig_response.css("NetworkConfi...
Set vApp Network Config
Summarize the following code: def set_vapp_port_forwarding_rules(vappid, network_name, config={}) builder = Nokogiri::XML::Builder.new do |xml| xml.NetworkConfigSection( "xmlns" => "http://www.vmware.com/vcloud/v1.5", "xmlns:ovf" => "http://schemas.dmtf.org/ovf/envelope/1") { xml['ov...
Set vApp port forwarding rules
Summarize the following code: def get_vapp_port_forwarding_rules(vAppId) params = { 'method' => :get, 'command' => "/vApp/vapp-#{vAppId}/networkConfigSection" } response, headers = send_request(params) # FIXME: this will return nil if the vApp uses multiple vApp Networks ...
Get vApp port forwarding rules
Summarize the following code: def merge_network_config(vapp_networks, new_network, config) net_configuration = new_network.css('Configuration').first fence_mode = new_network.css('FenceMode').first fence_mode.content = config[:fence_mode] || 'isolated' network_features = Nokogiri::XML:...
Merge the Configuration section of a new network and add specific configuration
Summarize the following code: def add_network_to_vapp(vAppId, network_section) params = { 'method' => :put, 'command' => "/vApp/vapp-#{vAppId}/networkConfigSection" } response, headers = send_request(params, network_section, "application/vnd.vmware.vcloud.networkConfigSectio...
Add a new network to a vApp
Summarize the following code: def create_fake_network_node(vapp_networks, network_name) parent_section = vapp_networks.css('NetworkConfigSection').first new_network = Nokogiri::XML::Node.new "NetworkConfig", parent_section new_network['networkName'] = network_name placeholder = Nokogiri:...
Create a fake NetworkConfig node whose content will be replaced later
Summarize the following code: def create_internal_network_node(network_config) builder = Nokogiri::XML::Builder.new do |xml| xml.Configuration { xml.IpScopes { xml.IpScope { xml.IsInherited(network_config[:is_inherited] || "false") xml.Gateway ...
Create a fake Configuration node for internal networking
Summarize the following code: def generate_network_section(vAppId, network, config, type) params = { 'method' => :get, 'command' => "/vApp/vapp-#{vAppId}/networkConfigSection" } vapp_networks, headers = send_request(params) create_fake_network_node(vapp_networks, net...
Create a NetworkConfigSection for a new internal or external network
Summarize the following code: def login params = { 'method' => :post, 'command' => '/sessions' } response, headers = send_request(params) if !headers.has_key?(:x_vcloud_authorization) raise "Unable to authenticate: missing x_vcloud_authorization header" end ...
Authenticate against the specified server
Summarize the following code: def get_task(taskid) params = { 'method' => :get, 'command' => "/task/#{taskid}" } response, headers = send_request(params) task = response.css('Task').first status = task['status'] start_time = task['startTime'] end_time = task['...
Fetch information for a given task
Summarize the following code: def wait_task_completion(taskid) errormsg = nil task = {} loop do task = get_task(taskid) break if task[:status] != 'running' sleep 1 end if task[:status] == 'error' errormsg = task[:response].css("Error").first errorm...
Poll a given task until completion
Summarize the following code: def send_request(params, payload=nil, content_type=nil) req_params = setup_request(params, payload, content_type) handled_request(req_params) do request = RestClient::Request.new(req_params) response = request.execute if ![200, 201, 202, 204]...
Sends a synchronous request to the vCloud API and returns the response as parsed XML + headers .
Summarize the following code: def upload_file(uploadURL, uploadFile, progressUrl, config={}) raise ::IOError, "#{uploadFile} not found." unless File.exists?(uploadFile) # Set chunksize to 10M if not specified otherwise chunkSize = (config[:chunksize] || 10485760) # Set progress bar to ...
Upload a large file in configurable chunks output an optional progressbar
Summarize the following code: def get_catalog(catalogId) params = { 'method' => :get, 'command' => "/catalog/#{catalogId}" } response, headers = send_request(params) description = response.css("Description").first description = description.text unless description.nil? ...
Fetch details about a given catalog
Summarize the following code: def get_vm_disk_info(vmid) response, headers = __get_disk_info(vmid) disks = [] response.css("Item").each do |entry| # Pick only entries with node "HostResource" resource = entry.css("rasd|HostResource").first next unless resource name = ...
Retrieve information about Disks