示例#1
0
文件: vm.py 项目: project-fifo/pyfi
def backups_list(args):
    l = args.endpoint.list_backups(args.vmuuid)
    l = sorted(l, key=lambda e: d(e, ['timestamp'], 0))
    if args.H:
        header(args)
    fmt = mk_fmt_str(args)
    for e in l:
        if not e:
            print('error!')
            exit(1)
        l = mk_fmt_line(args, e)
        if args.p:
            print(':'.join(l))
        else:
            print(fmt%tuple(l))
示例#2
0
def backups_list(args):
    l = args.endpoint.list_backups(args.vmuuid)
    l = sorted(l, key=lambda e: d(e, ['timestamp'], 0))
    if args.H:
        header(args)
    fmt = mk_fmt_str(args)
    for e in l:
        if not e:
            print('error!')
            exit(1)
        l = mk_fmt_line(args, e)
        if args.p:
            print(':'.join(l))
        else:
            print(fmt % tuple(l))
示例#3
0
文件: vm.py 项目: project-fifo/pyfi
 def name_of(self, obj):
     return d(obj, ['config', 'alias'])
示例#4
0
文件: vm.py 项目: project-fifo/pyfi
    return(vm['info'])

def vm_metadata_map_fn(vm):
    return(vm['metadata'])

# Returns the ip of a vm (first ip in the networks)
def vm_ip(e):
    n = d(e, ['config', 'networks'], [])
    if len(n) > 0:
        return n[0]['ip']
    else:
        return '-'

vm_fmt = {
    'uuid':
    {'title': 'UUID', 'len': 36, 'fmt': '%36s', 'get': lambda e: d(e, ['uuid'])},
    'alias':
    {'title': 'alias', 'len': 10, 'fmt': '%-10s', 'get': lambda e: d(e, ['config', 'alias'])},
    'ip':
    {'title': 'IP', 'len': 15, 'fmt': '%15s', 'get': vm_ip},
    'state':
    {'title': 'state', 'len': 15, 'fmt': '%-15s', 'get': lambda e: d(e, ['state'])},
    'hypervisor':
    {'title': 'hypervisor', 'len': 20, 'fmt': '%-20s', 'get': lambda e: d(e, ['hypervisor'])},
    'package':
    {'title': 'package', 'len': 36, 'fmt': '%36s', 'get': lambda e: d(e, ['package'])},
    'dataset':
    {'title': 'dataset', 'len': 36, 'fmt': '%36s', 'get': lambda e: d(e, ['config', 'dataset'])},
}

