예제 #1
0
def update_filesystem(module, filesystem):
    """Update Filesystem"""
    changed = False
    if module.params['size']:
        size = Capacity(module.params['size']).roundup(64 * KiB)
        if filesystem.get_size() != size:
            if not module.check_mode:
                filesystem.update_size(size)
            changed = True
    return changed
예제 #2
0
def main():
    argument_spec = infinibox_argument_spec()
    argument_spec.update(
        dict(
            name=dict(required=True),
            state=dict(default='present', choices=['present', 'absent']),
            size=dict(),
            vsize=dict(),
            ssd_cache=dict(type='bool', default=True)
        )
    )

    module = AnsibleModule(argument_spec, supports_check_mode=True)

    if not HAS_INFINISDK:
        module.fail_json(msg=missing_required_lib('infinisdk'))
    if not HAS_CAPACITY:
        module.fail_json(msg=missing_required_lib('capacity'), exception=CAPACITY_IMP_ERR)

    if module.params['size']:
        try:
            Capacity(module.params['size'])
        except Exception:
            module.fail_json(msg='size (Physical Capacity) should be defined in MB, GB, TB or PB units')

    if module.params['vsize']:
        try:
            Capacity(module.params['vsize'])
        except Exception:
            module.fail_json(msg='vsize (Virtual Capacity) should be defined in MB, GB, TB or PB units')

    state = module.params['state']
    system = get_system(module)
    pool = get_pool(module, system)

    if state == 'present' and not pool:
        create_pool(module, system)
    elif state == 'present' and pool:
        update_pool(module, system, pool)
    elif state == 'absent' and pool:
        delete_pool(module, pool)
    elif state == 'absent' and not pool:
        module.exit_json(changed=False)
예제 #3
0
def create_filesystem(module, system):
    """Create Filesystem"""
    changed = True
    if not module.check_mode:
        filesystem = system.filesystems.create(name=module.params['name'],
                                               pool=get_pool(module, system))
        if module.params['size']:
            size = Capacity(module.params['size']).roundup(64 * KiB)
            filesystem.update_size(size)
    return changed
def update_volume(module, volume):
    """Update Volume"""
    changed = False
    if module.params['size']:
        size = Capacity(module.params['size']).roundup(64 * KiB)
        if volume.get_size() != size:
            if not module.check_mode:
                volume.update_size(size)
            changed = True

    module.exit_json(changed=changed)
 def __init__(self, json_struct=None):
     self.requestedCapacity = Capacity()  #import
     self.latencyCharacteristic = KeyedArrayType(LatencyCharacteristic,
                                                 'trafficPropertyName')
     self._srcServiceEndPoint = ""
     self.serviceLevel = ""
     self.costCharacteristic = KeyedArrayType(CostCharacteristic,
                                              'costName')
     self.serviceLayer = ArrayType.factory(str)
     self._diversityExclusion = ArrayType.factory(str)
     self._sinkServiceEndPoint = ""
     super(VirtualNetworkConstraint, self).__init__(json_struct)
예제 #6
0
def create_pool(module, system):
    """Create Pool"""
    name = module.params['name']
    size = module.params['size']
    vsize = module.params['vsize']
    ssd_cache = module.params['ssd_cache']

    if not module.check_mode:
        if not size and not vsize:
            pool = system.pools.create(name=name, physical_capacity=Capacity('1TB'), virtual_capacity=Capacity('1TB'))
        elif size and not vsize:
            pool = system.pools.create(name=name, physical_capacity=Capacity(size), virtual_capacity=Capacity(size))
        elif not size and vsize:
            pool = system.pools.create(name=name, physical_capacity=Capacity('1TB'), virtual_capacity=Capacity(vsize))
        else:
            pool = system.pools.create(name=name, physical_capacity=Capacity(size), virtual_capacity=Capacity(vsize))
        # Default value of ssd_cache is True. Disable ssd chacing if False
        if not ssd_cache:
            pool.update_ssd_enabled(ssd_cache)

    module.exit_json(changed=True)
