pax_global_header00006660000000000000000000000064151026117050014510gustar00rootroot0000000000000052 comment=a8387295333f8bef463e5a5d8a7a9bda97d94294 fog-libvirt-0.14.0/000077500000000000000000000000001510261170500140165ustar00rootroot00000000000000fog-libvirt-0.14.0/.document000066400000000000000000000000341510261170500156320ustar00rootroot00000000000000README.md lib/**/*.rb bin/* fog-libvirt-0.14.0/.github/000077500000000000000000000000001510261170500153565ustar00rootroot00000000000000fog-libvirt-0.14.0/.github/dependabot.yml000066400000000000000000000003171510261170500202070ustar00rootroot00000000000000version: 2 updates: - package-ecosystem: "bundler" directory: "/" schedule: interval: "daily" - package-ecosystem: "github-actions" directory: "/" schedule: interval: "daily" fog-libvirt-0.14.0/.github/workflows/000077500000000000000000000000001510261170500174135ustar00rootroot00000000000000fog-libvirt-0.14.0/.github/workflows/rubocop.yml000066400000000000000000000007101510261170500216050ustar00rootroot00000000000000name: reviewdog on: [pull_request] jobs: rubocop: name: runner / rubocop runs-on: ubuntu-latest steps: - name: Check out code uses: actions/checkout@v5 - uses: ruby/setup-ruby@v1 with: ruby-version: 3.3 - name: rubocop uses: reviewdog/action-rubocop@v2 with: rubocop_version: gemfile github_token: ${{ secrets.github_token }} reporter: github-pr-check fog-libvirt-0.14.0/.github/workflows/ruby.yml000066400000000000000000000022401510261170500211150ustar00rootroot00000000000000# This workflow uses actions that are not certified by GitHub. # They are provided by a third-party and are governed by # separate terms of service, privacy policy, and support # documentation. # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby name: Ruby on: push: branches: [ master ] pull_request: branches: [ master ] jobs: test: runs-on: ubuntu-latest strategy: matrix: ruby-version: ['2.7', '3.0', '3.1', '3.2', '3.3', 'head'] continue-on-error: ${{ matrix.ruby-version == 'head' }} steps: - uses: actions/checkout@v5 - name: Update apt-get run: sudo apt-get update -qq - name: Install libvirt-dev run: sudo apt-get install -y libvirt-dev - name: Set up Ruby uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby-version }} bundler-cache: true # runs 'bundle install' and caches installed gems automatically - name: Install dependencies run: bundle install - name: Run tests run: bundle exec rake fog-libvirt-0.14.0/.gitignore000066400000000000000000000004711510261170500160100ustar00rootroot00000000000000*~ *.gem *.rbc *.sw? .rbenv .rvmrc .bundle .DS_Store .idea .yardoc /tests/.fog bin/* !bin/fog .fog coverage doc/* docs/_site/* docs/about/supported_services.markdown Gemfile.lock gemfiles/*.lock yardoc pkg spec/credentials.yml vendor/* tags tests/digitalocean/fixtures/ .ruby-gemset .ruby-version providers/*/doc fog-libvirt-0.14.0/.irbrc000066400000000000000000000042671510261170500151310ustar00rootroot00000000000000## This is primarily used for easier testing and development or # usage of Fog. # # How to use: # 1. Add this at the end of your `.irbrc` in your home directory. # # @working_directory = Dir.pwd # @local_irbrc = File.join(@working_directory, '.irbrc') # # if @working_directory != ENV['HOME'] # load @local_irbrc if File.exists?(@local_irbrc) # end # # remove_instance_variable(:@working_directory) # remove_instance_variable(:@local_irbrc) # # 2. Inside the Fog execute `bundle exec irb` # require 'fog' class ConnectionManager < Hash def [](key) $connection_manager_previous_key = key super(key) end def []=(key, value) $connection_manager_previous_key = key super(key, value) end end def connections return @connections if @connections @connections = ConnectionManager.new end def connection connections[$connection_manager_previous_key] end def connect_openstack(username, password, tenant = nil, url = 'http://192.168.27.100:35357/') parameters = { :provider => 'openstack', :openstack_api_key => password, :openstack_username => username, :openstack_auth_url => "#{url}v2.0/tokens" } parameters.merge!(:openstack_tenant => tenant) if tenant key = username.to_sym set_service(key, Fog::Identity, parameters) set_service(key, Fog::Compute, parameters) set_service(key, Fog::Volume, parameters) set_service(key, Fog::Image, parameters) end def connect(parameters) connections_count = connections.count connections[connections_count] = Hash.new set_service(connections_count, Fog::Identity, parameters) set_service(connections_count, Fog::Compute , parameters) set_service(connections_count, Fog::Storage , parameters) set_service(connections_count, Fog::Volume , parameters) set_service(connections_count, Fog::Image , parameters) set_service(connections_count, Fog::DNS , parameters) set_service(connections_count, Fog::CDN , parameters) connection end def set_service(connections_count, type, parameters) service_symbol = type.to_s.split('::').last.downcase.to_sym connections[connections_count].merge!({ service_symbol => type.new(parameters) }) rescue # Service not available end fog-libvirt-0.14.0/.rubocop.yml000066400000000000000000000006671510261170500163010ustar00rootroot00000000000000inherit_from: .rubocop_todo.yml Style/HashSyntax: EnforcedStyle: hash_rockets Layout/LineLength: Max: 100 Enabled: false Style/StringLiterals: Enabled: false Style/SignalException: Description: 'Do not enforce use of fail when raising exceptions.' # Valid values are: semantic, only_raise and only_fail EnforcedStyle: only_raise Metrics/ClassLength: Enabled: false Metrics/BlockLength: Exclude: - tests/**/*.rb fog-libvirt-0.14.0/.rubocop_todo.yml000066400000000000000000000760311510261170500173240ustar00rootroot00000000000000# This configuration was generated by # `rubocop --auto-gen-config` # on 2024-07-15 15:09:37 UTC using RuboCop version 1.64.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. # Offense count: 30 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, IndentationWidth. # SupportedStyles: with_first_element, with_fixed_indentation Layout/ArrayAlignment: Exclude: - 'lib/fog/libvirt/requests/compute/list_networks.rb' - 'tests/libvirt/models/compute/nic_tests.rb' - 'tests/libvirt/models/compute/server_tests.rb' - 'tests/libvirt/models/compute/volume_tests.rb' # Offense count: 12 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, IndentOneStep, IndentationWidth. # SupportedStyles: case, end Layout/CaseIndentation: Exclude: - 'lib/fog/bin/libvirt.rb' - 'lib/fog/libvirt/compute.rb' - 'lib/fog/libvirt/requests/compute/list_interfaces.rb' - 'lib/fog/libvirt/requests/compute/list_networks.rb' - 'lib/fog/libvirt/requests/compute/list_volumes.rb' # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). Layout/ClosingParenthesisIndentation: Exclude: - 'lib/fog/libvirt/models/compute/server.rb' # Offense count: 2 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. # SupportedStyles: leading, trailing Layout/DotPosition: Exclude: - 'minitests/server/user_data_iso_test.rb' # Offense count: 13 # This cop supports safe autocorrection (--autocorrect). Layout/EmptyLineAfterGuardClause: Exclude: - '.irbrc' - 'lib/fog/libvirt/models/compute/pool.rb' - 'lib/fog/libvirt/models/compute/server.rb' - 'lib/fog/libvirt/models/compute/volume.rb' - 'lib/fog/libvirt/requests/compute/list_interfaces.rb' - 'lib/fog/libvirt/requests/compute/update_display.rb' # Offense count: 5 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. # SupportedStyles: around, only_before Layout/EmptyLinesAroundAccessModifier: Exclude: - 'lib/fog/libvirt/models/compute/nic.rb' - 'lib/fog/libvirt/models/compute/server.rb' - 'lib/fog/libvirt/models/compute/util/uri.rb' - 'lib/fog/libvirt/requests/compute/list_interfaces.rb' - 'lib/fog/libvirt/requests/compute/list_networks.rb' # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowAliasSyntax, AllowedMethods. # AllowedMethods: alias_method, public, protected, private Layout/EmptyLinesAroundAttributeAccessor: Exclude: - 'lib/fog/libvirt/models/compute/volume.rb' # Offense count: 36 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. # SupportedStyles: empty_lines, no_empty_lines Layout/EmptyLinesAroundBlockBody: Enabled: false # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). Layout/EmptyLinesAroundExceptionHandlingKeywords: Exclude: - 'lib/fog/libvirt/compute.rb' # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyleAlignWith, Severity. # SupportedStylesAlignWith: keyword, variable, start_of_line Layout/EndAlignment: Exclude: - 'lib/fog/bin/libvirt.rb' # Offense count: 6 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment. Layout/ExtraSpacing: Exclude: - 'Rakefile' - 'tests/libvirt/requests/compute/create_domain_tests.rb' - 'tests/libvirt/requests/compute/define_domain_tests.rb' # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, IndentationWidth. # SupportedStyles: consistent, consistent_relative_to_receiver, special_for_inner_method_call, special_for_inner_method_call_in_parentheses Layout/FirstArgumentIndentation: Exclude: - 'lib/fog/libvirt/models/compute/server.rb' # Offense count: 9 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, IndentationWidth. # SupportedStyles: special_inside_parentheses, consistent, align_braces Layout/FirstHashElementIndentation: Exclude: - '.irbrc' - 'lib/fog/libvirt/requests/compute/list_domains.rb' - 'lib/fog/libvirt/requests/compute/list_interfaces.rb' - 'lib/fog/libvirt/requests/compute/list_networks.rb' - 'lib/fog/libvirt/requests/compute/list_pools.rb' - 'lib/fog/libvirt/requests/compute/list_volumes.rb' - 'minitests/test_helper.rb' # Offense count: 96 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle. # SupportedHashRocketStyles: key, separator, table # SupportedColonStyles: key, separator, table # SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit Layout/HashAlignment: Exclude: - 'lib/fog/libvirt/models/compute/nic.rb' - 'lib/fog/libvirt/models/compute/server.rb' - 'lib/fog/libvirt/models/compute/volume.rb' - 'lib/fog/libvirt/requests/compute/list_domains.rb' - 'lib/fog/libvirt/requests/compute/list_interfaces.rb' - 'lib/fog/libvirt/requests/compute/list_networks.rb' - 'lib/fog/libvirt/requests/compute/list_pools.rb' - 'lib/fog/libvirt/requests/compute/list_volumes.rb' # Offense count: 15 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowDoxygenCommentStyle, AllowGemfileRubyComment. Layout/LeadingCommentSpace: Exclude: - 'lib/fog/libvirt/compute.rb' - 'lib/fog/libvirt/models/compute/nic.rb' - 'lib/fog/libvirt/models/compute/server.rb' - 'lib/fog/libvirt/requests/compute/destroy_interface.rb' - 'tests/libvirt/models/compute/server_tests.rb' - 'tests/libvirt/requests/compute/create_domain_tests.rb' # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). Layout/LeadingEmptyLines: Exclude: - 'lib/fog/libvirt/requests/compute/libversion.rb' # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. # SupportedStyles: symmetrical, new_line, same_line Layout/MultilineArrayBraceLayout: Exclude: - 'lib/fog/libvirt/requests/compute/list_networks.rb' # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). Layout/MultilineBlockLayout: Exclude: - 'tests/libvirt/requests/compute/dhcp_leases_tests.rb' # Offense count: 2 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, IndentationWidth. # SupportedStyles: aligned, indented, indented_relative_to_receiver Layout/MultilineMethodCallIndentation: Exclude: - 'minitests/server/user_data_iso_test.rb' # Offense count: 10 # This cop supports safe autocorrection (--autocorrect). Layout/SpaceAfterComma: Exclude: - 'fog-libvirt.gemspec' - 'lib/fog/libvirt/compute.rb' - 'lib/fog/libvirt/models/compute/server.rb' - 'lib/fog/libvirt/requests/compute/list_domains.rb' # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). Layout/SpaceAfterMethodName: Exclude: - 'lib/fog/libvirt/requests/compute/clone_volume.rb' # Offense count: 23 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. # SupportedStyles: space, no_space Layout/SpaceAroundEqualsInParameterDefault: Exclude: - 'lib/fog/libvirt/compute.rb' - 'lib/fog/libvirt/models/compute/interfaces.rb' - 'lib/fog/libvirt/models/compute/networks.rb' - 'lib/fog/libvirt/models/compute/nodes.rb' - 'lib/fog/libvirt/models/compute/pool.rb' - 'lib/fog/libvirt/models/compute/server.rb' - 'lib/fog/libvirt/models/compute/servers.rb' - 'lib/fog/libvirt/models/compute/util/util.rb' - 'lib/fog/libvirt/models/compute/volume.rb' - 'lib/fog/libvirt/requests/compute/list_interfaces.rb' - 'lib/fog/libvirt/requests/compute/list_networks.rb' - 'lib/fog/libvirt/requests/compute/list_volumes.rb' - 'lib/fog/libvirt/requests/compute/volume_action.rb' # Offense count: 67 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator, EnforcedStyleForRationalLiterals. # SupportedStylesForExponentOperator: space, no_space # SupportedStylesForRationalLiterals: space, no_space Layout/SpaceAroundOperators: Exclude: - 'Rakefile' - 'lib/fog/bin/libvirt.rb' - 'lib/fog/libvirt/compute.rb' - 'lib/fog/libvirt/models/compute/server.rb' - 'lib/fog/libvirt/models/compute/util/uri.rb' - 'lib/fog/libvirt/models/compute/util/util.rb' - 'lib/fog/libvirt/requests/compute/list_domains.rb' - 'lib/fog/libvirt/requests/compute/list_interfaces.rb' - 'lib/fog/libvirt/requests/compute/list_networks.rb' - 'lib/fog/libvirt/requests/compute/list_pools.rb' # Offense count: 8 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. # SupportedStyles: space, no_space # SupportedStylesForEmptyBraces: space, no_space Layout/SpaceBeforeBlockBraces: Exclude: - 'fog-libvirt.gemspec' - 'lib/fog/libvirt/models/compute/server.rb' - 'lib/fog/libvirt/models/compute/util/util.rb' - 'lib/fog/libvirt/requests/compute/list_domains.rb' - 'tests/libvirt/models/compute/nic_tests.rb' - 'tests/libvirt/models/compute/server_tests.rb' - 'tests/libvirt/models/compute/volume_tests.rb' # Offense count: 7 # This cop supports safe autocorrection (--autocorrect). Layout/SpaceBeforeComma: Exclude: - '.irbrc' - 'lib/fog/libvirt/models/compute/server.rb' # Offense count: 4 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowForAlignment. Layout/SpaceBeforeFirstArg: Exclude: - 'tests/libvirt/requests/compute/create_domain_tests.rb' - 'tests/libvirt/requests/compute/define_domain_tests.rb' # Offense count: 9 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBrackets. # SupportedStyles: space, no_space, compact # SupportedStylesForEmptyBrackets: space, no_space Layout/SpaceInsideArrayLiteralBrackets: Exclude: - 'lib/fog/libvirt/models/compute/server.rb' - 'lib/fog/libvirt/requests/compute/list_networks.rb' - 'tests/libvirt/models/compute/interface_tests.rb' - 'tests/libvirt/models/compute/network_tests.rb' - 'tests/libvirt/models/compute/nic_tests.rb' - 'tests/libvirt/models/compute/pool_tests.rb' - 'tests/libvirt/models/compute/server_tests.rb' - 'tests/libvirt/models/compute/volume_tests.rb' # Offense count: 24 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. # SupportedStyles: space, no_space # SupportedStylesForEmptyBraces: space, no_space Layout/SpaceInsideBlockBraces: Exclude: - 'lib/fog/bin/libvirt.rb' - 'lib/fog/libvirt/models/compute/server.rb' - 'lib/fog/libvirt/models/compute/util/util.rb' - 'lib/fog/libvirt/requests/compute/list_domains.rb' - 'minitests/server/user_data_iso_test.rb' - 'tests/libvirt/models/compute/nic_tests.rb' - 'tests/libvirt/models/compute/server_tests.rb' - 'tests/libvirt/models/compute/volume_tests.rb' - 'tests/libvirt/requests/compute/create_domain_tests.rb' - 'tests/libvirt/requests/compute/define_domain_tests.rb' # Offense count: 30 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. # SupportedStyles: space, no_space, compact # SupportedStylesForEmptyBraces: space, no_space Layout/SpaceInsideHashLiteralBraces: Exclude: - 'lib/fog/libvirt/models/compute/nodes.rb' - 'lib/fog/libvirt/models/compute/server.rb' - 'lib/fog/libvirt/models/compute/volume.rb' - 'lib/fog/libvirt/requests/compute/clone_volume.rb' - 'lib/fog/libvirt/requests/compute/list_domains.rb' - 'lib/fog/libvirt/requests/compute/list_interfaces.rb' - 'lib/fog/libvirt/requests/compute/list_networks.rb' - 'lib/fog/libvirt/requests/compute/list_pools.rb' - 'lib/fog/libvirt/requests/compute/list_volumes.rb' - 'lib/fog/libvirt/requests/compute/update_display.rb' - 'lib/fog/libvirt/requests/compute/volume_action.rb' - 'tests/libvirt/requests/compute/create_domain_tests.rb' - 'tests/libvirt/requests/compute/update_display.rb' # Offense count: 3 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. # SupportedStyles: space, compact, no_space Layout/SpaceInsideParens: Exclude: - 'lib/fog/libvirt/models/compute/pool.rb' - 'lib/fog/libvirt/models/compute/server.rb' - 'tests/libvirt/requests/compute/create_domain_tests.rb' # Offense count: 4 # This cop supports safe autocorrection (--autocorrect). Layout/SpaceInsidePercentLiteralDelimiters: Exclude: - 'tests/libvirt/compute_tests.rb' - 'tests/libvirt/models/compute/server_tests.rb' # Offense count: 2 # This cop supports safe autocorrection (--autocorrect). Lint/ErbNewArguments: Exclude: - 'lib/fog/libvirt/models/compute/util/util.rb' # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). Lint/ParenthesesAsGroupedExpression: Exclude: - 'lib/fog/libvirt/requests/compute/update_display.rb' # Offense count: 1 Lint/RescueException: Exclude: - 'lib/fog/libvirt/requests/compute/upload_volume.rb' # Offense count: 1 Lint/ReturnInVoidContext: Exclude: - 'lib/fog/libvirt/models/compute/util/uri.rb' # Offense count: 1 Lint/ShadowingOuterLocalVariable: Exclude: - 'lib/fog/libvirt/models/compute/server.rb' # Offense count: 4 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AutoCorrect, IgnoreEmptyBlocks, AllowUnusedKeywordArguments. Lint/UnusedBlockArgument: Exclude: - 'lib/fog/libvirt/requests/compute/list_domains.rb' - 'minitests/server/user_data_iso_test.rb' # Offense count: 22 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AutoCorrect, AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods. Lint/UnusedMethodArgument: Enabled: false # Offense count: 2 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: AutoCorrect. Lint/UselessAssignment: Exclude: - 'lib/fog/bin/libvirt.rb' - 'lib/fog/libvirt/requests/compute/upload_volume.rb' # Offense count: 13 # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. Metrics/AbcSize: Max: 38 # Offense count: 9 # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. # AllowedMethods: refine Metrics/BlockLength: Max: 80 # Offense count: 1 # Configuration parameters: CountBlocks. Metrics/BlockNesting: Max: 4 # Offense count: 7 # Configuration parameters: AllowedMethods, AllowedPatterns. Metrics/CyclomaticComplexity: Max: 11 # Offense count: 29 # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. Metrics/MethodLength: Max: 24 # Offense count: 5 # Configuration parameters: AllowedMethods, AllowedPatterns. Metrics/PerceivedComplexity: Max: 12 # Offense count: 2 Naming/AccessorMethodName: Exclude: - 'lib/fog/libvirt/requests/compute/get_node_info.rb' # Offense count: 1 # Configuration parameters: ForbiddenDelimiters. # ForbiddenDelimiters: (?i-mx:(^|\s)(EO[A-Z]{1}|END)(\s|$)) Naming/HeredocDelimiterNaming: Exclude: - 'lib/fog/bin/libvirt.rb' # Offense count: 1 # Configuration parameters: EnforcedStyle, AllowedPatterns. # SupportedStyles: snake_case, camelCase Naming/MethodName: Exclude: - 'lib/fog/libvirt/requests/compute/list_domains.rb' # Offense count: 6 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. # SupportedStyles: separated, grouped Style/AccessorGrouping: Exclude: - 'lib/fog/libvirt/compute.rb' - 'lib/fog/libvirt/models/compute/server.rb' # Offense count: 4 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. # SupportedStyles: prefer_alias, prefer_alias_method Style/Alias: Exclude: - 'lib/fog/libvirt/models/compute/server.rb' # Offense count: 5 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: EnforcedStyle. # SupportedStyles: always, conditionals Style/AndOr: Exclude: - 'lib/fog/libvirt/compute.rb' - 'lib/fog/libvirt/models/compute/server.rb' # Offense count: 3 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, AllowedMethods, AllowedPatterns, AllowBracesOnProceduralOneLiners, BracesRequiredMethods. # SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces # ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object # FunctionalMethods: let, let!, subject, watch # AllowedMethods: lambda, proc, it Style/BlockDelimiters: Exclude: - 'lib/fog/libvirt/requests/compute/list_domains.rb' - 'tests/libvirt/models/compute/server_tests.rb' - 'tests/libvirt/requests/compute/dhcp_leases_tests.rb' # Offense count: 22 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. # SupportedStyles: is_a?, kind_of? Style/ClassCheck: Enabled: false # Offense count: 1 Style/ClassVars: Exclude: - 'lib/fog/bin/libvirt.rb' # Offense count: 5 # This cop supports safe autocorrection (--autocorrect). Style/ColonMethodCall: Exclude: - 'lib/fog/bin/libvirt.rb' - 'lib/fog/libvirt/compute.rb' - 'lib/fog/libvirt/models/compute/server.rb' # Offense count: 1 # This cop supports unsafe autocorrection (--autocorrect-all). Style/CommentedKeyword: Exclude: - 'lib/fog/bin/libvirt.rb' # Offense count: 2 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions. # SupportedStyles: assign_to_condition, assign_inside_condition Style/ConditionalAssignment: Exclude: - 'lib/fog/libvirt/compute.rb' - 'tests/helpers/formats_helper.rb' # Offense count: 2 # This cop supports safe autocorrection (--autocorrect). Style/DefWithParentheses: Exclude: - 'lib/fog/libvirt/requests/compute/libversion.rb' # Offense count: 81 # Configuration parameters: AllowedConstants. Style/Documentation: Enabled: false # Offense count: 2 # This cop supports safe autocorrection (--autocorrect). Style/EmptyLiteral: Exclude: - '.irbrc' - 'lib/fog/libvirt/requests/compute/get_node_info.rb' # Offense count: 5 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AutoCorrect, EnforcedStyle. # SupportedStyles: compact, expanded Style/EmptyMethod: Exclude: - 'lib/fog/libvirt/requests/compute/create_volume.rb' - 'lib/fog/libvirt/requests/compute/define_pool.rb' - 'lib/fog/libvirt/requests/compute/get_node_info.rb' - 'lib/fog/libvirt/requests/compute/list_pool_volumes.rb' - 'lib/fog/libvirt/requests/compute/upload_volume.rb' # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). Style/EvalWithLocation: Exclude: - 'lib/fog/bin/libvirt.rb' # Offense count: 4 # This cop supports safe autocorrection (--autocorrect). Style/ExpandPathArguments: Exclude: - 'fog-libvirt.gemspec' - 'lib/fog/libvirt.rb' - 'tests/helper.rb' # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). Style/ExplicitBlockArgument: Exclude: - 'minitests/server/user_data_iso_test.rb' # Offense count: 2 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: EnforcedStyle. # SupportedStyles: each, for Style/For: Exclude: - 'lib/fog/bin/libvirt.rb' # Offense count: 72 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: EnforcedStyle. # SupportedStyles: always, always_true, never Style/FrozenStringLiteralComment: Enabled: false # Offense count: 3 # Configuration parameters: AllowedVariables. Style/GlobalVars: Exclude: - '.irbrc' # Offense count: 9 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: MinBodyLength, AllowConsecutiveConditionals. Style/GuardClause: Exclude: - 'lib/fog/libvirt/models/compute/server.rb' - 'lib/fog/libvirt/models/compute/util/uri.rb' - 'lib/fog/libvirt/requests/compute/dhcp_leases.rb' # Offense count: 8 # This cop supports safe autocorrection (--autocorrect). Style/IfUnlessModifier: Exclude: - 'lib/fog/libvirt/models/compute/server.rb' - 'lib/fog/libvirt/requests/compute/dhcp_leases.rb' - 'lib/fog/libvirt/requests/compute/list_volumes.rb' - 'tests/helpers/mock_helper.rb' # Offense count: 1 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: InverseMethods, InverseBlocks. Style/InverseMethods: Exclude: - 'tests/libvirt/models/compute/volume_tests.rb' # Offense count: 1 # This cop supports unsafe autocorrection (--autocorrect-all). Style/LineEndConcatenation: Exclude: - 'lib/fog/libvirt/models/compute/server.rb' # Offense count: 5 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowedMethods, AllowedPatterns. Style/MethodCallWithoutArgsParentheses: Exclude: - 'lib/fog/libvirt/models/compute/server.rb' - 'lib/fog/libvirt/requests/compute/create_domain.rb' - 'lib/fog/libvirt/requests/compute/define_domain.rb' - 'tests/libvirt/models/compute/server_tests.rb' - 'tests/libvirt/requests/compute/define_domain_tests.rb' # Offense count: 17 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. # SupportedStyles: require_parentheses, require_no_parentheses, require_no_parentheses_except_multiline Style/MethodDefParentheses: Exclude: - 'lib/fog/libvirt/models/compute/nic.rb' - 'lib/fog/libvirt/models/compute/server.rb' - 'lib/fog/libvirt/models/compute/util/util.rb' - 'lib/fog/libvirt/requests/compute/get_node_info.rb' - 'lib/fog/libvirt/requests/compute/list_domains.rb' - 'lib/fog/libvirt/requests/compute/list_interfaces.rb' - 'lib/fog/libvirt/requests/compute/list_pools.rb' - 'lib/fog/libvirt/requests/compute/list_volumes.rb' # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). Style/MultilineIfModifier: Exclude: - 'lib/fog/libvirt/requests/compute/get_node_info.rb' # Offense count: 4 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: EnforcedStyle. # SupportedStyles: literals, strict Style/MutableConstant: Exclude: - 'Rakefile' - 'lib/fog/libvirt/models/compute/nic.rb' - 'lib/fog/libvirt/version.rb' # Offense count: 4 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. # SupportedStyles: both, prefix, postfix Style/NegatedIf: Exclude: - 'lib/fog/libvirt/models/compute/server.rb' - 'lib/fog/libvirt/requests/compute/dhcp_leases.rb' # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, MinBodyLength. # SupportedStyles: skip_modifier_ifs, always Style/Next: Exclude: - 'lib/fog/bin/libvirt.rb' # Offense count: 7 # This cop supports safe autocorrection (--autocorrect). Style/Not: Exclude: - 'lib/fog/libvirt/models/compute/server.rb' - 'tests/libvirt/models/compute/interfaces_tests.rb' - 'tests/libvirt/models/compute/nics_tests.rb' - 'tests/libvirt/models/compute/pools_tests.rb' - 'tests/libvirt/models/compute/servers_tests.rb' - 'tests/libvirt/models/compute/volumes_tests.rb' - 'tests/libvirt/requests/compute/update_autostart_tests.rb' # Offense count: 8 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: Strict, AllowedNumbers, AllowedPatterns. Style/NumericLiterals: MinDigits: 10 # Offense count: 1 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: EnforcedStyle, AllowedMethods, AllowedPatterns. # SupportedStyles: predicate, comparison Style/NumericPredicate: Exclude: - 'spec/**/*' - 'lib/fog/libvirt/models/compute/server.rb' # Offense count: 2 # Configuration parameters: AllowedMethods. # AllowedMethods: respond_to_missing? Style/OptionalBooleanParameter: Exclude: - 'lib/fog/libvirt/requests/compute/list_volumes.rb' - 'tests/helpers/formats_helper.rb' # Offense count: 7 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: PreferredDelimiters. Style/PercentLiteralDelimiters: Exclude: - 'lib/fog/libvirt/models/compute/server.rb' - 'lib/fog/libvirt/requests/compute/list_domains.rb' - 'tests/libvirt/compute_tests.rb' - 'tests/libvirt/models/compute/server_tests.rb' # Offense count: 21 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: EnforcedStyle, AllowedCompactTypes. # SupportedStyles: compact, exploded Style/RaiseArgs: Exclude: - 'lib/fog/libvirt/compute.rb' - 'lib/fog/libvirt/models/compute/interface.rb' - 'lib/fog/libvirt/models/compute/network.rb' - 'lib/fog/libvirt/models/compute/nic.rb' - 'lib/fog/libvirt/models/compute/pool.rb' - 'lib/fog/libvirt/models/compute/server.rb' - 'lib/fog/libvirt/models/compute/volume.rb' # Offense count: 4 # This cop supports safe autocorrection (--autocorrect). Style/RedundantBegin: Exclude: - 'lib/fog/libvirt/models/compute/server.rb' - 'lib/fog/libvirt/requests/compute/list_volumes.rb' - 'lib/fog/libvirt/requests/compute/upload_volume.rb' - 'tests/libvirt/requests/compute/create_domain_tests.rb' # Offense count: 15 # This cop supports unsafe autocorrection (--autocorrect-all). Style/RedundantInterpolation: Exclude: - 'Rakefile' - 'lib/fog/libvirt/models/compute/server.rb' - 'tests/libvirt/models/compute/interface_tests.rb' - 'tests/libvirt/models/compute/network_tests.rb' - 'tests/libvirt/models/compute/nic_tests.rb' - 'tests/libvirt/models/compute/pool_tests.rb' - 'tests/libvirt/models/compute/server_tests.rb' - 'tests/libvirt/models/compute/volume_tests.rb' # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). Style/RedundantParentheses: Exclude: - 'lib/fog/libvirt/models/compute/volume.rb' # Offense count: 24 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowMultipleReturnValues. Style/RedundantReturn: Exclude: - 'lib/fog/libvirt/compute.rb' - 'lib/fog/libvirt/models/compute/server.rb' - 'lib/fog/libvirt/models/compute/util/uri.rb' - 'lib/fog/libvirt/requests/compute/dhcp_leases.rb' - 'lib/fog/libvirt/requests/compute/libversion.rb' - 'lib/fog/libvirt/requests/compute/list_domains.rb' - 'lib/fog/libvirt/requests/compute/list_volumes.rb' # Offense count: 19 # This cop supports safe autocorrection (--autocorrect). Style/RedundantSelf: Exclude: - 'lib/fog/bin/libvirt.rb' - 'lib/fog/libvirt/models/compute/interfaces.rb' - 'lib/fog/libvirt/models/compute/networks.rb' - 'lib/fog/libvirt/models/compute/pools.rb' - 'lib/fog/libvirt/models/compute/server.rb' - 'lib/fog/libvirt/models/compute/volume.rb' - 'lib/fog/libvirt/models/compute/volumes.rb' # Offense count: 1 # This cop supports unsafe autocorrection (--autocorrect-all). Style/RedundantSort: Exclude: - 'lib/fog/libvirt/models/compute/server.rb' # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, AllowInnerSlashes. # SupportedStyles: slashes, percent_r, mixed Style/RegexpLiteral: Exclude: - 'fog-libvirt.gemspec' # Offense count: 14 # This cop supports safe autocorrection (--autocorrect). Style/RescueModifier: Exclude: - 'lib/fog/libvirt/requests/compute/get_node_info.rb' - 'lib/fog/libvirt/requests/compute/list_domains.rb' - 'lib/fog/libvirt/requests/compute/list_interfaces.rb' - 'lib/fog/libvirt/requests/compute/list_volumes.rb' # Offense count: 7 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. # SupportedStyles: implicit, explicit Style/RescueStandardError: Exclude: - '.irbrc' - 'lib/fog/bin/libvirt.rb' - 'lib/fog/libvirt/models/compute/server.rb' - 'tests/libvirt/requests/compute/create_domain_tests.rb' # Offense count: 5 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods, MaxChainLength. # AllowedMethods: present?, blank?, presence, try, try! Style/SafeNavigation: Exclude: - 'lib/fog/libvirt/models/compute/server.rb' - 'lib/fog/libvirt/requests/compute/upload_volume.rb' # Offense count: 2 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: RequireEnglish, EnforcedStyle. # SupportedStyles: use_perl_names, use_english_names, use_builtin_english_names Style/SpecialGlobalVars: Exclude: - 'lib/fog/libvirt/compute.rb' - 'minitests/test_helper.rb' # Offense count: 1 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: Mode. Style/StringConcatenation: Exclude: - 'Rakefile' # Offense count: 12 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: MinSize. # SupportedStyles: percent, brackets Style/SymbolArray: EnforcedStyle: brackets # Offense count: 2 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: AllowMethodsWithArguments, AllowedMethods, AllowedPatterns, AllowComments. # AllowedMethods: define_method Style/SymbolProc: Exclude: - 'lib/fog/bin/libvirt.rb' - 'lib/fog/libvirt/models/compute/server.rb' # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyleForMultiline. # SupportedStylesForMultiline: comma, consistent_comma, no_comma Style/TrailingCommaInArrayLiteral: Exclude: - 'lib/fog/libvirt/models/compute/server.rb' # Offense count: 7 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyleForMultiline. # SupportedStylesForMultiline: comma, consistent_comma, no_comma Style/TrailingCommaInHashLiteral: Exclude: - 'lib/fog/libvirt/models/compute/server.rb' - 'lib/fog/libvirt/models/compute/volume.rb' - 'lib/fog/libvirt/requests/compute/list_domains.rb' - 'lib/fog/libvirt/requests/compute/list_volumes.rb' - 'minitests/test_helper.rb' - 'tests/helpers/mock_helper.rb' # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). Style/UnlessElse: Exclude: - 'lib/fog/libvirt/models/compute/util/uri.rb' # Offense count: 3 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: WordRegex. # SupportedStyles: percent, brackets Style/WordArray: EnforcedStyle: percent MinSize: 5 fog-libvirt-0.14.0/CONTRIBUTORS.md000066400000000000000000000016471510261170500163050ustar00rootroot00000000000000* Amos Benari * brookemckim * Carl Caum * Carlos Sanchez * David Wittman * Dominic Cleal * Greg Sutcliffe * James Herdman * Josef Strzibny * Kevin Menard * Konstantin Haase * Kyle Rames * Lance Ivy * Ohad Levy * Patrick Debois * Paul Thornthwaite * Romain Vrignaud * Ryan Davies * Sergio Rubio * Shlomi Zadok * Steve Smith * Vincent Demeester * Wesley Beary * Tomer Brisker fog-libvirt-0.14.0/Gemfile000066400000000000000000000003151510261170500153100ustar00rootroot00000000000000source "https://rubygems.org" group :development, :test do # This is here because gemspec doesn't support require: false gem "netrc", :require => false gem "octokit", :require => false end gemspec fog-libvirt-0.14.0/LICENSE.md000066400000000000000000000021711510261170500154230ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2009-2014 [CONTRIBUTORS.md](https://github.com/fog/fog/blob/master/CONTRIBUTORS.md) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. fog-libvirt-0.14.0/README.md000066400000000000000000000046731510261170500153070ustar00rootroot00000000000000# Fog::Libvirt fog-libvirt is a libvirt provider for [fog](https://github.com/fog/fog). [![Build Status](https://github.com/fog/fog-libvirt/actions/workflows/ruby.yml/badge.svg)](https://github.com/fog/fog-libvirt/actions/workflows/ruby.yml) [![Dependency Status](https://gemnasium.com/fog/fog.png)](https://gemnasium.com/fog/fog-libvirt) [![Code Climate](https://codeclimate.com/github/fog/fog.png)](https://codeclimate.com/github/fog/fog-libvirt) [![Gem Version](https://fury-badge.herokuapp.com/rb/fog.png)](http://badge.fury.io/rb/fog-libvirt) [![Gittip](http://img.shields.io/gittip/geemus.png)](https://www.gittip.com/geemus/) ## Installation fog-libvirt can be used as a module for fog or installed separately as: ``` $ sudo gem install fog-libvirt ``` ## Usage Example REPL session: ``` >> require "fog/libvirt" => true >> compute = Fog::Compute.new(provider: :libvirt, libvirt_uri: "qemu:///session") => #, @uri="qemu:///session"... >> server = compute.servers.create(name: "test") => ], volumes=[ ], active=false, boot_order=["hd", "cdrom", "network"], display={:type=>"vnc", :port=>"-1", :listen=>"127.0.0.1"}, cpu={}, hugepages=false, guest_agent=true, virtio_rng={}, state="shutoff" > ``` See [README.md](https://github.com/fog/fog-libvirt/blob/master/lib/fog/libvirt/models/compute/README.md). ## Contributing Please refer to [CONTRIBUTING.md](https://github.com/fog/fog/blob/master/CONTRIBUTING.md). ## License Please refer to [LICENSE.md](https://github.com/fog/fog-libvirt/blob/master/LICENSE.md). fog-libvirt-0.14.0/Rakefile000066400000000000000000000054201510261170500154640ustar00rootroot00000000000000require 'bundler/setup' require 'rake/testtask' require 'rubygems' require 'rubygems/package_task' require 'yard' require File.dirname(__FILE__) + '/lib/fog/libvirt' ############################################################################# # # Helper functions # ############################################################################# def name @name ||= Dir['*.gemspec'].first.split('.').first end def version Fog::Libvirt::VERSION end def gemspec_file "#{name}.gemspec" end def gem_file "#{name}-#{version}.gem" end ############################################################################# # # Standard tasks # ############################################################################# GEM_NAME = "#{name}" task :default => [:test, :minitest] Rake::TestTask.new(:minitest) do |t| t.libs << '.' t.libs << 'lib' t.libs << 'minitests' t.test_files = Dir.glob('minitests/**/*_test.rb') t.verbose = true end desc 'Run tests' task :test do mock = ENV['FOG_MOCK'] || 'true' sh("export FOG_MOCK=#{mock} && bundle exec shindont tests") end desc 'Run mocked tests' task :mock do sh("export FOG_MOCK=true && bundle exec shindont tests") end desc 'Run live tests' task :live do sh("export FOG_MOCK=false && bundle exec shindont tests") end desc "Open an irb session preloaded with this library" task :console do sh "irb -rubygems -r ./lib/fog/libvirt.rb" end ############################################################################# # # Packaging tasks # ############################################################################# task :release => ["release:prepare", "release:publish"] namespace :release do task :preflight do unless `git branch` =~ /^\* master$/ puts "You must be on the master branch to release!" exit! end if `git tag` =~ /^\* v#{version}$/ puts "Tag v#{version} already exists!" exit! end end task :prepare => :preflight do Rake::Task[:build].invoke sh "gem install pkg/#{name}-#{version}.gem" Rake::Task[:git_mark_release].invoke end task :publish do Rake::Task[:git_push_release].invoke Rake::Task[:gem_push].invoke end end task :git_mark_release do sh "git commit --allow-empty -a -m 'Release #{version}'" sh "git tag v#{version}" end task :git_push_release do sh "git push origin master" sh "git push origin v#{version}" end task :gem_push do sh "gem push pkg/#{name}-#{version}.gem" end desc "Build #{name}-#{version}.gem" task :build do sh "mkdir -p pkg" sh "gem build #{gemspec_file}" sh "mv #{gem_file} pkg" end task :gem => :build # Include Yard tasks for rake yard YARDOC_LOCATION = "doc" YARD::Rake::YardocTask.new do |t| t.files = ['lib/**/*.rb', "README"] t.options = ["--output-dir", YARDOC_LOCATION, "--title", "#{name} #{version}"] end fog-libvirt-0.14.0/fog-libvirt.gemspec000066400000000000000000000032521510261170500176110ustar00rootroot00000000000000lib = File.expand_path("../lib", __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require "fog/libvirt/version" Gem::Specification.new do |s| s.specification_version = 2 if s.respond_to? :specification_version= s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.name = "fog-libvirt" s.version = Fog::Libvirt::VERSION s.summary = "Module for the 'fog' gem to support libvirt" s.description = "This library can be used as a module for 'fog' or as standalone libvirt provider." s.authors = ["geemus (Wesley Beary)"] s.email = "geemus@gmail.com" s.homepage = "http://github.com/fog/fog-libvirt" s.license = "MIT" s.require_paths = %w[lib] s.rdoc_options = ["--charset=UTF-8"] s.extra_rdoc_files = %w[README.md] s.required_ruby_version = '>= 2.7' s.add_dependency("fog-core", ">= 1.27.4") s.add_dependency("fog-json") s.add_dependency("fog-xml", "~> 0.1.1") s.add_dependency("json") s.add_dependency('ruby-libvirt','>= 0.7.0') s.add_development_dependency("minitest", "~> 5.0") s.add_development_dependency("mocha", ">= 1.15", "< 3") s.add_development_dependency("net-ssh") s.add_development_dependency("pry") s.add_development_dependency("rake") s.add_development_dependency("rubocop") s.add_development_dependency("shindo", "~> 0.3.4") s.add_development_dependency("simplecov") s.add_development_dependency("yard") # Let's not ship dot files and gemfiles git_files = `git ls-files`.split("\n") s.files = git_files.delete_if{ |f| f =~ /^\..*/ || f =~ /^gemfiles\/*/ } s.test_files = `git ls-files -- {spec,tests}/*`.split("\n") end fog-libvirt-0.14.0/lib/000077500000000000000000000000001510261170500145645ustar00rootroot00000000000000fog-libvirt-0.14.0/lib/fog/000077500000000000000000000000001510261170500153375ustar00rootroot00000000000000fog-libvirt-0.14.0/lib/fog/bin/000077500000000000000000000000001510261170500161075ustar00rootroot00000000000000fog-libvirt-0.14.0/lib/fog/bin/libvirt.rb000066400000000000000000000030231510261170500201050ustar00rootroot00000000000000module Libvirt # deviates from other bin stuff to accommodate gem class << self def class_for(key) case key when :compute Fog::Libvirt::Compute else raise ArgumentError, "Unrecognized service: #{key}" end end def [](service) @@connections ||= Hash.new do |hash, key| hash[key] = case key when :compute Fog::Logger.warning("Libvirt[:compute] is not recommended, use Compute[:libvirt] for portability") Fog::Compute.new(:provider => 'Libvirt') else raise ArgumentError, "Unrecognized service: #{key.inspect}" end end @@connections[service] end def available? begin availability=true unless Gem::Specification::find_by_name("ruby-libvirt").nil? rescue Gem::LoadError availability=false rescue availability_gem=Gem.available?("ruby-libvirt") end if availability for service in services for collection in self.class_for(service).collections unless self.respond_to?(collection) self.class_eval <<-EOS, __FILE__, __LINE__ def self.#{collection} self[:#{service}].#{collection} end EOS end end end end availability end def collections services.map {|service| self[service].collections}.flatten.sort_by {|service| service.to_s} end def services Fog::Libvirt.services end end end fog-libvirt-0.14.0/lib/fog/libvirt.rb000066400000000000000000000004571510261170500173450ustar00rootroot00000000000000require 'fog/core' require 'fog/xml' require 'fog/json' require 'libvirt' require File.expand_path('../libvirt/version', __FILE__) module Fog module Libvirt extend Fog::Provider autoload :Compute, File.expand_path('../libvirt/compute', __FILE__) service(:compute, 'Compute') end end fog-libvirt-0.14.0/lib/fog/libvirt/000077500000000000000000000000001510261170500170125ustar00rootroot00000000000000fog-libvirt-0.14.0/lib/fog/libvirt/compute.rb000066400000000000000000000071771510261170500210270ustar00rootroot00000000000000require 'fog/libvirt/models/compute/util/util' require 'fog/libvirt/models/compute/util/uri' module Fog module Libvirt class Compute < Fog::Service requires :libvirt_uri recognizes :libvirt_username, :libvirt_password model_path 'fog/libvirt/models/compute' model :server collection :servers model :network collection :networks model :interface collection :interfaces model :volume collection :volumes model :pool collection :pools model :node collection :nodes model :nic collection :nics request_path 'fog/libvirt/requests/compute' request :list_domains request :create_domain request :define_domain request :vm_action request :list_pools request :list_pool_volumes request :define_pool request :pool_action request :list_volumes request :volume_action request :create_volume request :upload_volume request :clone_volume request :list_networks request :destroy_network request :dhcp_leases request :list_interfaces request :destroy_interface request :get_node_info request :update_autostart request :update_display request :libversion module Shared include Fog::Libvirt::Util attr_reader :client attr_reader :uri def initialize(options={}) super() @uri = ::Fog::Libvirt::Util::URI.new(enhance_uri(options[:libvirt_uri])) # libvirt is part of the gem => ruby-libvirt begin require 'libvirt' rescue LoadError => e retry if require('rubygems') raise e.message end begin if options[:libvirt_username] and options[:libvirt_password] @client = ::Libvirt::open_auth(uri.uri, [::Libvirt::CRED_AUTHNAME, ::Libvirt::CRED_PASSPHRASE]) do |cred| case cred['type'] when ::Libvirt::CRED_AUTHNAME options[:libvirt_username] when ::Libvirt::CRED_PASSPHRASE options[:libvirt_password] end end else @client = ::Libvirt::open(uri.uri) end rescue ::Libvirt::ConnectionError raise Fog::Errors::Error.new("Error making a connection to libvirt URI #{uri.uri}:\n#{$!}") end end def terminate @client.close if @client and !@client.closed? end def enhance_uri(uri) require 'cgi' append="" # on macosx, chances are we are using libvirt through homebrew # the client will default to a socket location based on it's own location (/opt) # we conveniently point it to /var/run/libvirt/libvirt-sock # if no socket option has been specified explicitly and # if the socket exists socketpath="/var/run/libvirt/libvirt-sock" if RUBY_PLATFORM =~ /darwin/ && File.exist?(socketpath) querystring=::URI.parse(uri).query if querystring.nil? append="?socket=#{socketpath}" elsif !::CGI.parse(querystring).key?("socket") append="&socket=#{socketpath}" end end uri+append end end class Real include Shared end class Mock include Shared def enhance_uri(uri) uri = 'test:///default' unless ::URI.parse(uri).scheme == 'test' super(uri) end end end end end fog-libvirt-0.14.0/lib/fog/libvirt/models/000077500000000000000000000000001510261170500202755ustar00rootroot00000000000000fog-libvirt-0.14.0/lib/fog/libvirt/models/compute/000077500000000000000000000000001510261170500217515ustar00rootroot00000000000000fog-libvirt-0.14.0/lib/fog/libvirt/models/compute/README.md000066400000000000000000000076411510261170500232400ustar00rootroot00000000000000This model implements the connection with a libvirt URI. A libvirt URI can either be local or remote. To learn more on the specific libvirt URI syntax see: - [http://libvirt.org/uri.html](http://libvirt.org/uri.html) - [http://libvirt.org/remote.html#Remote_URI_reference](http://libvirt.org/remote.html#Remote_URI_reference) Only ssh is supported as the transport for remote URI's. TLS is NOT supported, as we can't easily login to the server ## Dependencies - the interaction with libvirt is done through the official libvirt gem called 'ruby-libvirt'. - be aware that there is another libvirt gem called 'libvirt', which is not compatible - If this gem is not installed the models for libvirt will not be available - libvirt needs to be setup so that it can be used - for a remote ssh connection this requires to be member of the libvirt group before you can use the libvirt commands - verify if you can execute virsh command to see if you have correct access ## Libvirt on Macosx - There is a libvirt client for Macosx, available via homebrew - By default this will install things in /usr/local/somewhere - This means that also the default locations of the libvirt-socket are assumed to be in /usr/local - To check the connection you need to override your libvirt socket location in the URI - "qemu+ssh://patrick@myserver/system?socket=/var/run/libvirt/libvirt-sock" ## Ceph RBD volumes To configure Ceph RBD volumes, the file ``/etc/foreman/ceph.conf`` is used. After adding the authentication key to a libvirt secret, it can be configured as follows: ``` monitor=mon001.example.com,mon002.example.com,mon003.example.com port=6789 libvirt_ceph_pool=rbd_pool_name auth_username=libvirt auth_uuid=uuid_of_libvirt_secret bus_type=virtio ``` For more recent versions of libvirt which support using the secret by name (`usage` attribute in the `secret` tag), you can also drop `auth_uuid` and specify `auth_usage` instead. If both are specified, `auth_uuid` will be preferred for maximum compatibility. The `bus_type` can be set to `virtio` or `scsi`. If it is ommited, the default is `scsi`. ## Configuration The URI can be configured in two ways: 1) via the .fog file :default :libvirt_uri: "qemu+ssh://patrick@myserver/system?socket=/var/run/libvirt/libvirt-sock" 2) you can also pass it during creation : f=Fog::Compute.new(:provider => "Libvirt", :libvirt_uri => "qemu+ssh://patrick@myserver/system") ## IP-addresses of guests Libvirt does not provide a way to query guests for Ip-addresses. The way we solve this problem is by installing arpwatch: this watches an interface for new mac-addresses and ip-addresses requested by DHCP We query that logfile for the mac-address and can retrieve the ip-address vi /etc/rsyslog.d/30-arpwatch.conf #:msg, contains, "arpwatch:" -/var/log/arpwatch.log #& ~ if $programname =='arpwatch' then /var/log/arpwatch.log & ~ This log files needs to be readable for the users of libvirt ## SSh-ing into the guests Once we have retrieved the ip-address of the guest we can ssh into it. This works great if the URI is local. But when the URI is remote our machine can't ssh directly into the guest sometimes (due to NAT or firewall issues) Luckily libvirt over ssh requires netcat to be installed on the libvirt server. We use this to proxy our ssh requests to the guest over the ssh connection to the libvirt server. Thanks to the requirement that you need ssh login to work to a libvirt server, we can login and tunnel the ssh to the guest. ## Bridge configuration (slowness) We had noticed that sometimes it takes about 30 seconds before the server gets a DHCP response from the server. In our case it was because the new machine Mac-address was not allowed immediately by the bridge. Adding the flag 'bridge_fd 0' solved that problem. /etc/network/interfaces auto br0 iface br0 inet static address 10.247.4.13 netmask 255.255.255.0 network 10.247.4.0 broadcast 10.247.4.255 bridge_ports eth0.4 bridge_stp on bridge_maxwait 0 bridge_fd 0 fog-libvirt-0.14.0/lib/fog/libvirt/models/compute/interface.rb000066400000000000000000000007341510261170500242420ustar00rootroot00000000000000require 'fog/core/model' module Fog module Libvirt class Compute class Interface < Fog::Model identity :name attribute :mac attribute :active def save raise Fog::Errors::Error.new('Creating a new interface is not yet implemented. Contributions welcome!') end def shutdown service.destroy_interface(mac) end def active? active end end end end end fog-libvirt-0.14.0/lib/fog/libvirt/models/compute/interfaces.rb000066400000000000000000000006231510261170500244220ustar00rootroot00000000000000require 'fog/core/collection' require 'fog/libvirt/models/compute/interface' module Fog module Libvirt class Compute class Interfaces < Fog::Collection model Fog::Libvirt::Compute::Interface def all(filter={}) load(service.list_interfaces(filter)) end def get(name) self.all(:name => name).first end end end end end fog-libvirt-0.14.0/lib/fog/libvirt/models/compute/network.rb000066400000000000000000000017231510261170500237720ustar00rootroot00000000000000require 'fog/core/model' require 'fog/libvirt/models/compute/util/util' module Fog module Libvirt class Compute class Network < Fog::Model include Fog::Libvirt::Util identity :uuid attribute :name attribute :bridge_name attribute :xml def initialize(attributes = {}) super end def dhcp_leases(mac, flags = 0) service.dhcp_leases(uuid, mac, flags) end def save raise Fog::Errors::Error.new('Creating a new network is not yet implemented. Contributions welcome!') end def shutdown service.destroy_network(uuid) end def to_xml builder = Nokogiri::XML::Builder.new do |xml| xml.network do xml.name(name) xml.bridge(:name => bridge_name, :stp => 'on', :delay => '0') end end builder.to_xml end end end end end fog-libvirt-0.14.0/lib/fog/libvirt/models/compute/networks.rb000066400000000000000000000006131510261170500241520ustar00rootroot00000000000000require 'fog/core/collection' require 'fog/libvirt/models/compute/network' module Fog module Libvirt class Compute class Networks < Fog::Collection model Fog::Libvirt::Compute::Network def all(filter={}) load(service.list_networks(filter)) end def get(uuid) self.all(:uuid => uuid).first end end end end end fog-libvirt-0.14.0/lib/fog/libvirt/models/compute/nic.rb000066400000000000000000000022531510261170500230510ustar00rootroot00000000000000require 'fog/core/model' module Fog module Libvirt class Compute class Nic < Fog::Model identity :mac attribute :id attribute :type attribute :network attribute :bridge attribute :model attr_accessor :server TYPES = ["network", "bridge", "user"] def new? mac.nil? end def initialize attributes super defaults.merge(attributes) raise Fog::Errors::Error.new("#{type} is not a supported nic type") if new? && !TYPES.include?(type) end def save raise Fog::Errors::Error.new('Creating a new nic is not yet implemented. Contributions welcome!') #requires :server #service.attach_nic(domain , self) end def destroy raise Fog::Errors::Error.new('Destroying an interface is not yet implemented. Contributions welcome!') #requires :server ##detach the nic #service.detach_nic(domain, mac) end private def defaults { :type => "bridge", :model => "virtio" } end end end end end fog-libvirt-0.14.0/lib/fog/libvirt/models/compute/nics.rb000066400000000000000000000003361510261170500232340ustar00rootroot00000000000000require 'fog/core/collection' require 'fog/libvirt/models/compute/nic' module Fog module Libvirt class Compute class Nics < Fog::Collection model Fog::Libvirt::Compute::Nic end end end end fog-libvirt-0.14.0/lib/fog/libvirt/models/compute/node.rb000066400000000000000000000011401510261170500232170ustar00rootroot00000000000000require 'fog/core/model' module Fog module Libvirt class Compute class Node < Fog::Model identity :uuid attribute :model attribute :memory attribute :cpus attribute :mhz attribute :nodes attribute :sockets attribute :cores attribute :threads attribute :type attribute :version attribute :uri attribute :node_free_memory attribute :max_vcpus attribute :manufacturer attribute :product attribute :serial attribute :hostname end end end end fog-libvirt-0.14.0/lib/fog/libvirt/models/compute/nodes.rb000066400000000000000000000005411510261170500234060ustar00rootroot00000000000000require 'fog/core/collection' require 'fog/libvirt/models/compute/node' module Fog module Libvirt class Compute class Nodes < Fog::Collection model Fog::Libvirt::Compute::Node def all(filter={ }) load(service.get_node_info) end def get all.first end end end end end fog-libvirt-0.14.0/lib/fog/libvirt/models/compute/pool.rb000066400000000000000000000044011510261170500232460ustar00rootroot00000000000000require 'fog/core/model' module Fog module Libvirt class Compute class Pool < Fog::Model attr_reader :xml identity :uuid attribute :persistent attribute :autostart attribute :active attribute :name attribute :allocation attribute :capacity attribute :num_of_volumes attribute :state def initialize(attributes={} ) # Can be created by passing in XML @xml = attributes.delete(:xml) super(attributes) end def save raise Fog::Errors::Error.new('Creating a new pool requires proper xml') unless xml self.uuid = (persistent ? service.define_pool(xml) : service.create_pool(xml)).uuid reload end # Start the pool = make it active # Performs a libvirt create (= start) def start service.pool_action uuid, :create end # Stop the pool = make it non-active # Performs a libvirt destroy (= stop) def stop service.pool_action uuid, :destroy end # Shuts down the pool def shutdown stop end # Build this storage pool def build service.pool_action uuid, :build end # Destroys the storage pool def destroy # Shutdown pool if active service.pool_action uuid, :destroy if active? # If this is a persistent domain we need to undefine it service.pool_action uuid, :undefine if persistent? end # Is the pool active or not? def active? active end # Will the pool autostart or not? def auto_start? autostart end # Is the pool persistent or not? def persistent? persistent end # Retrieves the volumes of this pool def volumes service.list_pool_volumes uuid end def to_xml builder = Nokogiri::XML::Builder.new do |xml| xml.pool(:type => 'dir') do xml.name(name) xml.target do xml.path(path) end end end builder.to_xml end end end end end fog-libvirt-0.14.0/lib/fog/libvirt/models/compute/pools.rb000066400000000000000000000006011510261170500234270ustar00rootroot00000000000000require 'fog/core/collection' require 'fog/libvirt/models/compute/pool' module Fog module Libvirt class Compute class Pools < Fog::Collection model Fog::Libvirt::Compute::Pool def all(filter = {}) load(service.list_pools(filter)) end def get(uuid) self.all(:uuid => uuid).first end end end end end fog-libvirt-0.14.0/lib/fog/libvirt/models/compute/server.rb000066400000000000000000000501201510261170500236020ustar00rootroot00000000000000require 'fog/compute/models/server' require 'fog/libvirt/models/compute/util/util' require 'fileutils' module Fog module Libvirt class Compute class Server < Fog::Compute::Server include Fog::Libvirt::Util attr_reader :xml identity :id, :aliases => 'uuid' attribute :cpus attribute :cputime attribute :firmware attribute :firmware_features attribute :secure_boot attribute :loader_attributes attribute :os_type attribute :memory_size attribute :max_memory_size attribute :name attribute :arch attribute :persistent attribute :domain_type attribute :uuid attribute :autostart attribute :nics attribute :volumes attribute :active attribute :boot_order attribute :display attribute :cpu attribute :hugepages attribute :guest_agent attribute :video attribute :virtio_rng attribute :state # The following attributes are only needed when creating a new vm #TODO: Add depreciation warning attr_accessor :iso_dir, :iso_file attr_accessor :network_interface_type ,:network_nat_network, :network_bridge_name attr_accessor :volume_format_type, :volume_allocation,:volume_capacity, :volume_name, :volume_pool_name, :volume_template_name, :volume_path attr_accessor :password attr_accessor :user_data # Can be created by passing in :xml => "" # or by providing :template_options => { # :name => "", :cpus => 1, :memory_size => 256 , :volume_template # } def initialize(attributes={} ) @xml = attributes.delete(:xml) verify_boot_order(attributes[:boot_order]) super defaults.merge(attributes) initialize_nics initialize_volumes @user_data = attributes.delete(:user_data) end def new? uuid.nil? end def save raise Fog::Errors::Error.new('Saving an existing server may create a duplicate') unless new? create_or_clone_volume unless xml or @volumes create_user_data_iso if user_data @xml ||= to_xml self.id = (persistent ? service.define_domain(xml) : service.create_domain(xml)).uuid reload rescue => e raise Fog::Errors::Error.new("Error saving the server: #{e}") end def start return true if active? action_status = service.vm_action(uuid, :create) reload action_status end def update_autostart(value) service.update_autostart(uuid, value) end def mac nics&.first&.mac end def disk_path volumes.first.path if volumes and volumes.first end def destroy(options={ :destroy_volumes => false, :flags => ::Libvirt::Domain::UNDEFINE_NVRAM }) poweroff unless stopped? flags = options.fetch(:flags, ::Libvirt::Domain::UNDEFINE_NVRAM) if flags.zero? service.vm_action(uuid, :undefine) else # the test driver doesn't support UNDEFINE_NVRAM if service.uri.driver == 'test' flags ^= ::Libvirt::Domain::UNDEFINE_NVRAM end service.vm_action(uuid, :undefine, flags) end volumes.each { |vol| vol.destroy } if options[:destroy_volumes] true end def reboot action_status = service.vm_action(uuid, :reboot) reload action_status end def poweroff action_status = service.vm_action(uuid, :destroy) reload action_status end def shutdown action_status = service.vm_action(uuid, :shutdown) reload action_status end def resume action_status = service.vm_action(uuid, :resume) reload action_status end def suspend action_status = service.vm_action(uuid, :suspend) reload action_status end def stopped? state == "shutoff" end def ready? state == "running" end #alias methods alias_method :halt, :poweroff alias_method :stop, :shutdown alias_method :active?, :active alias_method :autostart?, :autostart def volumes # lazy loading of volumes @volumes ||= (@volumes_path || []).map{ |path| service.volumes.all(:path => path).first }.compact end def private_ip_address ip_address(:private) end def public_ip_address ip_address(:public) end def ssh(commands) requires :ssh_ip_address, :username ssh_options={} ssh_options[:password] = password unless password.nil? ssh_options[:proxy]= ssh_proxy unless ssh_proxy.nil? super(commands, ssh_options) end def ssh_proxy begin require 'net/ssh/proxy/command' rescue LoadError Fog::Logger.warning("'net/ssh' missing, please install and try again.") exit(1) end # if this is a direct connection, we don't need a proxy to be set. return nil unless connection.uri.ssh_enabled? user_string= service.uri.user ? "-l #{service.uri.user}" : "" Net::SSH::Proxy::Command.new("ssh #{user_string} #{service.uri.host} nc %h %p") end # Transfers a file def scp(local_path, remote_path, upload_options = {}) requires :ssh_ip_address, :username scp_options = {} scp_options[:password] = password unless self.password.nil? scp_options[:key_data] = [private_key] if self.private_key scp_options[:proxy]= ssh_proxy unless self.ssh_proxy.nil? Fog::SCP.new(ssh_ip_address, username, scp_options).upload(local_path, remote_path, upload_options) end # Sets up a new key def setup(credentials = {}) requires :public_key, :ssh_ip_address, :username credentials[:proxy]= ssh_proxy unless ssh_proxy.nil? credentials[:password] = password unless self.password.nil? credentials[:key_data] = [private_key] if self.private_key commands = [ %{mkdir .ssh}, # %{passwd -l #{username}}, #Not sure if we need this here # %{echo "#{Fog::JSON.encode(attributes)}" >> ~/attributes.json} ] if public_key commands << %{echo "#{public_key}" >> ~/.ssh/authorized_keys} end # wait for domain to be ready Timeout::timeout(360) do begin Timeout::timeout(8) do Fog::SSH.new(ssh_ip_address, username, credentials.merge(:timeout => 4)).run('pwd') end rescue Errno::ECONNREFUSED sleep(2) retry rescue Net::SSH::AuthenticationFailed, Timeout::Error retry end end Fog::SSH.new(ssh_ip_address, username, credentials).run(commands) end def update_display attrs = {} service.update_display attrs.merge(:uuid => uuid) reload end # can't use deprecate method, as the value is part of the display hash def vnc_port Fog::Logger.deprecation("#{self.class} => #vnc_port is deprecated, use #display[:port] instead [light_black](#{caller.first})[/]") display[:port] end def generate_config_iso(user_data, &blk) Dir.mktmpdir('config') do |wd| generate_config_iso_in_dir(wd, user_data, &blk) end end def generate_config_iso_in_dir(dir_path, user_data, &blk) FileUtils.touch(File.join(dir_path, "meta-data")) File.open(File.join(dir_path, 'user-data'), 'w') { |f| f.write user_data } isofile = Tempfile.new(['init', '.iso']).path unless system("genisoimage -output #{isofile} -volid cidata -joliet -rock #{File.join(dir_path, 'user-data')} #{File.join(dir_path, 'meta-data')}") raise Fog::Errors::Error.new("Couldn't generate cloud-init iso disk with genisoimage.") end blk.call(isofile) end def create_user_data_iso generate_config_iso(user_data) do |iso| vol = service.volumes.create(:name => cloud_init_volume_name, :capacity => "#{File.size(iso)}b", :allocation => "0G") vol.upload_image(iso) @iso_file = cloud_init_volume_name @iso_dir = File.dirname(vol.path) if vol.path end end def cloud_init_volume_name "#{name}-cloud-init.iso" end # rubocop:disable Metrics def to_xml builder = Nokogiri::XML::Builder.new do |xml| xml.domain(:type => domain_type) do xml.name(name) xml.memory(memory_size) if hugepages xml.memoryBacking do xml.hugepages end end xml.vcpu(cpus) os_tags = {} os_tags[:firmware] = firmware if firmware == 'efi' xml.os(**os_tags) do type = xml.type(os_type, :arch => arch) type[:machine] = "q35" if ["i686", "x86_64"].include?(arch) boot_order.each do |dev| xml.boot(:dev => dev) end loader_attributes&.each do |key, value| xml.loader(key => value) end if firmware == "efi" && firmware_features&.any? xml.firmware do firmware_features.each_pair do |key, value| xml.feature(:name => key, :enabled => value) end end end end xml.features do xml.acpi xml.apic end unless cpu.empty? if cpu.dig(:model, :name) xml.cpu do xml.model(cpu.dig(:model, :name), :fallback => cpu.dig(:model, :fallback) || "allow") end else xml.cpu( :mode => cpu.fetch(:mode, "host-passthrough"), :check => cpu.fetch(:check, "none"), :migratable => cpu.fetch(:migratable, "on") ) end end xml.clock(:offset => "utc") do xml.timer(:name => "rtc", :tickpolicy => "catchup") xml.timer(:name => "pit", :tickpolicy => "delay") xml.timer(:name => "hpet", :present => "no") end xml.devices do ceph_args = read_ceph_args volumes.each_with_index do |volume, index| target_device = "vd#{('a'..'z').to_a[index]}" if ceph_args && volume.pool_name.include?(ceph_args["libvirt_ceph_pool"]) xml.disk(:type => "network", :device => "disk") do xml.driver(:name => "qemu", :type => volume.format_type, :cache => "writeback", :discard => "unmap") xml.source(:protocol => "rbd", :name => volume.path) ceph_args["monitor"]&.split(",")&.each do |monitor| xml.host(:name => monitor, :port => ceph_args["port"]) end xml.auth(:username => ceph_args["auth_username"]) do if ceph_args.key?("auth_uuid") xml.secret(:type => "ceph", :uuid => ceph_args["auth_uuid"]) else xml.secret(:type => "ceph", :usage => ceph_args["auth_usage"]) end end xml.target(:dev => target_device, :bus => ceph_args["bus_type"] == "virtio" ? "virtio" : "scsi") end else is_block = volume.path.start_with?("/dev/") xml.disk(:type => is_block ? "block" : "file", :device => "disk") do xml.driver(:name => "qemu", :type => volume.format_type) if is_block xml.source(:dev => volume.path) else xml.source(:file => volume.path) end xml.target(:dev => target_device, :bus => "virtio") end end end if iso_file xml.disk(:type => "file", :device => "cdrom") do xml.driver(:name => "qemu", :type => "raw") xml.source(:file => "#{iso_dir}/#{iso_file}") xml.target(:dev => "sda", :bus => "scsi") xml.readonly xml.address(:type => "drive", :controller => 0, :bus => 0, :unit => 0) end end nics.each do |nic| xml.interface(:type => nic.type) do xml.mac(:address => nic.mac) if nic.mac if nic.type == "bridge" xml.source(:bridge => nic.bridge) else xml.source(:network => nic.network) end xml.model(:type => nic.model) end end if guest_agent xml.channel(:type => "unix") do xml.target(:type => "virtio", :name => "org.qemu.guest_agent.0") end end xml.rng(:model => "virtio") do xml.backend(virtio_rng[:backend_path], :model => virtio_rng.fetch(:backend_model, "random")) end if arch == "s390x" xml.controller(:type => "scsi", :index => "0", :model => "virtio-scsi") xml.console(:type => "pty") do xml.target(:type => "sclp") end xml.memballoon(:model => "virtio") else xml.serial(:type => "pty") do xml.target(:port => 0) end xml.console(:type => "pty") do xml.target(:port => 0) end xml.input(:type => "tablet", :bus => "usb") xml.input(:type => "mouse", :bus => "ps2") graphics = xml.graphics(:type => display[:type]) if display[:port].empty? graphics.port = display[:port] graphics.autoport = "no" else graphics.port = -1 graphics.autoport = "yes" end graphics.listen = display[:listen] unless display[:listen].empty? graphics.passwd = display[:password] if display[:password] && !display[:password].empty? xml.video do xml.model(video) end end end end end builder.to_xml end # rubocop:enable Metrics private attr_accessor :volumes_path def read_ceph_args(path = "/etc/foreman/ceph.conf") return unless File.file?(path) args = {} File.readlines(path).each do |line| pair = line.strip.split("=") key = pair[0] value = pair[1] args[key] = value end args end # This retrieves the ip address of the mac address using dhcp_leases # It returns an array of public and private ip addresses # Currently only one ip address is returned, but in the future this could be multiple # if the server has multiple network interface def addresses(service_arg=service, options={}) ip_address = nil if (nic = self.nics&.first) net = service.networks.all(:name => nic.network).first # Assume the lease expiring last is the current IP address ip_address = net&.dhcp_leases(nic.mac)&.max_by { |lse| lse["expirytime"] }&.dig("ipaddr") end return { :public => [ip_address], :private => [ip_address] } end # Locale-friendly removal of non-alpha nums DOMAIN_CLEANUP_REGEXP = Regexp.compile('[\W_-]') def ip_address(key) addresses[key]&.first end def initialize_nics if nics nics.map! { |nic| nic.is_a?(Hash) ? service.nics.new(nic) : nic } else self.nics = [service.nics.new({:type => network_interface_type, :bridge => network_bridge_name, :network => network_nat_network})] end end def initialize_volumes if attributes[:volumes] && !attributes[:volumes].empty? @volumes = attributes[:volumes].map { |vol| vol.is_a?(Hash) ? service.volumes.new(vol) : vol } end end def create_or_clone_volume options = {:name => volume_name || default_volume_name} # Check if a disk template was specified if volume_template_name template_volume = service.volumes.all(:name => volume_template_name).first raise Fog::Errors::Error.new("Template #{volume_template_name} not found") unless template_volume begin volume = template_volume.clone("#{options[:name]}") rescue => e raise Fog::Errors::Error.new("Error creating the volume : #{e}") end else # If no template volume was given, let's create our own volume options[:pool_name] = volume_pool_name if volume_pool_name options[:format_type] = volume_format_type if volume_format_type options[:capacity] = volume_capacity if volume_capacity options[:allocation] = volume_allocation if volume_allocation begin volume = service.volumes.create(options) rescue => e raise Fog::Errors::Error.new("Error creating the volume : #{e}") end end @volumes.nil? ? @volumes = [volume] : @volumes << volume end def default_iso_dir "/var/lib/libvirt/images" end def default_volume_name "#{name}.#{volume_format_type || 'img'}" end def defaults { :persistent => true, :cpus => 1, :memory_size => 256 * 1024, :name => randomized_name, :os_type => "hvm", :arch => "x86_64", :domain_type => "kvm", :autostart => false, :iso_dir => default_iso_dir, :network_interface_type => "network", :network_nat_network => "default", :network_bridge_name => "br0", :boot_order => %w[hd cdrom network], :display => default_display, :cpu => {}, :hugepages => false, :guest_agent => true, :video => {:type => "virtio", :heads => 1}, :virtio_rng => {}, :firmware_features => { "secure-boot" => "no" }, } end def verify_boot_order order = [] valid_boot_media = %w[cdrom fd hd network] if order order.each do |b| raise "invalid boot order, possible values are any combination of: #{valid_boot_media.join(', ')}" unless valid_boot_media.include?(b) end end end def default_display {:port => '-1', :listen => '127.0.0.1', :type => 'vnc' } end end end end end fog-libvirt-0.14.0/lib/fog/libvirt/models/compute/servers.rb000066400000000000000000000006651510261170500237760ustar00rootroot00000000000000require 'fog/core/collection' require 'fog/libvirt/models/compute/server' module Fog module Libvirt class Compute class Servers < Fog::Collection model Fog::Libvirt::Compute::Server def all(filter={}) load(service.list_domains(filter)) end def get(uuid) data = service.list_domains(:uuid => uuid) new data.first if data end end end end end fog-libvirt-0.14.0/lib/fog/libvirt/models/compute/util/000077500000000000000000000000001510261170500227265ustar00rootroot00000000000000fog-libvirt-0.14.0/lib/fog/libvirt/models/compute/util/uri.rb000066400000000000000000000047341510261170500240620ustar00rootroot00000000000000require 'uri' require 'cgi' module Fog module Libvirt module Util class URI attr_reader :uri def initialize(uri) @parsed_uri=::URI.parse(uri) @uri=uri return self end # Transport will be part of the scheme # The part after the plus sign # f.i. qemu+ssh def transport scheme=@parsed_uri.scheme return nil if scheme.nil? return scheme.split(/\+/)[1] end def scheme return @parsed_uri.scheme end def driver scheme=@parsed_uri.scheme return nil if scheme.nil? return scheme.split(/\+/).first end def ssh_enabled? if remote? return transport.include?("ssh") else return false end end def remote? return !transport.nil? end def user @parsed_uri.user end def host @parsed_uri.host end def port @parsed_uri.port end def password @parsed_uri.password end def name value("name") end def command value("command") end def socket value("socket") end def keyfile value("keyfile") end def netcat value("netcat") end def no_verify? no_verify=value("no_verify") return false if no_verify.nil? if no_verify.to_s=="0" return false else return true end end def verify? return !no_verify? end def no_tty? no_tty=value("no_tty") return false if no_tty.nil? if no_tty=="0" return false else return true end end def tty? return !no_tty? end def pkipath value("pkipath") end # A libvirt URI allows you to specify extra params # http://libvirt.org/remote.html private def value(name) unless @parsed_uri.query.nil? params=CGI.parse(@parsed_uri.query) if params.key?(name) return params[name].first else return nil end else return nil end end end end end end fog-libvirt-0.14.0/lib/fog/libvirt/models/compute/util/util.rb000066400000000000000000000010671510261170500242340ustar00rootroot00000000000000require 'nokogiri' require 'securerandom' module Fog module Libvirt module Util def xml_element(xml, path, attribute=nil) xml = Nokogiri::XML(xml) attribute.nil? ? (xml/path).first.text : (xml/path).first[attribute.to_sym] end def xml_elements(xml, path, attribute=nil) xml = Nokogiri::XML(xml) attribute.nil? ? (xml/path).map : (xml/path).map{|element| element[attribute.to_sym]} end def randomized_name "fog-#{(SecureRandom.random_number*10E14).to_i.round}" end end end end fog-libvirt-0.14.0/lib/fog/libvirt/models/compute/volume.rb000066400000000000000000000107451510261170500236140ustar00rootroot00000000000000require 'fog/core/model' require 'fog/libvirt/models/compute/util/util' module Fog module Libvirt class Compute class Volume < Fog::Model attr_reader :xml include Fog::Libvirt::Util identity :id, :aliases => 'key' attribute :pool_name attribute :key attribute :name attribute :path attribute :capacity attribute :allocation attribute :owner attribute :group attribute :format_type attribute :backing_volume # Can be created by passing in :xml => "" # A volume always belongs to a pool, :pool_name => "" # def initialize(attributes={ }) @xml = attributes.delete(:xml) super(defaults.merge(attributes)) # We need a connection to calculate the pool_name # This is why we do this after super self.pool_name ||= default_pool_name end # Takes a pool and either :xml or other settings def save requires :pool_name raise Fog::Errors::Error.new('Reserving an existing volume may create a duplicate') if key @xml ||= to_xml self.id = service.create_volume(pool_name, xml).key reload end # Destroy a volume def destroy service.volume_action key, :delete end # Wipes a volume , zeroes disk def wipe service.volume_action key, :wipe end # Clones this volume to the name provided def clone(name) new_volume = self.dup new_volume.key = nil new_volume.name = name new_volume.save new_volume.reload end def clone_volume(new_name) requires :pool_name new_volume = self.dup new_volume.key = nil new_volume.name = new_name new_volume.id = service.clone_volume(pool_name, new_volume.to_xml, self.name).key new_volume.reload end def upload_image(file_path) requires :pool_name service.upload_volume(pool_name, name, file_path) end def to_xml builder = Nokogiri::XML::Builder.new do |xml| xml.volume do xml.name(name) allocation_size, allocation_unit = split_size_unit(allocation) xml.allocation(allocation_size, :unit => allocation_unit) capacity_size, capacity_unit = split_size_unit(capacity) xml.capacity(capacity_size, :unit => capacity_unit) xml.target do xml.format(:type => format_type) xml_permissions(xml) end if backing_volume xml.backingStore do xml.path(backing_volume.path) xml.format(:type => backing_volume.format_type) xml_permissions(xml) end end end end builder.to_xml end private def xml_permissions(xml) xml.permissions do xml.owner(owner) if owner xml.group(group) if group xml.mode('0744') xml.label('virt_image_t') end end def image_suffix return "img" if format_type == "raw" format_type end def randominzed_name "#{super}.#{image_suffix}" end # Try to guess the default/first pool of no pool_name was specified def default_pool_name name = "default" return name unless (service.pools.all(:name => name)).empty? # we default to the first pool we find. first_pool = service.pools.first raise Fog::Errors::Error.new('No storage pools are defined') unless first_pool first_pool.name end def defaults { :persistent => true, :format_type => "raw", :name => randomized_name, :capacity => "10G", :allocation => "1G", :owner => nil, :group => nil, } end def split_size_unit(text) if (text.kind_of? String) && (matcher = text.match(/(\d+)(.+)/)) size = matcher[1] unit = matcher[2] else size = text.to_i unit = "G" end [size, unit] end end end end end fog-libvirt-0.14.0/lib/fog/libvirt/models/compute/volumes.rb000066400000000000000000000006061510261170500237720ustar00rootroot00000000000000require 'fog/core/collection' require 'fog/libvirt/models/compute/volume' module Fog module Libvirt class Compute class Volumes < Fog::Collection model Fog::Libvirt::Compute::Volume def all(filter = {}) load(service.list_volumes(filter)) end def get(key) self.all(:key => key).first end end end end end fog-libvirt-0.14.0/lib/fog/libvirt/requests/000077500000000000000000000000001510261170500206655ustar00rootroot00000000000000fog-libvirt-0.14.0/lib/fog/libvirt/requests/compute/000077500000000000000000000000001510261170500223415ustar00rootroot00000000000000fog-libvirt-0.14.0/lib/fog/libvirt/requests/compute/clone_volume.rb000066400000000000000000000006571510261170500253650ustar00rootroot00000000000000module Fog module Libvirt class Compute module Shared def clone_volume(pool_name, xml, name) vol = client.lookup_storage_pool_by_name(pool_name).lookup_volume_by_name(name) client.lookup_storage_pool_by_name(pool_name).create_vol_xml_from(xml, vol) end end class Real include Shared end class Mock include Shared end end end end fog-libvirt-0.14.0/lib/fog/libvirt/requests/compute/create_domain.rb000066400000000000000000000004271510261170500254630ustar00rootroot00000000000000module Fog module Libvirt class Compute module Shared def create_domain(xml) client.create_domain_xml(xml) end end class Real include Shared end class Mock include Shared end end end end fog-libvirt-0.14.0/lib/fog/libvirt/requests/compute/create_volume.rb000066400000000000000000000005061510261170500255210ustar00rootroot00000000000000module Fog module Libvirt class Compute module Shared def create_volume(pool_name, xml) client.lookup_storage_pool_by_name(pool_name).create_vol_xml(xml) end end class Real include Shared end class Mock include Shared end end end end fog-libvirt-0.14.0/lib/fog/libvirt/requests/compute/define_domain.rb000066400000000000000000000004271510261170500254520ustar00rootroot00000000000000module Fog module Libvirt class Compute module Shared def define_domain(xml) client.define_domain_xml(xml) end end class Real include Shared end class Mock include Shared end end end end fog-libvirt-0.14.0/lib/fog/libvirt/requests/compute/define_pool.rb000066400000000000000000000004331510261170500251510ustar00rootroot00000000000000module Fog module Libvirt class Compute module Shared def define_pool(xml) client.define_storage_pool_xml(xml) end end class Real include Shared end class Mock include Shared end end end end fog-libvirt-0.14.0/lib/fog/libvirt/requests/compute/destroy_interface.rb000066400000000000000000000005141510261170500263770ustar00rootroot00000000000000module Fog module Libvirt class Compute module Shared #shutdown the interface def destroy_interface(uuid) client.lookup_interface_by_uuid(uuid).destroy end end class Real include Shared end class Mock include Shared end end end end fog-libvirt-0.14.0/lib/fog/libvirt/requests/compute/destroy_network.rb000066400000000000000000000004501510261170500261270ustar00rootroot00000000000000module Fog module Libvirt class Compute module Shared def destroy_network(uuid) client.lookup_network_by_uuid(uuid).destroy end end class Real include Shared end class Mock include Shared end end end end fog-libvirt-0.14.0/lib/fog/libvirt/requests/compute/dhcp_leases.rb000066400000000000000000000021371510261170500251430ustar00rootroot00000000000000require 'socket' module Fog module Libvirt class Compute class Real def dhcp_leases(uuid, mac, flags = 0) client.lookup_network_by_uuid(uuid).dhcp_leases(mac, flags) end end class Mock # Not implemented by the test driver def dhcp_leases(uuid, mac, flags = 0) leases1 = { 'aa:bb:cc:dd:ee:ff' => [ { 'type' => Socket::AF_INET, 'ipaddr' => '1.2.3.4', 'prefix' => 24, 'expirytime' => 5000 }, { 'type' => Socket::AF_INET, 'ipaddr' => '1.2.5.6', 'prefix' => 24, 'expirytime' => 5005 } ] } leases2 = { '99:88:77:66:55:44' => [ { 'type' => Socket::AF_INET, 'ipaddr' => '10.1.1.5', 'prefix' => 24, 'expirytime' => 50 } ] } networks = { # should match the default network from the test connection 'dd8fe884-6c02-601e-7551-cca97df1c5df' => leases1, 'fbd4ac68-cbea-4f95-86ed-22953fd92384' => leases2 } networks.dig(uuid, mac) end end end end end fog-libvirt-0.14.0/lib/fog/libvirt/requests/compute/get_node_info.rb000066400000000000000000000020551510261170500254670ustar00rootroot00000000000000module Fog module Libvirt class Compute module Shared def get_node_info node_hash = Hash.new node_info = client.node_get_info [:model, :memory, :cpus, :mhz, :nodes, :sockets, :cores, :threads].each do |param| node_hash[param] = node_info.send(param) rescue nil end [:type, :version, :node_free_memory, :max_vcpus].each do |param| node_hash[param] = client.send(param) rescue nil end node_hash[:uri] = client.uri xml = client.sys_info rescue nil [:uuid, :manufacturer, :product, :serial].each do |attr| node_hash[attr] = node_attr(attr, xml) rescue nil end if xml node_hash[:hostname] = client.hostname [node_hash] end private def node_attr attr, xml xml_element(xml, "sysinfo/system/entry[@name='#{attr}']").strip end end class Real include Shared end class Mock include Shared end end end end fog-libvirt-0.14.0/lib/fog/libvirt/requests/compute/libversion.rb000066400000000000000000000004061510261170500250420ustar00rootroot00000000000000 module Fog module Libvirt class Compute module Shared def libversion() client.libversion end end class Real include Shared end class Mock include Shared end end end end fog-libvirt-0.14.0/lib/fog/libvirt/requests/compute/list_domains.rb000066400000000000000000000102411510261170500253510ustar00rootroot00000000000000module Fog module Libvirt class Compute module Shared def list_domains(filter = { }) data=[] if filter.key?(:uuid) data << client.lookup_domain_by_uuid(filter[:uuid]) elsif filter.key?(:name) data << client.lookup_domain_by_name(filter[:name]) else client.list_defined_domains.each { |name| data << catchLibvirtExceptions { client.lookup_domain_by_name(name) } } unless filter[:defined] == false client.list_domains.each { |id| data << catchLibvirtExceptions { client.lookup_domain_by_id(id) } } unless filter[:active] == false end data.compact.map { |d| domain_to_attributes d }.compact end # Catch Libvirt exceptions to avoid race conditions involving # concurrent libvirt operations from other processes. For example, # domains being undefined while fog-libvirt is trying to work with # domain lists. def catchLibvirtExceptions yield rescue ::Libvirt::RetrieveError, ::Libvirt::Error nil end private def domain_display xml attrs = {} [:type, :port, :password, :listen].each do |element| attrs[element] = xml_element(xml, "domain/devices/graphics",element.to_s) rescue nil end attrs.reject{|k,v| v.nil? or v == ""} end def domain_volumes xml xml_elements(xml, "domain/devices/disk/source").map do |element| element[:file] || element[:dev] || element[:name] end end def boot_order xml xml_elements(xml, "domain/os/boot", "dev") end def firmware(xml) firmware_from_loader = xml_elements(xml, "domain/os/loader", "type").first case firmware_from_loader when 'pflash' 'efi' when 'rom' 'bios' else xml_elements(xml, "domain/os", "firmware").first || 'bios' end end # we rely on the fact that the secure attribute is only present when secure boot is enabled def secure_boot_enabled?(xml) xml_elements(xml, "domain/os/loader", "secure").first == 'yes' end def domain_interfaces xml ifs = xml_elements(xml, "domain/devices/interface") ifs.map { |i| nics.new({ :type => i['type'], :mac => (i/'mac').first[:address], :network => ((i/'source').first[:network] rescue nil), :bridge => ((i/'source').first[:bridge] rescue nil), :model => ((i/'model').first[:type] rescue nil), }.reject{|k,v| v.nil?}) } end def domain_to_attributes(dom) states= %w(nostate running blocked paused shutting-down shutoff crashed pmsuspended) begin { :id => dom.uuid, :uuid => dom.uuid, :name => dom.name, :max_memory_size => dom.info.max_mem, :cputime => dom.info.cpu_time, :memory_size => dom.info.memory, :cpus => dom.info.nr_virt_cpu, :autostart => dom.autostart?, :os_type => dom.os_type, :active => dom.active?, :display => domain_display(dom.xml_desc), :boot_order => boot_order(dom.xml_desc), :nics => domain_interfaces(dom.xml_desc), :volumes_path => domain_volumes(dom.xml_desc), :state => states[dom.info.state], :firmware => firmware(dom.xml_desc), :secure_boot => secure_boot_enabled?(dom.xml_desc), } rescue ::Libvirt::RetrieveError, ::Libvirt::Error # Catch libvirt exceptions to avoid race conditions involving # concurrent libvirt operations (like from another process) return nil end end end class Real include Shared end class Mock include Shared end end end end fog-libvirt-0.14.0/lib/fog/libvirt/requests/compute/list_interfaces.rb000066400000000000000000000024211510261170500260430ustar00rootroot00000000000000module Fog module Libvirt class Compute module Shared def list_interfaces(filter = { }) data=[] if filter.keys.empty? active_networks = client.list_interfaces rescue [] defined_networks = client.list_defined_interfaces rescue [] (active_networks + defined_networks).each do |ifname| data << interface_to_attributes(client.lookup_interface_by_name(ifname)) end else data = [interface_to_attributes(get_interface_by_filter(filter))] end data.compact end private # Retrieve the interface by mac or by name def get_interface_by_filter(filter) case filter.keys.first when :mac client.lookup_interface_by_mac(filter[:mac]) when :name client.lookup_interface_by_name(filter[:name]) end end def interface_to_attributes(net) return if net.nil? || net.name == 'lo' { :mac => net.mac, :name => net.name, :active => net.active? } end end class Real include Shared end class Mock include Shared end end end end fog-libvirt-0.14.0/lib/fog/libvirt/requests/compute/list_networks.rb000066400000000000000000000025551510261170500256040ustar00rootroot00000000000000module Fog module Libvirt class Compute module Shared def list_networks(filter = { }) data=[] if filter.keys.empty? (client.list_networks + client.list_defined_networks).each do |network_name| data << network_to_attributes(client.lookup_network_by_name(network_name)) end else data = [network_to_attributes(get_network_by_filter(filter))] end data end private # Retrieve the network by uuid or name def get_network_by_filter(filter) case filter.keys.first when :uuid client.lookup_network_by_uuid(filter[:uuid]) when :name client.lookup_network_by_name(filter[:name]) end end # bridge name may not be defined in some networks, we should skip that in such case def network_to_attributes(net) return if net.nil? begin bridge_name = net.bridge_name rescue ::Libvirt::Error bridge_name = '' end { :uuid => net.uuid, :name => net.name, :bridge_name => bridge_name } end end class Real include Shared end class Mock include Shared end end end end fog-libvirt-0.14.0/lib/fog/libvirt/requests/compute/list_pool_volumes.rb000066400000000000000000000006661510261170500264540ustar00rootroot00000000000000module Fog module Libvirt class Compute module Shared def list_pool_volumes(uuid) pool = client.lookup_storage_pool_by_uuid uuid pool.list_volumes.map do |volume_name| volume_to_attributes(pool.lookup_volume_by_name(volume_name)) end end end class Real include Shared end class Mock include Shared end end end end fog-libvirt-0.14.0/lib/fog/libvirt/requests/compute/list_pools.rb000066400000000000000000000034731510261170500250640ustar00rootroot00000000000000module Fog module Libvirt class Compute module Shared def list_pools(filter = { }) data=[] if filter.key?(:name) data << find_pool_by_name(filter[:name], filter[:include_inactive]) elsif filter.key?(:uuid) data << find_pool_by_uuid(filter[:uuid], filter[:include_inactive]) else (client.list_storage_pools + client.list_defined_storage_pools).each do |name| data << find_pool_by_name(name, filter[:include_inactive]) end end data.compact end private def find_pool_by_name name, include_inactive pool_to_attributes(client.lookup_storage_pool_by_name(name), include_inactive) rescue ::Libvirt::RetrieveError nil end def find_pool_by_uuid uuid, include_inactive pool_to_attributes(client.lookup_storage_pool_by_uuid(uuid), include_inactive) rescue ::Libvirt::RetrieveError nil end def pool_to_attributes(pool, include_inactive = nil) return nil unless pool.active? || include_inactive states=[:inactive, :building, :running, :degrated, :inaccessible] { :uuid => pool.uuid, :persistent => pool.persistent?, :autostart => pool.autostart?, :active => pool.active?, :name => pool.name, :allocation => pool.info.allocation, :capacity => pool.info.capacity, :num_of_volumes => pool.active? ? pool.num_of_volumes : nil, :state => states[pool.info.state] } end end class Real include Shared end class Mock include Shared end end end end fog-libvirt-0.14.0/lib/fog/libvirt/requests/compute/list_volumes.rb000066400000000000000000000047541510261170500254250ustar00rootroot00000000000000module Fog module Libvirt class Compute module Shared def list_volumes(filter = { }) data = [] if filter.keys.empty? raw_volumes do |pool| pool.list_volumes.each do |volume_name| begin data << volume_to_attributes(pool.lookup_volume_by_name(volume_name)) rescue ::Libvirt::RetrieveError # Catch libvirt exceptions to avoid race conditions involving # concurrent libvirt operations (like from another process) next end end end else data << get_volume(filter) end data.compact end private def volume_to_attributes(vol) format_type = xml_element(vol.xml_desc, "/volume/target/format", "type") rescue nil # not all volumes have types, e.g. LVM return nil if format_type == "dir" begin { :pool_name => vol.pool.name, :key => vol.key, :id => vol.key, :path => vol.path, :name => vol.name, :format_type => format_type, :allocation => bytes_to_gb(vol.info.allocation), :capacity => bytes_to_gb(vol.info.capacity), } rescue ::Libvirt::RetrieveError, ::Libvirt::Error return nil # If there are issues during stat of volume file end end def bytes_to_gb bytes bytes / 1024**3 end def raw_volumes client.list_storage_pools.each do |pool_name| pool = client.lookup_storage_pool_by_name(pool_name) yield(pool) end end def get_volume filter = { }, raw = false raw_volumes do |pool| vol = case filter.keys.first when :name pool.lookup_volume_by_name(filter[:name]) rescue nil when :key pool.lookup_volume_by_key(filter[:key]) rescue nil when :path pool.lookup_volume_by_path(filter[:path]) rescue nil end if vol return raw ? vol : volume_to_attributes(vol) end end nil end end class Real include Shared end class Mock include Shared end end end end fog-libvirt-0.14.0/lib/fog/libvirt/requests/compute/pool_action.rb000066400000000000000000000005321510261170500251740ustar00rootroot00000000000000module Fog module Libvirt class Compute module Shared def pool_action(uuid, action) pool = client.lookup_storage_pool_by_uuid uuid pool.send(action) true end end class Real include Shared end class Mock include Shared end end end end fog-libvirt-0.14.0/lib/fog/libvirt/requests/compute/update_autostart.rb000066400000000000000000000005231510261170500262560ustar00rootroot00000000000000module Fog module Libvirt class Compute module Shared def update_autostart(uuid, value) domain = client.lookup_domain_by_uuid(uuid) domain.autostart = value end end class Real include Shared end class Mock include Shared end end end end fog-libvirt-0.14.0/lib/fog/libvirt/requests/compute/update_display.rb000066400000000000000000000022161510261170500256760ustar00rootroot00000000000000module Fog module Libvirt class Compute module Shared def update_display(options = { }) raise ArgumentError, "uuid is a required parameter" unless options.key? :uuid domain = client.lookup_domain_by_uuid(options[:uuid]) display = { } display[:type] = options[:type] || 'vnc' display[:port] = (options[:port] || -1).to_s display[:listen] = options[:listen].to_s if options[:listen] display[:passwd] = options[:password].to_s if options[:password] display[:autoport] = 'yes' if display[:port] == '-1' new_keymap = options[:keymap] || xml_elements(domain.xml_desc, "graphics", "keymap")[0] display[:keymap] = new_keymap unless new_keymap.nil? builder = Nokogiri::XML::Builder.new { graphics_ (display) } xml = Nokogiri::XML(builder.to_xml).root.to_s domain.update_device(xml, 0) # if we got no exceptions, then we're good' true end end class Real include Shared end class Mock include Shared end end end end fog-libvirt-0.14.0/lib/fog/libvirt/requests/compute/upload_volume.rb000066400000000000000000000014521510261170500255430ustar00rootroot00000000000000module Fog module Libvirt class Compute module Shared def upload_volume(pool_name, volume_name, file_path) volume = client.lookup_storage_pool_by_name(pool_name).lookup_volume_by_name(volume_name) stream = client.stream image_file = File.open(file_path, "rb") volume.upload(stream, 0, image_file.size) stream.sendall do |_opaque, n| begin r = image_file.read(n) r ? [r.length, r] : [0, ""] rescue Exception => e [-1, ""] end end stream.finish ensure image_file.close if image_file end end class Real include Shared end class Mock include Shared end end end end fog-libvirt-0.14.0/lib/fog/libvirt/requests/compute/vm_action.rb000066400000000000000000000005511510261170500246460ustar00rootroot00000000000000module Fog module Libvirt class Compute module Shared def vm_action(uuid, action, *params) domain = client.lookup_domain_by_uuid(uuid) domain.send(action, *params) true end end class Real include Shared end class Mock include Shared end end end end fog-libvirt-0.14.0/lib/fog/libvirt/requests/compute/volume_action.rb000066400000000000000000000005111510261170500255270ustar00rootroot00000000000000module Fog module Libvirt class Compute module Shared def volume_action(key, action, options={}) get_volume({:key => key}, true).send(action) true end end class Real include Shared end class Mock include Shared end end end end fog-libvirt-0.14.0/lib/fog/libvirt/version.rb000066400000000000000000000000751510261170500210260ustar00rootroot00000000000000module Fog module Libvirt VERSION = '0.14.0' end end fog-libvirt-0.14.0/minitests/000077500000000000000000000000001510261170500160355ustar00rootroot00000000000000fog-libvirt-0.14.0/minitests/server/000077500000000000000000000000001510261170500173435ustar00rootroot00000000000000fog-libvirt-0.14.0/minitests/server/user_data_iso_test.rb000066400000000000000000000050121510261170500235460ustar00rootroot00000000000000require 'test_helper' class UserDataIsoTest < Minitest::Test def setup @compute = Fog::Compute[:libvirt] @server = @compute.servers.new(:name => "test") @test_data = "test data" end def test_contains_meta_data_file @server.stubs(:system).returns(true) in_a_temp_dir do |d| @server.generate_config_iso_in_dir(d, @test_data) {|iso| assert File.exist?(File.join(d, 'meta-data')) } end end def test_contains_user_data_file @server.stubs(:system).returns(true) in_a_temp_dir do |d| @server.generate_config_iso_in_dir(d, @test_data) do |iso| assert File.exist?(File.join(d, 'user-data')) assert_equal @test_data, File.read(File.join(d, 'user-data')) end end end def test_iso_is_generated in_a_temp_dir do |d| @server.expects(:system).with(regexp_matches(/^genisoimage/)).returns(true) @server.generate_config_iso_in_dir(d, @test_data) {|iso| } end end def test_volume_is_created_during_user_data_iso_generation @server.stubs(:system).returns(true) Fog::Libvirt::Compute::Volumes.any_instance.expects(:create). with(has_entries(:name => @server.cloud_init_volume_name)). returns(@compute.volumes.new) Fog::Libvirt::Compute::Volume.any_instance.stubs(:upload_image) @server.create_user_data_iso end def test_volume_is_uploaded_during_user_data_iso_generation @server.stubs(:system).returns(true) Fog::Libvirt::Compute::Volumes.any_instance.stubs(:create).returns(@compute.volumes.new) Fog::Libvirt::Compute::Volume.any_instance.expects(:upload_image).returns(true) @server.create_user_data_iso end def test_iso_file_is_set_during_user_data_iso_generation @server.stubs(:system).returns(true) Fog::Libvirt::Compute::Volumes.any_instance.stubs(:create).returns(@compute.volumes.new) Fog::Libvirt::Compute::Volume.any_instance.stubs(:upload_image) @server.create_user_data_iso assert_equal @server.cloud_init_volume_name, @server.iso_file end def test_iso_dir_is_set_during_user_data_iso_generation @server.stubs(:system).returns(true) volume = @compute.volumes.new volume.stubs(:path).returns("/srv/libvirt/#{@server.cloud_init_volume_name}") Fog::Libvirt::Compute::Volumes.any_instance.stubs(:create).returns(volume) Fog::Libvirt::Compute::Volume.any_instance.stubs(:upload_image) @server.create_user_data_iso assert_equal '/srv/libvirt', @server.iso_dir end def in_a_temp_dir Dir.mktmpdir('test-dir') do |d| yield d end end end fog-libvirt-0.14.0/minitests/test_helper.rb000066400000000000000000000006501510261170500207010ustar00rootroot00000000000000require 'minitest/autorun' require 'mocha/minitest' require 'fileutils' $: << File.join(File.dirname(__FILE__), '..', 'lib') logdir = File.join(File.dirname(__FILE__), '..', 'logs') FileUtils.mkdir_p(logdir) unless File.exist?(logdir) ENV['TMPDIR'] = 'test/tmp' FileUtils.rm_f Dir.glob 'test/tmp/*.tmp' require 'fog/libvirt' Fog.mock! Fog.credentials = { :libvirt_uri => 'test:///default', }.merge(Fog.credentials) fog-libvirt-0.14.0/tests/000077500000000000000000000000001510261170500151605ustar00rootroot00000000000000fog-libvirt-0.14.0/tests/helper.rb000066400000000000000000000011401510261170500167600ustar00rootroot00000000000000ENV['FOG_RC'] = ENV['FOG_RC'] || File.expand_path('../.fog', __FILE__) ENV['FOG_CREDENTIAL'] = ENV['FOG_CREDENTIAL'] || 'default' require 'fog/libvirt' Excon.defaults.merge!(:debug_request => true, :debug_response => true) require File.expand_path(File.join(File.dirname(__FILE__), 'helpers', 'mock_helper')) # This overrides the default 600 seconds timeout during live test runs if Fog.mocking? FOG_TESTING_TIMEOUT = ENV['FOG_TEST_TIMEOUT'] || 2000 Fog.timeout = 2000 Fog::Logger.warning "Setting default fog timeout to #{Fog.timeout} seconds" else FOG_TESTING_TIMEOUT = Fog.timeout end fog-libvirt-0.14.0/tests/helpers/000077500000000000000000000000001510261170500166225ustar00rootroot00000000000000fog-libvirt-0.14.0/tests/helpers/formats_helper.rb000066400000000000000000000070101510261170500221570ustar00rootroot00000000000000# frozen_string_literal: true require 'fog/schema/data_validator' # format related hackery # allows both true.is_a?(Fog::Boolean) and false.is_a?(Fog::Boolean) # allows both nil.is_a?(Fog::Nullable::String) and ''.is_a?(Fog::Nullable::String) module Fog module Boolean; end module Nullable module Boolean; end module Integer; end module String; end module Time; end module Float; end module Hash; end module Array; end end end [FalseClass, TrueClass].each { |klass| klass.send(:include, Fog::Boolean) } [FalseClass, TrueClass, NilClass, Fog::Boolean].each { |klass| klass.send(:include, Fog::Nullable::Boolean) } [NilClass, String].each { |klass| klass.send(:include, Fog::Nullable::String) } [NilClass, Time].each { |klass| klass.send(:include, Fog::Nullable::Time) } [Integer, NilClass].each { |klass| klass.send(:include, Fog::Nullable::Integer) } [Float, NilClass].each { |klass| klass.send(:include, Fog::Nullable::Float) } [Hash, NilClass].each { |klass| klass.send(:include, Fog::Nullable::Hash) } [Array, NilClass].each { |klass| klass.send(:include, Fog::Nullable::Array) } module Shindo # Generates a Shindo test that compares a hash schema to the result # of the passed in block returning true if they match. # # The schema that is passed in is a Hash or Array of hashes that # have Classes in place of values. When checking the schema the # value should match the Class. # # Strict mode will fail if the data has additional keys. Setting # +strict+ to +false+ will allow additional keys to appear. # # @param [Hash] schema A Hash schema # @param [Hash] options Options to change validation rules # @option options [Boolean] :allow_extra_keys # If +true+ does not fail when keys are in the data that are # not specified in the schema. This allows new values to # appear in API output without breaking the check. # @option options [Boolean] :allow_optional_rules # If +true+ does not fail if extra keys are in the schema # that do not match the data. Not recommended! # @yield Data to check with schema # # @example Using in a test # Shindo.tests("comparing welcome data against schema") do # data = {:welcome => "Hello" } # data_matches_schema(:welcome => String) { data } # end # # comparing welcome data against schema # + data matches schema # # @example Example schema # { # "id" => String, # "ram" => Integer, # "disks" => [ # { # "size" => Float # } # ], # "dns_name" => Fog::Nullable::String, # "active" => Fog::Boolean, # "created" => DateTime # } # # @return [Boolean] class Tests def data_matches_schema(schema, options = {}) test('data matches schema') do validator = Fog::Schema::DataValidator.new valid = validator.validate(yield, schema, options) @message = validator.message unless valid valid end end # @deprecated #formats is deprecated. Use #data_matches_schema instead def formats(format, strict = true) test('has proper format') do if strict options = { :allow_extra_keys => false, :allow_optional_rules => true } else options = { :allow_extra_keys => true, :allow_optional_rules => true } end validator = Fog::Schema::DataValidator.new valid = validator.validate(yield, format, options) @message = validator.message unless valid valid end end end end fog-libvirt-0.14.0/tests/helpers/formats_helper_tests.rb000066400000000000000000000070461510261170500234120ustar00rootroot00000000000000Shindo.tests('test_helper', 'meta') do tests('comparing welcome data against schema') do data = { :welcome => 'Hello' } data_matches_schema(:welcome => String) { data } end tests('#data_matches_schema') do tests('when value matches schema expectation') do data_matches_schema('key' => String) { { 'key' => 'Value' } } end tests('when values within an array all match schema expectation') do data_matches_schema('key' => [Integer]) { { 'key' => [1, 2] } } end tests('when nested values match schema expectation') do data_matches_schema('key' => { :nested_key => String }) { { 'key' => { :nested_key => 'Value' } } } end tests('when collection of values all match schema expectation') do data_matches_schema([{ 'key' => String }]) { [{ 'key' => 'Value' }, { 'key' => 'Value' }] } end tests('when collection is empty although schema covers optional members') do data_matches_schema([{ 'key' => String }], :allow_optional_rules => true) { [] } end tests('when additional keys are passed and not strict') do data_matches_schema({ 'key' => String }, :allow_extra_keys => true) { { 'key' => 'Value', :extra => 'Bonus' } } end tests('when value is nil and schema expects NilClass') do data_matches_schema('key' => NilClass) { { 'key' => nil } } end tests('when value and schema match as hashes') do data_matches_schema({}) { {} } end tests('when value and schema match as arrays') do data_matches_schema([]) { [] } end tests('when value is a Time') do data_matches_schema('time' => Time) { { 'time' => Time.now } } end tests('when key is missing but value should be NilClass (#1477)') do data_matches_schema({ 'key' => NilClass }, :allow_optional_rules => true) { {} } end tests('when key is missing but value is nullable (#1477)') do data_matches_schema({ 'key' => Fog::Nullable::String }, :allow_optional_rules => true) { {} } end end tests('#formats backwards compatible changes') do tests('when value matches schema expectation') do formats('key' => String) { { 'key' => 'Value' } } end tests('when values within an array all match schema expectation') do formats('key' => [Integer]) { { 'key' => [1, 2] } } end tests('when nested values match schema expectation') do formats('key' => { :nested_key => String }) { { 'key' => { :nested_key => 'Value' } } } end tests('when collection of values all match schema expectation') do formats([{ 'key' => String }]) { [{ 'key' => 'Value' }, { 'key' => 'Value' }] } end tests('when collection is empty although schema covers optional members') do formats([{ 'key' => String }]) { [] } end tests('when additional keys are passed and not strict') do formats({ 'key' => String }, false) { { 'key' => 'Value', :extra => 'Bonus' } } end tests('when value is nil and schema expects NilClass') do formats('key' => NilClass) { { 'key' => nil } } end tests('when value and schema match as hashes') do formats({}) { {} } end tests('when value and schema match as arrays') do formats([]) { [] } end tests('when value is a Time') do formats('time' => Time) { { 'time' => Time.now } } end tests('when key is missing but value should be NilClass (#1477)') do formats('key' => NilClass) { {} } end tests('when key is missing but value is nullable (#1477)') do formats('key' => Fog::Nullable::String) { {} } end end end fog-libvirt-0.14.0/tests/helpers/mock_helper.rb000066400000000000000000000004401510261170500214350ustar00rootroot00000000000000# Use so you can run in mock mode from the command line # # FOG_MOCK=true fog if ENV["FOG_MOCK"] == "true" Fog.mock! end # if in mocked mode, fill in some fake credentials for us if Fog.mock? Fog.credentials = { :libvirt_uri => 'test:///default', }.merge(Fog.credentials) end fog-libvirt-0.14.0/tests/helpers/succeeds_helper.rb000066400000000000000000000002321510261170500223010ustar00rootroot00000000000000module Shindo class Tests def succeeds(&block) test('succeeds') do !instance_eval(&Proc.new(&block)).nil? end end end end fog-libvirt-0.14.0/tests/libvirt/000077500000000000000000000000001510261170500166335ustar00rootroot00000000000000fog-libvirt-0.14.0/tests/libvirt/compute_tests.rb000066400000000000000000000013431510261170500220570ustar00rootroot00000000000000Shindo.tests('Fog::Compute[:libvirt]', ['libvirt']) do compute = Fog::Compute[:libvirt] tests("Compute collections") do %w{ servers interfaces networks nics nodes pools volumes}.each do |collection| test("it should respond to #{collection}") { compute.respond_to? collection } end end tests("Compute requests") do %w{ create_domain create_volume define_domain define_pool destroy_interface destroy_network get_node_info update_autostart list_domains list_interfaces list_networks list_pools list_pool_volumes list_volumes pool_action vm_action volume_action dhcp_leases }.each do |request| test("it should respond to #{request}") { compute.respond_to? request } end end end fog-libvirt-0.14.0/tests/libvirt/models/000077500000000000000000000000001510261170500201165ustar00rootroot00000000000000fog-libvirt-0.14.0/tests/libvirt/models/compute/000077500000000000000000000000001510261170500215725ustar00rootroot00000000000000fog-libvirt-0.14.0/tests/libvirt/models/compute/interface_tests.rb000066400000000000000000000016271510261170500253070ustar00rootroot00000000000000Shindo.tests('Fog::Compute[:libvirt] | interface model', ['libvirt']) do interfaces = Fog::Compute[:libvirt].interfaces interface = interfaces.last tests('The interface model should') do tests('have the action') do test('reload') { interface.respond_to? 'reload' } end tests('have attributes') do model_attribute_hash = interface.attributes attributes = [ :name, :mac, :active] tests("The interface model should respond to") do attributes.each do |attribute| test("#{attribute}") { interface.respond_to? attribute } end end tests("The attributes hash should have key") do attributes.each do |attribute| test("#{attribute}") { model_attribute_hash.key? attribute } end end end test('be a kind of Fog::Libvirt::Compute::Interface') { interface.kind_of? Fog::Libvirt::Compute::Interface } end end fog-libvirt-0.14.0/tests/libvirt/models/compute/interfaces_tests.rb000066400000000000000000000010771510261170500254710ustar00rootroot00000000000000Shindo.tests('Fog::Compute[:libvirt] | interfaces collection', ['libvirt']) do interfaces = Fog::Compute[:libvirt].interfaces tests('The interfaces collection') do test('should not be empty') { not interfaces.empty? } test('should be a kind of Fog::Libvirt::Compute::Interfaces') { interfaces.kind_of? Fog::Libvirt::Compute::Interfaces } tests('should be able to reload itself').succeeds { interfaces.reload } tests('should be able to get a model') do tests('by instance name').succeeds { interfaces.get interfaces.first.name } end end end fog-libvirt-0.14.0/tests/libvirt/models/compute/network_tests.rb000066400000000000000000000025651510261170500250420ustar00rootroot00000000000000Shindo.tests('Fog::Compute[:libvirt] | network model', ['libvirt']) do networks = Fog::Compute[:libvirt].networks network = networks.first tests('The network model should') do tests('have the action') do test('reload') { network.respond_to? 'reload' } test('dhcp_leases') { network.respond_to? 'dhcp_leases' } end tests('have a dhcp_leases action that') do test('returns an array') { network.dhcp_leases('aa:bb:cc:dd:ee:ff', 0).kind_of? Array } end tests('have attributes') do model_attribute_hash = network.attributes attributes = [ :name, :uuid, :bridge_name] tests("The network model should respond to") do attributes.each do |attribute| test("#{attribute}") { network.respond_to? attribute } end end tests("The attributes hash should have key") do attributes.each do |attribute| test("#{attribute}") { model_attribute_hash.key? attribute } end end end test('be a kind of Fog::Libvirt::Compute::Network') { network.kind_of? Fog::Libvirt::Compute::Network } end tests("to_xml") do test("default") do expected = <<~NETWORK default NETWORK network.to_xml == expected end end end fog-libvirt-0.14.0/tests/libvirt/models/compute/networks_tests.rb000066400000000000000000000007571510261170500252260ustar00rootroot00000000000000Shindo.tests('Fog::Compute[:libvirt] | networks collection', ['libvirt']) do networks = Fog::Compute[:libvirt].networks tests('The networks collection') do test('should be a kind of Fog::Libvirt::Compute::Networks') { networks.kind_of? Fog::Libvirt::Compute::Networks } tests('should be able to reload itself').succeeds { networks.reload } tests('should be able to get a model') do tests('by instance id').succeeds { networks.get networks.first.uuid } end end end fog-libvirt-0.14.0/tests/libvirt/models/compute/nic_tests.rb000066400000000000000000000017301510261170500241130ustar00rootroot00000000000000Shindo.tests('Fog::Compute[:libvirt] | nic model', ['libvirt']) do server = Fog::Compute[:libvirt].servers.create(:name => Fog::Mock.random_letters(8)) nic = server.nics.first tests('The nic model should') do tests('have the action') do test('reload') { nic.respond_to? 'reload' } end tests('have attributes') do model_attribute_hash = nic.attributes attributes = [ :mac, :model, :type, :network, :bridge] tests("The nic model should respond to") do attributes.each do |attribute| test("#{attribute}") { nic.respond_to? attribute } end end tests("The attributes hash should have key") do attributes.delete(:bridge) attributes.each do |attribute| test("#{attribute}") { model_attribute_hash.key? attribute } end end end test('be a kind of Fog::Libvirt::Compute::Nic') { nic.kind_of? Fog::Libvirt::Compute::Nic } end end fog-libvirt-0.14.0/tests/libvirt/models/compute/nics_tests.rb000066400000000000000000000004351510261170500242770ustar00rootroot00000000000000Shindo.tests('Fog::Compute[:libvirt] | nics collection', ['libvirt']) do nics = Fog::Compute[:libvirt].servers.first.nics tests('The nics collection') do test('should not be empty') { not nics.empty? } test('should be a kind of Array') { nics.kind_of? Array } end end fog-libvirt-0.14.0/tests/libvirt/models/compute/pool_tests.rb000066400000000000000000000016601510261170500243150ustar00rootroot00000000000000Shindo.tests('Fog::Compute[:libvirt] | interface model', ['libvirt']) do pools = Fog::Compute[:libvirt].pools pool = pools.last tests('The interface model should') do tests('have the action') do test('reload') { pool.respond_to? 'reload' } end tests('have attributes') do model_attribute_hash = pool.attributes attributes = [ :uuid, :name, :persistent, :active, :autostart, :allocation, :capacity, :num_of_volumes, :state] tests("The interface model should respond to") do attributes.each do |attribute| test("#{attribute}") { pool.respond_to? attribute } end end tests("The attributes hash should have key") do attributes.each do |attribute| test("#{attribute}") { model_attribute_hash.key? attribute } end end end test('be a kind of Fog::Libvirt::Compute::Pool') { pool.kind_of? Fog::Libvirt::Compute::Pool } end end fog-libvirt-0.14.0/tests/libvirt/models/compute/pools_tests.rb000066400000000000000000000010021510261170500244660ustar00rootroot00000000000000Shindo.tests('Fog::Compute[:libvirt] | pools request', ['libvirt']) do pools = Fog::Compute[:libvirt].pools tests('The pools collection') do test('should not be empty') { not pools.empty? } test('should be a kind of Fog::Libvirt::Compute::Pools') { pools.kind_of? Fog::Libvirt::Compute::Pools } tests('should be able to reload itself').succeeds { pools.reload } tests('should be able to get a model') do tests('by instance id').succeeds { pools.get pools.first.uuid } end end end fog-libvirt-0.14.0/tests/libvirt/models/compute/server_tests.rb000066400000000000000000000106401510261170500246500ustar00rootroot00000000000000Shindo.tests('Fog::Compute[:libvirt] | server model', ['libvirt']) do servers = Fog::Compute[:libvirt].servers # Match the mac in dhcp_leases mock nics = Fog.mock? ? [{ :type => 'network', :network => 'default', :mac => 'aa:bb:cc:dd:ee:ff' }] : nil server = servers.create(:name => Fog::Mock.random_letters(8), :nics => nics) tests('The server model should') do tests('have the action') do test('autostart') { server.respond_to? 'autostart' } test('update_autostart') { server.respond_to? 'update_autostart' } test('reload') { server.respond_to? 'reload' } %w{ start stop destroy reboot suspend }.each do |action| test(action) { server.respond_to? action } end %w{ start reboot suspend stop }.each do |action| test("#{action} returns successfully") { begin server.send(action.to_sym) rescue Libvirt::Error #libvirt error is acceptable for the above actions. true end } end end tests('have an ip_address action that') do test('returns the latest IP address lease') { server.public_ip_address() == '1.2.5.6' } end tests('have attributes') do model_attribute_hash = server.attributes attributes = [ :id, :cpus, :cputime, :firmware, :firmware_features, :secure_boot, :loader_attributes, :os_type, :memory_size, :max_memory_size, :name, :arch, :persistent, :domain_type, :uuid, :autostart, :display, :nics, :volumes, :active, :boot_order, :hugepages, :state] tests("The server model should respond to") do attributes.each do |attribute| test("#{attribute}") { server.respond_to? attribute } end end tests("The attributes hash should have key") do attributes.delete(:volumes) attributes.each do |attribute| test("#{attribute}") { model_attribute_hash.key? attribute } end end end test('can destroy') do servers.create(:name => Fog::Mock.random_letters(8)).destroy end test('be a kind of Fog::Libvirt::Compute::Server') { server.kind_of? Fog::Libvirt::Compute::Server } tests("serializes to xml") do test("without firmware") { server.to_xml.include?("") } test("with memory") { server.to_xml.match?(%r{\d+}) } test("with disk of type file") do xml = server.to_xml xml.match?(//) && xml.match?(%r{}) end test("with disk of type block") do server = Fog::Libvirt::Compute::Server.new( { :nics => [], :volumes => [ Fog::Libvirt::Compute::Volume.new({ :path => "/dev/sda", :pool_name => "dummy" }) ] } ) xml = server.to_xml xml.match?(//) && xml.match?(%r{}) end test("with q35 machine type on x86_64") { server.to_xml.match?(%r{hvm}) } end test("with efi firmware") do server = Fog::Libvirt::Compute::Server.new( { :firmware => "efi", :nics => [], :volumes => [] } ) xml = server.to_xml os_firmware = xml.include?('') secure_boot = xml.include?('') loader_attributes = !xml.include?('') os_firmware && secure_boot && loader_attributes end test("with secure boot enabled") do server = Fog::Libvirt::Compute::Server.new( { :firmware => "efi", :firmware_features => { "secure-boot" => "yes", "enrolled-keys" => "yes" }, :loader_attributes => { "secure" => "yes" }, :nics => [], :volumes => [] } ) xml = server.to_xml os_firmware = xml.include?('') secure_boot = xml.include?('') enrolled_keys = xml.include?('') loader_attributes = xml.include?('') os_firmware && secure_boot && enrolled_keys && loader_attributes end end end fog-libvirt-0.14.0/tests/libvirt/models/compute/servers_tests.rb000066400000000000000000000010341510261170500250300ustar00rootroot00000000000000Shindo.tests('Fog::Compute[:libvirt] | servers collection', ['libvirt']) do servers = Fog::Compute[:libvirt].servers tests('The servers collection') do test('should not be empty') { not servers.empty? } test('should be a kind of Fog::Libvirt::Compute::Servers') { servers.kind_of? Fog::Libvirt::Compute::Servers } tests('should be able to reload itself').succeeds { servers.reload } tests('should be able to get a model') do tests('by instance uuid').succeeds { servers.get servers.first.id } end end end fog-libvirt-0.14.0/tests/libvirt/models/compute/volume_tests.rb000066400000000000000000000033631510261170500246550ustar00rootroot00000000000000Shindo.tests('Fog::Compute[:libvirt] | volume model', ['libvirt']) do volume = Fog::Compute[:libvirt].volumes.create(:name => 'fog_test') tests('The volume model should') do tests('have attributes') do model_attribute_hash = volume.attributes attributes = [ :id, :pool_name, :key, :name, :path, :capacity, :allocation, :format_type] tests("The volume model should respond to") do attributes.each do |attribute| test("#{attribute}") { volume.respond_to? attribute } end end tests("The attributes hash should have key") do attributes.each do |attribute| test("#{attribute}") { model_attribute_hash.key? attribute } end end end test('be a kind of Fog::Libvirt::Compute::Volume') { volume.kind_of? Fog::Libvirt::Compute::Volume } end tests('Cloning volumes should') do test('respond to clone_volume') { volume.respond_to? :clone_volume } new_vol = volume.clone_volume('new_vol') # We'd like to test that the :name attr has changed, but it seems that's # not possible, so we can at least check the new_vol xml exists properly test('succeed') { volume.xml == new_vol.xml } end test('to_xml') do test('default') do expected = <<~VOLUME fog_test 1 10 0744 VOLUME volume.to_xml == expected end end end fog-libvirt-0.14.0/tests/libvirt/models/compute/volumes_tests.rb000066400000000000000000000012261510261170500250340ustar00rootroot00000000000000Shindo.tests('Fog::Compute[:libvirt] | volumes collection', ['libvirt']) do volumes = Fog::Compute[:libvirt].volumes volumes.create(:name => 'test') tests('The volumes collection') do test('should not be empty') { not volumes.empty? } test('should be a kind of Fog::Libvirt::Compute::Volumes') { volumes.kind_of? Fog::Libvirt::Compute::Volumes } tests('should be able to reload itself').succeeds { volumes.reload } tests('should be able to get a model') do tests('by instance uuid').succeeds { volumes.get volumes.first.id } end test('filtered should be empty') { volumes.all(:name => "does-not-exist").empty? } end end fog-libvirt-0.14.0/tests/libvirt/requests/000077500000000000000000000000001510261170500205065ustar00rootroot00000000000000fog-libvirt-0.14.0/tests/libvirt/requests/compute/000077500000000000000000000000001510261170500221625ustar00rootroot00000000000000fog-libvirt-0.14.0/tests/libvirt/requests/compute/create_domain_tests.rb000066400000000000000000000013251510261170500265240ustar00rootroot00000000000000Shindo.tests("Fog::Compute[:libvirt] | create_domain request", 'libvirt') do compute = Fog::Compute[:libvirt] xml = compute.servers.new( :nics => [{:bridge => "br180"}]).to_xml tests("Create Domain") do response = compute.create_domain(xml) test("should be a kind of Libvirt::Domain") { response.kind_of? Libvirt::Domain} end tests("Fail Creating Domain") do begin response = compute.create_domain(xml) test("should be a kind of Libvirt::Domain") { response.kind_of? Libvirt::Domain} #mock never raise exceptions rescue => e #should raise vm name already exist exception. test("error should be a kind of Libvirt::Error") { e.kind_of? Libvirt::Error} end end end fog-libvirt-0.14.0/tests/libvirt/requests/compute/define_domain_tests.rb000066400000000000000000000004761510261170500265210ustar00rootroot00000000000000Shindo.tests("Fog::Compute[:libvirt] | define_domain request", 'libvirt') do compute = Fog::Compute[:libvirt] xml = compute.servers.new().to_xml tests("Define Domain") do response = compute.define_domain(xml) test("should be a kind of Libvirt::Domain") { response.kind_of? Libvirt::Domain} end end fog-libvirt-0.14.0/tests/libvirt/requests/compute/dhcp_leases_tests.rb000066400000000000000000000011251510261170500262020ustar00rootroot00000000000000Shindo.tests("Fog::Compute[:libvirt] | dhcp_leases request", 'libvirt') do compute = Fog::Compute[:libvirt] tests("DHCP leases response") do response = compute.dhcp_leases("fbd4ac68-cbea-4f95-86ed-22953fd92384", "99:88:77:66:55:44", 0) test("should be an array") { response.kind_of? Array } test("should have one element") { response.length == 1 } test("should have dict elements") { response[0].kind_of? Hash } ["ipaddr", "prefix", "expirytime", "type"].each { |k| test("should have dict elements with required key #{k}") { !response[0][k].nil? } } end end fog-libvirt-0.14.0/tests/libvirt/requests/compute/list_pools_tests.rb000066400000000000000000000030321510261170500261160ustar00rootroot00000000000000class FakePool < Fog::Model # Fake pool object to allow exercising the internal parsing of pools # returned by the client queries identity :uuid attribute :persistent attribute :autostart attribute :active attribute :name attribute :num_of_volumes attr_reader :info class FakeInfo < Fog::Model attribute :allocation attribute :capacity attribute :state end def initialize(attributes = {}) @info = FakeInfo.new(attributes.dup.delete(:info)) super(attributes) end def active? active end def autostart? autostart end def persistent? persistent end end Shindo.tests("Fog::Compute[:libvirt] | list_pools request", 'libvirt') do compute = Fog::Compute[:libvirt] tests("Lists Pools") do response = compute.list_pools test("should be an array") { response.kind_of? Array } test("should have two pools") { response.length == 1 } end tests("Handle Inactive Pools") do inactive_pool = { :uuid => 'pool.uuid', :persistent => true, :autostart => true, :active => false, :name => 'inactive_pool1', :info => { :allocation => 123456789, :capacity => 123456789, :state => 2 # running }, :num_of_volumes => 3 } response = compute.send(:pool_to_attributes, FakePool.new(inactive_pool), true) test("should be hash of attributes") { response.kind_of? Hash } response = compute.send(:pool_to_attributes, FakePool.new(inactive_pool)) test("should be nil") { response.nil? } end end fog-libvirt-0.14.0/tests/libvirt/requests/compute/update_autostart_tests.rb000066400000000000000000000005441510261170500273240ustar00rootroot00000000000000Shindo.tests('Fog::Compute[:libvirt] | update_autostart request', ['libvirt']) do servers = Fog::Compute[:libvirt].servers tests('The response should') do test('should not be empty') { not servers.empty? } server = servers.first tests('should be false').succeeds { server.autostart == false } server.update_autostart(true) end end fog-libvirt-0.14.0/tests/libvirt/requests/compute/update_display.rb000066400000000000000000000006131510261170500255160ustar00rootroot00000000000000Shindo.tests('Fog::Compute[:libvirt] | update_display request', ['libvirt']) do compute = Fog::Compute[:libvirt] reconfig_target = 'f74d728a-5b62-7e2f-1f84-239aead298ca' display_spec = {:password => 'ssaaa'} tests('The response should') do response = compute.update_display(:uuid => reconfig_target).merge(display_spec) test('should be true').succeeds { response } end end