コード例 #1
0
ファイル: iaas.py プロジェクト: Gandi/gandi.widget
    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]
コード例 #2
0
    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]
コード例 #3
0
    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
コード例 #4
0
ファイル: disk.py プロジェクト: Simakink/gandi.cli
    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
コード例 #5
0
ファイル: disk.py プロジェクト: klnikita/gandi.cli
    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
コード例 #6
0
ファイル: disk.py プロジェクト: yanndinendal/gandi.cli
    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
コード例 #7
0
ファイル: docker.py プロジェクト: Gandi/gandi.cli
    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))
コード例 #8
0
ファイル: docker.py プロジェクト: ziir/gandi.cli
    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))
コード例 #9
0
ファイル: network.py プロジェクト: Gandi/gandi.cli
    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
コード例 #10
0
ファイル: network.py プロジェクト: lisptick/gandi.cli
    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
コード例 #11
0
ファイル: network.py プロジェクト: Gandi/gandi.cli
    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
コード例 #12
0
ファイル: network.py プロジェクト: ziir/gandi.cli
    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
コード例 #13
0
ファイル: network.py プロジェクト: Gandi/gandi.cli
    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)
コード例 #14
0
ファイル: network.py プロジェクト: lisptick/gandi.cli
    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)