예제 #7
0
def main():
    argument_spec = infinibox_argument_spec()
    argument_spec.update(
        dict(
            name=dict(required=True),
            state=dict(default='present',
                       choices=['stat', 'present', 'absent']),
            size=dict(),
            vsize=dict(),
            ssd_cache=dict(type='bool', default=True),
            compression=dict(type='bool', default=True),
        ))

    module = AnsibleModule(argument_spec, supports_check_mode=True)

    if not HAS_INFINISDK:
        module.fail_json(msg=missing_required_lib('infinisdk'))
    if not HAS_CAPACITY:
        module.fail_json(msg=missing_required_lib('capacity'),
                         exception=CAPACITY_IMP_ERR)

    if module.params['size']:
        try:
            Capacity(module.params['size'])
        except Exception:
            module.fail_json(
                msg=
                'size (Physical Capacity) should be defined in MB, GB, TB or PB units'
            )

    if module.params['vsize']:
        try:
            Capacity(module.params['vsize'])
        except Exception:
            module.fail_json(
                msg=
                'vsize (Virtual Capacity) should be defined in MB, GB, TB or PB units'
            )

    execute_state(module)
 def __init__(self, json_struct=None):
     self.pathLayer = ArrayType.factory(str)
     self._excludePath = KeyedArrayType(TeLink, 'localId')
     self._includePath = KeyedArrayType(TeLink, 'localId')
     self.requestedCapacity = Capacity()  #import
     self.costCharacteristic = KeyedArrayType(CostCharacteristic,
                                              'costName')
     self._avoidTopology = ArrayType.factory(str)
     self.latencyCharacteristic = KeyedArrayType(LatencyCharacteristic,
                                                 'trafficPropertyName')
     self.serviceLevel = ""
     self._includeTopology = ArrayType.factory(str)
     super(RoutingConstraint, self).__init__(json_struct)
예제 #9
0
def update_pool(module, system, pool):
    """Update Pool"""
    changed = False

    size = module.params['size']
    vsize = module.params['vsize']
    #ssd_cache = module.params['ssd_cache']
    compression = module.params['compression']

    # Roundup the capacity to mimic Infinibox behaviour
    if size:
        physical_capacity = Capacity(size).roundup(6 * 64 * KiB)
        if pool.get_physical_capacity() != physical_capacity:
            if not module.check_mode:
                pool.update_physical_capacity(physical_capacity)
            changed = True

    if vsize:
        virtual_capacity = Capacity(vsize).roundup(6 * 64 * KiB)
        if pool.get_virtual_capacity() != virtual_capacity:
            if not module.check_mode:
                pool.update_virtual_capacity(virtual_capacity)
            changed = True

    #if pool.is_ssd_enabled() != ssd_cache:
    #    if not module.check_mode:
    #        pool.update_ssd_enabled(ssd_cache)
    #    changed = True

    if pool.is_compression_enabled() != compression:
        if not module.check_mode:
            pool.update_compression_enabled(compression)
        changed = True

    if changed:
        msg = 'Pool updated'
    else:
        msg = 'Pool did not require updating'
    module.exit_json(changed=changed, msg=msg)
예제 #10
0
def create_volume(module, system):
    """Create Volume"""
    if not module.check_mode:
        if module.params['thin_provision']:
            prov_type = 'THIN'
        else:
            prov_type = 'THICK'
        pool = get_pool(module, system)
        volume = system.volumes.create(name=module.params['name'], provtype=prov_type, pool=pool)

        if module.params['size']:
            size = Capacity(module.params['size']).roundup(64 * KiB)
            volume.update_size(size)
    changed = True
    return changed
예제 #11
0
def main():
    argument_spec = infinibox_argument_spec()
    argument_spec.update(
        dict(name=dict(required=True),
             state=dict(default='present', choices=['present', 'absent']),
             pool=dict(required=True),
             size=dict()))

    module = AnsibleModule(argument_spec, supports_check_mode=True)

    if not HAS_INFINISDK:
        module.fail_json(msg=missing_required_lib('infinisdk'))
    if not HAS_CAPACITY:
        module.fail_json(msg=missing_required_lib('capacity'),
                         exception=CAPACITY_IMP_ERR)

    if module.params['size']:
        try:
            Capacity(module.params['size'])
        except Exception:
            module.fail_json(
                msg=
                'size (Physical Capacity) should be defined in MB, GB, TB or PB units'
            )

    state = module.params['state']
    system = get_system(module)
    pool = get_pool(module, system)
    filesystem = get_filesystem(module, system)

    if pool is None:
        module.fail_json(
            msg='Pool {0} not found'.format(module.params['pool']))

    if state == 'present' and not filesystem:
        create_filesystem(module, system)
    elif state == 'present' and filesystem:
        update_filesystem(module, filesystem)
    elif state == 'absent' and filesystem:
        delete_filesystem(module, filesystem)
    elif state == 'absent' and not filesystem:
        module.exit_json(changed=False)
예제 #12
0
def update_volume(module, volume):
    """Update Volume"""
    changed = False
    if module.params['size']:
        size = Capacity(module.params['size']).roundup(64 * KiB)
        if volume.get_size() != size:
            if not module.check_mode:
                volume.update_size(size)
            changed = True
    if module.params['thin_provision'] is not None:
        type = str(volume.get_provisioning())
        if type == 'THICK' and module.params['thin_provision']:
            if not module.check_mode:
                volume.update_provisioning('THIN')
            changed = True
        if type == 'THIN' and not module.params['thin_provision']:
            if not module.check_mode:
                volume.update_provisioning('THICK')
            changed = True
    return changed