snapshot_fmt = {
示例#5
0
文件: network.py 项目: tim-tang/pyfi
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

from .wiggle import Entity
from fifo.helper import d, ListAction, show_list, show_get, show_delete

network_fmt = {
    'uuid':
    {'title': 'UUID', 'len': 36, 'fmt': '%36s', 'get': lambda e: d(e, ['uuid'])},
    'name':
    {'title': 'Name', 'len': 10, 'fmt': '%-10s', 'get': lambda e: d(e, ['name'])},
    'ipranges':
    {'title': 'ipranges', 'len': 36, 'fmt': '%36s', 'get': lambda e: ','.join(d(e, ['ipranges']))},
 }

def create(args):
    res = args.endpoint.create(args.name)
    if res:
        print 'Network successfully created: %s' % res['uuid']
    else:
        print 'Network creation failed: %r' % res
        exit(1)

def add_range(args):
    res = args.endpoint.add_range(args.uuid, args.iprange_uuid)
    if res:
        print 'Successfully added IP range %s to %s' % (args.iprange_uuid, args.uuid)
    else:
        print 'Adding IP range failed: %r' % res
        exit(1)

class Network(Entity):
示例#6
0
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

import json
from .wiggle import Entity
from fifo.helper import d, ListAction, show_list, show_get, show_delete

iprange_fmt = {
    'uuid': {
        'title': 'UUID',
        'len': 36,
        'fmt': '%36s',
        'get': lambda e: d(e, ['uuid'])
    },
    'name': {
        'title': 'Name',
        'len': 20,
        'fmt': '%-20s',
        'get': lambda e: d(e, ['name'])
    },
    'tag': {
        'title': 'Tag',
        'len': 10,
        'fmt': '%-10s',
        'get': lambda e: d(e, ['tag'])
    },
    'iprange': {
        'title': 'Iprange',
        'len': 15,
        'fmt': '%15s',
        'get': lambda e: d(e, ['iprange'])
    },
示例#7
0
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

from .wiggle import Entity
from fifo.helper import d, ListAction, show_list, show_get, show_delete
import re
import argparse

pkg_fmt = {
    'uuid': {
        'title': 'UUID',
        'len': 36,
        'fmt': '%36s',
        'get': lambda e: d(e, ['uuid'])
    },
    'name': {
        'title': 'Name',
        'len': 10,
        'fmt': '%-10s',
        'get': lambda e: d(e, ['name'])
    },
    'cpu_cap': {
        'title': 'CPU cap',
        'len': 10,
        'fmt': '%-10s',
        'get': lambda e: str(d(e, ['cpu_cap'])) + '%'
    },
    'quota': {
        'title': 'Quota',
        'len': 10,
        'fmt': '%-10s',
        'get': lambda e: str(d(e, ['quota'])) + ' GB'
示例#8
0
文件: role.py 项目: teotikalki/pyfi
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

from .wiggle import Entity
from fifo.helper import d, ListAction, show_list, show_get, show_delete

role_fmt = {
    'uuid':
    {'title': 'UUID', 'len': 36, 'fmt': '%36s', 'get': lambda e: d(e, ['uuid'])},
    'name':
    {'title': 'Name', 'len': 10, 'fmt': '%-10s', 'get': lambda e: d(e, ['name'])},
}

def create(args):
    res = args.endpoint.create(args.name)
    if args.p:
        if res:
            print res['uuid']
        else:
            exit(1)
    else:
        if res:
            print 'Role successfully created: %s' % res['uuid']
        else:
            print 'Role creation failed: %r' % res
            exit(1)

def grant(args):
    res = args.endpoint.grant(args.uuid, args.permission)
    if args.p:
        if res:
            exit(0)
示例#9
0
# Returns the ip of a vm (first ip in the networks)
def vm_ip(e):
    n = d(e, ['config', 'networks'], [])
    if len(n) > 0:
        return n[0]['ip']
    else:
        return '-'


vm_fmt = {
    'uuid': {
        'title': 'UUID',
        'len': 36,
        'fmt': '%36s',
        'get': lambda e: d(e, ['uuid'])
    },
    'alias': {
        'title': 'alias',
        'len': 10,
        'fmt': '%-10s',
        'get': lambda e: d(e, ['config', 'alias'])
    },
    'ip': {
        'title': 'IP',
        'len': 15,
        'fmt': '%15s',
        'get': vm_ip
    },
    'state': {
        'title': 'state',
示例#10
0
def vm_ip(e):
    n = d(e, ['config', 'networks'], [])
    if len(n) > 0:
        return n[0]['ip']
    else:
        return '-'
示例#11
0
文件: dataset.py 项目: tim-tang/pyfi
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

import sys
from .wiggle import Entity
from fifo.helper import d, vprint, ListAction, show_list, show_get, show_delete
import httplib
import json
import argparse

dataset_fmt = {
    'uuid': {
        'title': 'UUID',
        'len': 36,
        'fmt': '%36s',
        'get': lambda e: d(e, ['uuid'])
    },
    'name': {
        'title': 'Name',
        'len': 10,
        'fmt': '%-10s',
        'get': lambda e: d(e, ['name'])
    },
    'version': {
        'title': 'Version',
        'len': 7,
        'fmt': '%-7s',
        'get': lambda e: d(e, ['version'])
    },
    'type': {
        'title': 'Type',
        'len': 5,
示例#12
0
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

import sys
from .wiggle import Entity
from fifo.helper import d, vprint, ListAction, show_list, show_get, show_delete
import httplib
import json
import argparse

dataset_fmt = {
    'uuid':
    {'title': 'UUID', 'len': 36, 'fmt': '%36s', 'get': lambda e: d(e, ['uuid'])},
    'name':
    {'title': 'Name', 'len': 10, 'fmt': '%-10s', 'get': lambda e: d(e, ['name'])},
    'version':
    {'title': 'Version', 'len': 7, 'fmt': '%-7s', 'get': lambda e: d(e, ['version'])},
    'type':
    {'title': 'Type', 'len': 5, 'fmt': '%-5s', 'get': lambda e: d(e, ['type'])},
    'description':
    {'title': 'Description', 'len': 10, 'fmt': '%-30s', 'get': lambda e: d(e, ['description'])},
}

def _write_bindata(response, f):
    amt = 4096
    try:
        data = response.read(amt)
    except httplib.IncompleteRead, e:
        data = e.partial
        f.write(data)
        f.flush()
        return
示例#13
0
    return(vm['info'])

def vm_metadata_map_fn(vm):
    return(vm['metadata'])

# Returns the ip of a vm (first ip in the networks)
def vm_ip(e):
    n = d(e, ['config', 'networks'], [])
    if len(n) > 0:
        return n[0]['ip']
    else:
        return '-'

vm_fmt = {
    'uuid':
    {'title': 'UUID', 'len': 36, 'fmt': '%36s', 'get': lambda e: d(e, ['uuid'])},
    'alias':
    {'title': 'alias', 'len': 10, 'fmt': '%-10s', 'get': lambda e: d(e, ['config', 'alias'])},
    'ip':
    {'title': 'IP', 'len': 15, 'fmt': '%15s', 'get': vm_ip},
    'state':
    {'title': 'state', 'len': 15, 'fmt': '%-15s', 'get': lambda e: d(e, ['state'])},
    'hypervisor':
    {'title': 'hypervisor', 'len': 20, 'fmt': '%-20s', 'get': lambda e: d(e, ['hypervisor'])},
    'package':
    {'title': 'package', 'len': 36, 'fmt': '%36s', 'get': lambda e: d(e, ['package'])},
    'dataset':
    {'title': 'dataset', 'len': 36, 'fmt': '%36s', 'get': lambda e: d(e, ['config', 'dataset'])},
}

snapshot_fmt = {
示例#14
0
文件: vm.py 项目: project-fifo/pyfi
def vm_ip(e):
    n = d(e, ['config', 'networks'], [])
    if len(n) > 0:
        return n[0]['ip']
    else:
        return '-'
示例#15
0
 def name_of(self, obj):
     return d(obj, ['config', 'alias'])
示例#16
0
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

from .wiggle import Entity
from fifo.helper import d, ListAction, show_list, show_get, show_delete


grouping_fmt = {
    "uuid": {"title": "UUID", "len": 36, "fmt": "%36s", "get": lambda e: d(e, ["uuid"])},
    "name": {"title": "Name", "len": 10, "fmt": "%-10s", "get": lambda e: d(e, ["name"])},
    "type": {"title": "Name", "len": 10, "fmt": "%-10s", "get": lambda e: d(e, ["type"])},
    "elements": {"title": "elements", "len": 36, "fmt": "%36s", "get": lambda e: ",".join(d(e, ["elements"]))},
    "groupings": {"title": "groupings", "len": 36, "fmt": "%36s", "get": lambda e: ",".join(d(e, ["groupings"]))},
}


def create_grouping(args):
    res = args.endpoint.create(args.name, args.type)
    if res:
        print "New " + args.type + " created: " + res["uuid"]
    else:
        print "Failed to create " + args.type
        exit(1)


def grouping_add(args):
    main = args.endpoint.get(args.uuid)
    if main["type"] != "stack":
        print "Only clusters can be added to stacks."
        exit(1)
    res = args.endpoint.get(args.target)
    if not res:
示例#17
0
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

from .wiggle import Entity
from fifo.helper import d, ListAction, show_list, show_get, show_delete
import sys

user_fmt = {
    'uuid': {
        'title': 'UUID',
        'len': 36,
        'fmt': '%36s',
        'get': lambda e: d(e, ['uuid'])
    },
    'name': {
        'title': 'Name',
        'len': 10,
        'fmt': '%-10s',
        'get': lambda e: d(e, ['name'])
    },
    'roles': {
        'title': 'Roles',
        'len': 10,
        'fmt': '%-10s',
        'get': lambda e: str(d(e, ['roles']))
    },
    'orgs': {
        'title': 'Orgs',
        'len': 10,
        'fmt': '%-10s',
        'get': lambda e: str(d(e, ['orgs']))
    },
示例#18
0
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4


from .wiggle import Entity
from fifo.helper import d, ListAction, show_list, show_get, show_delete
import sys


user_fmt = {
    'uuid':
    {'title': 'UUID', 'len': 36, 'fmt': '%36s', 'get': lambda e: d(e, ['uuid'])},
    'name':
    {'title': 'Name', 'len': 10, 'fmt': '%-10s', 'get': lambda e: d(e, ['name'])},
    'roles':
    {'title': 'Roles', 'len': 10, 'fmt': '%-10s', 'get': lambda e: str(d(e, ['roles']))},
    'orgs':
    {'title': 'Orgs', 'len': 10, 'fmt': '%-10s', 'get': lambda e: str(d(e, ['orgs']))},
}



def user_create(args):
    if not args.userpassword:
        print 'You have to specify a userpassword'
        exit(1)
    wiggle = args.endpoint._wiggle
    reply = args.endpoint.create(args.name, args.userpassword)
    if reply:
        if args.organization:
            args.endpoint.join_org(reply['uuid'], args.organization)
        if args.p:
示例#19
0
文件: org.py 项目: teotikalki/pyfi
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

from .wiggle import Entity
from fifo.helper import d, ListAction, show_list, show_get, show_delete

org_fmt = {
    'uuid':
    {'title': 'UUID', 'len': 36, 'fmt': '%36s', 'get': lambda e: d(e, ['uuid'])},
    'name':
    {'title': 'Name', 'len': 10, 'fmt': '%-10s', 'get': lambda e: d(e, ['name'])},
 }

org_acct_fmt = {
    'resource':
    {'title': 'Resource UUID', 'len': 36, 'fmt': '%36s', 'get': lambda e: d(e, ['resource'])},
    'action':
    {'title': 'Action', 'len': 8, 'fmt': '%-8s', 'get': lambda e: d(e, ['action'])},
    'timestamp':
    {'title': 'Timestamp', 'len': 16, 'fmt': '%-16s', 'get': lambda e: d(e, ['timestamp'])},
    'date':
    {'title': 'Date & Time', 'len': 19, 'fmt': '%-19s', 'get': lambda e: t(d(e, ['timestamp']))},
 }

def create(args):
    res = args.endpoint.create(args.name)
    if args.p:
        if res:
            print res['uuid']
        else:
            exit(1)
    else:
示例#20
0
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

from .wiggle import Entity
from fifo.helper import d, ListAction, show_list, show_get, show_delete

grouping_fmt = {
    'uuid': {
        'title': 'UUID',
        'len': 36,
        'fmt': '%36s',
        'get': lambda e: d(e, ['uuid'])
    },
    'name': {
        'title': 'Name',
        'len': 10,
        'fmt': '%-10s',
        'get': lambda e: d(e, ['name'])
    },
    'type': {
        'title': 'Name',
        'len': 10,
        'fmt': '%-10s',
        'get': lambda e: d(e, ['type'])
    },
    'elements': {
        'title': 'elements',
        'len': 36,
        'fmt': '%36s',
        'get': lambda e: ','.join(d(e, ['elements']))
    },
    'groupings': {
示例#21
0
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

from .wiggle import Entity
from fifo.helper import d, ListAction, show_list, show_get, show_delete
import re
import argparse

pkg_fmt = {
    'uuid':
    {'title': 'UUID', 'len': 36, 'fmt': '%36s', 'get': lambda e: d(e, ['uuid'])},
    'name':
    {'title': 'Name', 'len': 10, 'fmt': '%-10s', 'get': lambda e: d(e, ['name'])},
    'cpu_cap':
    {'title': 'CPU cap', 'len': 10, 'fmt': '%-10s', 'get': lambda e: str(d(e, ['cpu_cap'])) + '%'},
    'quota':
    {'title': 'Quota', 'len': 10, 'fmt': '%-10s', 'get': lambda e: str(d(e, ['quota'])) + ' GB'},
    'ram':
    {'title': 'RAM', 'len': 10, 'fmt': '%-10s', 'get': lambda e: str(d(e, ['ram'])) + ' MB'},
}


def create(args):
    mb = 1024*1024
    gb = mb * 1024
    reqs = []
    if args.requirement:
        reqs = map(package_rule, args.requirement)
    if args.random:
        reqs += map(package_random, args.random)
    if args.scale:
        reqs += map(package_scale, args.scale)
示例#22
0
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

from .wiggle import Entity
from fifo.helper import d, ListAction, show_list, show_get, show_delete

iprange_fmt = {
    'uuid':
    {'title': 'UUID', 'len': 36, 'fmt': '%36s', 'get': lambda e: d(e, ['uuid'])},
    'name':
    {'title': 'Name', 'len': 20, 'fmt': '%-20s', 'get': lambda e: d(e, ['name'])},
    'tag':
    {'title': 'Tag', 'len': 10, 'fmt': '%-10s', 'get': lambda e: d(e, ['tag'])},
    'iprange':
    {'title': 'Iprange', 'len': 15, 'fmt': '%15s', 'get': lambda e: d(e, ['iprange'])},
    'first':
    {'title': 'First', 'len': 15, 'fmt': '%15s', 'get': lambda e: d(e, ['first'])},
    'next':
    {'title': 'Next', 'len': 15, 'fmt': '%15s', 'get': lambda e: d(e, ['current'])},
    'last':
    {'title': 'Last', 'len': 15, 'fmt': '%15s', 'get': lambda e: d(e, ['last'])},
    'returned':
    {'title': 'Returned', 'len': 15, 'fmt': '%15s', 'get': lambda e: len(d(e, ['free'], []))},
    'gateway':
    {'title': 'Gateway', 'len': 15, 'fmt': '%15s', 'get': lambda e: d(e, ['gateway'])},
    'netmask':
    {'title': 'Netmask', 'len': 15, 'fmt': '%15s', 'get': lambda e: d(e, ['netmask'])},
    'vlan':
    {'title': 'vlan', 'len': 5, 'fmt': '%5s', 'get': lambda e: d(e, ['vlan'])},
}

def create(args):
示例#23
0
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

from .wiggle import Entity
from fifo.helper import d, ListAction, show_list, show_get, show_delete

hypervisor_fmt = {
    'uuid': {
        'title': 'UUID',
        'len': 36,
        'fmt': '%36s',
        'get': lambda e: d(e, ['uuid'])
    },
    'name': {
        'title': 'Name',
        'len': 30,
        'fmt': '%30s',
        'get': lambda e: d(e, ['alias'])
    },
    'free': {
        'title': 'Free RAM',
        'len': 10,
        'fmt': '%10s',
        'get': lambda e: str(d(e, ['resources', 'free-memory'])) + 'MB'
    },
    'used': {
        'title': 'Used RAM',
        'len': 10,
        'fmt': '%10s',
        'get': lambda e: str(d(e, ['resources', 'provisioned-memory'])) + 'MB'
    },
    'reserved': {