def retrieve(): vms = [] for vm in ApiIaas.list({"state": ["running", "halted"], "sort_by": "hostname"}): vms.append(ApiIaas.info(vm["id"])) if hasattr(ApiAccount, "all"): account = ApiAccount.all() else: account = ApiAccount.info() account["credit_usage"] = ApiAccount.creditusage() return [vms, account]
def retrieve(): vms = [] for vm in ApiIaas.list({'state': ['running', 'halted'], 'sort_by': 'hostname'}): vms.append(ApiIaas.info(vm['id'])) if hasattr(ApiAccount, 'all'): account = ApiAccount.all() else: account = ApiAccount.info() account['credit_usage'] = ApiAccount.creditusage() return [vms, account]
def attach(cls, disk, vm, background, position=None, read_only=False): from gandi.cli.modules.iaas import Iaas as VM vm_id = VM.usable_id(vm) disk_id = cls.usable_id(disk) disk_info = cls._info(disk_id) options = {} if position is not None: options['position'] = position if read_only: options['access'] = 'read' need_detach = disk_info.get('vms_id') if need_detach: if disk_info.get('vms_id') == [vm_id]: cls.echo('This disk is already attached to this vm.') return # detach disk detach_op = cls._detach(disk_id) # interactive mode, run a progress bar cls.echo('Detaching your disk.') cls.display_progress(detach_op) oper = cls._attach(disk_id, vm_id, options) if oper and not background: cls.echo('Attaching your disk(s).') cls.display_progress(oper) return oper
def attach(cls, disk, vm, background): from gandi.cli.modules.iaas import Iaas as VM vm_id = VM.usable_id(vm) disk_id = cls.usable_id(disk) disk_info = cls._info(disk_id) need_detach = disk_info.get('vms_id') if need_detach: if disk_info.get('vms_id') == [vm_id]: cls.echo('This disk is already attached to this vm.') return # detach disk detach_op = cls._detach(disk_id) # interactive mode, run a progress bar cls.echo('Detaching your disk.') cls.display_progress(detach_op) oper = cls._attach(disk_id, vm_id) if oper and not background: cls.echo('Attaching your disk(s).') cls.display_progress(oper) return oper
def handle(cls, vm, args): """ Setup forwarding connection to given VM and pipe docker cmds over SSH. """ docker = Iaas.info(vm) if not docker: raise Exception('docker vm %s not found' % vm) if docker['state'] != 'running': Iaas.start(vm) # XXX remote_addr = docker['ifaces'][0]['ips'][0]['ip'] port = unixpipe.setup(remote_addr, 'root', '/var/run/docker.sock') os.environ['DOCKER_HOST'] = 'tcp://localhost:%d' % port cls.echo('using DOCKER_HOST=%s' % os.environ['DOCKER_HOST']) subprocess.call(['docker'] + list(args))
def attach(cls, ip, vm, background=False, force=False): """ Attach """ vm_ = Iaas.info(vm) ip_ = cls.info(ip) if not cls._check_and_detach(ip_, vm_): return # then we should attach the ip to the vm attach = Iface._attach(ip_['iface_id'], vm_['id']) if not background: cls.display_progress(attach) return attach
def attach(cls, ip, vm, background=False, force=False): """ Attach """ vm_ = Iaas.info(vm) ip_ = cls.info(ip) if not cls.check_and_detach(ip_, vm_, force): return # then we should attach the ip to the vm attach = Iface._attach(ip_['iface_id'], vm_['id']) if not background: cls.display_progress(attach) return attach
def create(cls, ip_version, datacenter, bandwidth, vlan, vm, ip, background): """ Create a new iface """ if not background and not cls.intty(): background = True datacenter_id_ = int(Datacenter.usable_id(datacenter)) iface_params = { 'ip_version': ip_version, 'datacenter_id': datacenter_id_, 'bandwidth': bandwidth, } if vlan: iface_params['vlan'] = Vlan.usable_id(vlan) if ip: iface_params['ip'] = ip result = cls.call('hosting.iface.create', iface_params) if background and not vm: return result # interactive mode, run a progress bar cls.echo('Creating your iface.') cls.display_progress(result) iface_info = cls._info(result['iface_id']) cls.echo('Your iface has been created with the following IP ' 'addresses:') for _ip in iface_info['ips']: cls.echo('ip%d:\t%s' % (_ip['version'], _ip['ip'])) if not vm: return result vm_id = Iaas.usable_id(vm) result = cls._attach(result['iface_id'], vm_id) if background: return result cls.echo('Attaching your iface.') cls.display_progress(result) return result
def update(cls, id, bandwidth, vm, background): """ Update this iface. """ if not background and not cls.intty(): background = True iface_params = {} iface_id = cls.usable_id(id) if bandwidth: iface_params['bandwidth'] = bandwidth if iface_params: result = cls.call('hosting.iface.update', iface_id, iface_params) if background: return result # interactive mode, run a progress bar cls.echo('Updating your iface %s.' % id) cls.display_progress(result) if not vm: return vm_id = Iaas.usable_id(vm) opers = cls._detach(iface_id) if opers: cls.echo('Detaching iface.') cls.display_progress(opers) result = cls._attach(iface_id, vm_id) if background: return result cls.echo('Attaching your iface.') cls.display_progress(result)