예제 #13
0
def main():
    module = AnsibleModule(argument_spec=dict(
        name=dict(required=True),
        state=dict(default='present', choices=['present', 'absent']),
        pool=dict(required=True),
        size=dict(),
        system=dict(required=True),
        user=dict(no_log=True),
        password=dict(no_log=True),
    ),
                           supports_check_mode=False)

    if not HAS_INFINISDK:
        module.fail_json(msg='infinisdk is required for this module')

    if module.params['size']:
        try:
            Capacity(module.params['size'])
        except:
            module.fail_json(
                msg=
                'size (Physical Capacity) should be defined in MB, GB, TB or PB units'
            )

    state = module.params['state']
    system = get_system(module)
    pool = get_pool(module, system)
    volume = get_volume(module, system)

    if pool is None:
        module.fail_json(msg='Pool {} not found'.format(module.params['pool']))

    if state == 'present' and not volume:
        create_volume(module, system)
    elif state == 'present' and volume:
        update_volume(module, volume)
    elif state == 'absent' and volume:
        delete_volume(module, volume)
    elif state == 'absent' and not volume:
        module.exit_json(changed=False)
예제 #14
0
def test_from_string_construction():
    assert Capacity('20*GiB') == (20 * GiB)
예제 #15
0
 def __init__(self, json_struct=None):
     self.capacityAssignedToUserView=KeyedArrayType(Capacity, 'totalSize')
     self.availableCapacity=Capacity() #import
     self.totalPotentialCapacity=Capacity() #import
     self.capacityInteractionAlgorithm=""
     super(TransferCapacityPac, self).__init__(json_struct)
예제 #16
0
def test_add():
    assert (MiB + MiB) == Capacity((MiB.bits * 2))
    assert (MiB + 0) == MiB
    assert (0 + MiB) == MiB
예제 #17
0
class Payment(object):
    def __init__(self, two_wheeler_price, four_wheeler_price, time):
        self.charge = Charge(two_wheeler_price, four_wheeler_price)
        self.time = time

    def amount(self):
        return self.charge.two_wheeler_price * self.time


p = Payment(12, 25, 5)
print(p.amount())

print(vars(p))


capacity = Capacity(10, 13)


class Booking(object):

    _count = capacity

    def __init__(self, v_type, reg_number):
        self._vechile = Vehicle(v_type, reg_number)

    def __new__(cls, v_type, req_number):
        if v_type == 'two_wheeler':
            if cls._count._two_wheeler < 1:
                print("No space available  for two wheeler sorry !!!!")
            else:
                cls._count._two_wheeler -= 1
예제 #18
0
# Input data
# ==========
graph_to_study = input("Choose graph to study: F1, F2 or F3? ")


# Load graph
# ==========
filename = "data/" + graph_to_study + ".txt"
edges = GraphFile(filename).read_edges_from_file()
F = Graph(edges)

# Get edges capacity
# ==================
nodes_capacity = GraphFile("data/nodes_capacity.txt").read_nodes_capacity_from_file()
C = Capacity(nodes_capacity, 'i', 'f')
C_edges = C.get_edges_capacity(F, "weight")

for k,v in C_edges.items():
    if ("i" in k) or ("f" in k):
        pass 
    else:
        C_edges[k] = int(v)
        
C_edges = {k:v for k,v in C_edges.items() if v > 0}



# Flow Network
# ============
flow_network = Graph(C_edges.copy())
from fordfulkerson import FordFulkerson
import string


# Load edges
# ==========
filename = "data/manufacturing_data.txt"
edges = readwrite.read_edges_from_file(filename)
G = Graph(edges)


# Get edges capacity
# ==================
filename = "data/nodes_capacity.txt"
nodes_capacity = readwrite.read_nodes_capacity_from_file(filename)
C = Capacity(nodes_capacity, source_node='source', sink_node='sink')
C_edges = C.get_edges_capacity(G, "weight")


# Flow Network
# ============
flow_network = Graph(C_edges.copy())

antiparallel_edges = flow_network.find_antiparallel_edges()
counter = 0
while len(antiparallel_edges) > 0:
    edge = antiparallel_edges.pop(0)
    anti = (edge[1],edge[0])
    antiparallel_edges.remove( anti )
    w = flow_network.edges[anti]
    flow_network.deleteEdge(anti[0], anti[1])
예제 #20
0
    def __init__(self, texture, capacity):

        self.rules = Ruler()
        self.texture = Texture(texture)
        self.capacity = Capacity(capacity)
예제 #21
0
def test_sub():
    assert (MiB - bit) == Capacity((MiB.bits - 1))
    assert (0 - bit) == (-bit)
    assert (bit - 0) == bit
예제 #22
0
def test_mul():
    assert (2 * MiB) == Capacity((MiB.bits * 2))
    assert (0 * MiB) == Capacity(0)
예제 #23
0
def test_from_string_fractions():
    assert Capacity('1119.63 * TB') == (1119630 * GB)