Beruflich Dokumente
Kultur Dokumente
#
#
#
#
#
#
#
#
#
import socket,struct
class Example(object):
def address_in_network(self,ip, net):
ip_addr = struct.unpack('<L', socket.inet_aton(ip))[0]
net, bits = net.split('/')
net_addr = struct.unpack('<L', socket.inet_aton(net))[0]
netmask = ((1L << int(bits)) - 1)
return ip_addr & netmask == net_addr & netmask
def get_all_pools(self):
# List all pools.
# Returns a list of pool uids, or [] if no pools
# [
# <pool uid 1>,
# <pool uid 2>,
# ...
# ]
pass
def get_pool(self, uid):
# Get the contents of a specific pool by uid.
# Returns a dict of pool attributes:
# {
# 'active': <integer enumerating state>,
# 'datasource_id': <datasource uid>,
# 'managed': <boolean indicating managed status>,
# 'name': <string describing the pool>,
# 'uid': <pool uid>
# }
pass
def get_datasource(self, uid):
# Get the contents of a specific datasource by uid.
# Returns a dict of datasource attributes:
# {
# 'search_order': <integer>,
# 'type': 'DS',
# 'uid': <datasource uid>,
# 'name': <string describing the datasource>,
# 'properties': <property list (see below)>
# }
# Where property list is an *unordered list* of key-value pairs (not
# a dictionary) as follows:
# [
# ['master_address_1', <ip address as string>],
#
# For example, passing {'managed': True, 'active': 3} might
# return [10, 1234, 5555, 678], where each pool with that uid is
# both managed and inactive. Passing {} would return all pool uuids.
uid_list=[]
if not desc:
return uid_list
pools = self.get_all_pools()
for pool_id in pools:
pool = self.get_pool(pool_id)
if len(pool.viewitems() & desc.viewitems()) == len(desc.items()):
uid_list.append(pool['uid'])
return uid_list