Git Product home page Git Product logo

ansible-filter-plugin-parted-bytes-formatters's Introduction

Ansible formatters filter plugins for parted

Adds two filter plugins:

  • parted_human_readable
  • parted_human_to_bytes

History

These plugins are used to convert partition size in bytes to parted-compatable format.

Parted (as its Ansible module wrapper) supports both Kilobytes (SI prefix) and Kibibytes.
Ansible considers GB a Gibibyte while Parted interprets is as a Gigabyte.
Also Parted is case-sensitive and doesn't support space separator for taken values.

Code is based on official Ansible filters for size convertions.

Installation

Common for custom Ansible filter plugins.

Use

Parted Human Readable

Asserts whether the given string is human readable or not.

For example:

- name: "Parted Human Readable"
  assert:
    that:
      - '"1.00 Bytes" == 1|parted_human_readable'
      - '"1.00 bits" == 1|parted_human_readable(isbits=True)'
      - '"10.00 KB" == 10000|parted_human_readable'
      - '"97.66 MB" == 97660000|parted_human_readable'
      - '"0.10 GB" == 100000000|parted_human_readable(unit="G")'
      - '"0.10 Gb" == 100000000|parted_human_readable(isbits=True, unit="G")'
      - '"10.00 KiB" == 10240|parted_human_readable(iskibi=True)'
      - '"97.66 MiB" == 102400000|parted_human_readable(iskibi=True)'
      - '"0.10 GiB" == 107374182|parted_human_readable(iskibi=True, unit="Gi")'
      - '"0.10 Gib" == 107374182|parted_human_readable(iskibi=True, isbits=True, unit="Gi")'
      - '"0.10GiB" == 107374182|parted_human_readable(iskibi=True, unit="Gi", spaceseparator=False)'

This would result in:

{ "changed": false, "msg": "All assertions passed" }

Parted Human to Bytes

Returns the given string in the Bytes format.

For example:

- name: "Parted Human to Bytes"
  assert:
    that:
      - "{{'0'|parted_human_to_bytes}}        == 0"
      - "{{'0.1'|parted_human_to_bytes}}      == 0"
      - "{{'0.9'|parted_human_to_bytes}}      == 1"
      - "{{'1'|parted_human_to_bytes}}        == 1"
      - "{{'10.00 KB'|parted_human_to_bytes}} == 10000"
      - "{{   '11 MB'|parted_human_to_bytes}} == 11000000"
      - "{{  '1.1 GB'|parted_human_to_bytes}} == 1100000000"
      - "{{'10.00 Kib'|parted_human_to_bytes(iskibi=True, isbits=True)}} == 10240"
      - "{{'10.00 KiB'|parted_human_to_bytes(iskibi=True)}} == 10240"
      - "{{   '11 MiB'|parted_human_to_bytes(iskibi=True)}} == 11534336"
      - "{{  '1.1 GiB'|parted_human_to_bytes(iskibi=True)}} == 1181116006"

This would result in:

{ "changed": false, "msg": "All assertions passed" }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.