Esempio n. 1
0
    def test_destroy_node(self):
        VoxelMockHttp.type = 'DESTROY_NODE'
        node = Node(
            id=72258, name=None, state=None, public_ips=None, private_ips=None,
            driver=self.driver)

        self.assertTrue(node.destroy())
Esempio n. 2
0
def destroy_machine(request):
    """Destroys a machine on a certain backend.

    After destroying a machine it also deletes all key associations. However,
    it doesn't undeploy the keypair. There is no need to do it because the
    machine will be destroyed.

    """
    try:
        conn = connect(request)
    except:
        return Response("Backend not found", 404)

    machine_id = request.matchdict["machine"]
    machine = Node(machine_id, name=machine_id, state=0, public_ips=[], private_ips=[], driver=conn)

    machine.destroy()

    backend_id = request.matchdict["backend"]
    pair = [backend_id, machine_id]

    try:
        keypairs = request.environ["beaker.session"]["keypairs"]
    except:
        keypairs = request.registry.settings.get("keypairs", {})

    for key in keypairs:
        machines = keypairs[key].get("machines", None)
        if pair in machines:
            disassociate_key(request, key, backend_id, machine_id, undeploy=False)

    return Response("Success", 200)
Esempio n. 3
0
    def test_reboot_node(self):
        VoxelMockHttp.type = 'REBOOT_NODE'
        node = Node(
            id=72258, name=None, state=None, public_ips=None, private_ips=None,
            driver=self.driver)

        self.assertTrue(node.reboot())
Esempio n. 4
0
 def test_destroy_node_response_INPROGRESS(self):
     OpsourceMockHttp.type = "INPROGRESS"
     node = Node(id="11", name=None, state=None, public_ips=None, private_ips=None, driver=self.driver)
     try:
         node.destroy()
         self.assertTrue(False)  # above command should have thrown OpsourceAPIException
     except OpsourceAPIException:
         self.assertTrue(True)
    def test_destroy_node(self):
        node = Node(id=1, name=None, state=None, public_ips=None, private_ips=None,
                    driver=self.driver)

        ret = node.destroy()
        self.assertTrue(ret is True)

        ret = self.driver.destroy_node(node)
        self.assertTrue(ret is True)
Esempio n. 6
0
 def test_reboot_node_response_INPROGRESS(self):
     OpsourceMockHttp.type = 'INPROGRESS'
     node = Node(id='11', name=None, state=None,
                 public_ips=None, private_ips=None, driver=self.driver)
     try:
         node.reboot()
         self.assertTrue(
             False)  # above command should have thrown OpsourceAPIException
     except OpsourceAPIException:
         pass
Esempio n. 7
0
 def test_destroy_node_response_INPROGRESS(self):
     DimensionDataMockHttp.type = 'INPROGRESS'
     node = Node(id='11', name=None, state=None,
                 public_ips=None, private_ips=None, driver=self.driver)
     try:
         node.destroy()
         self.assertTrue(
             False)  # above command should have thrown DimensionDataAPIException
     except DimensionDataAPIException:
         pass
Esempio n. 8
0
def reboot_machine(request):
    """Reboots a machine on a certain backend."""
    try:
        conn = connect(request)
    except:
        return Response("Backend not found", 404)

    machine_id = request.matchdict["machine"]
    machine = Node(machine_id, name=machine_id, state=0, public_ips=[], private_ips=[], driver=conn)

    machine.reboot()

    return Response("Success", 200)
Esempio n. 9
0
    def test_reboot_node(self):
        node = Node(id=1, name=None, state=None, public_ip=None, private_ip=None,
                    driver=self.driver)

        ret = node.reboot()
        self.assertTrue(ret is True)

        ret = self.driver.reboot_node(node)
        self.assertTrue(ret is True)

        SlicehostMockHttp.type = 'FORBIDDEN'
        try:
            ret = self.driver.reboot_node(node)
        except Exception, e:
            self.assertEqual(e.args[0], 'Permission denied')
    def test_reboot_node(self):
        node = Node(id=1, name=None, state=None, public_ips=None, private_ips=None,
                    driver=self.driver)

        ret = node.reboot()
        self.assertTrue(ret is True)

        ret = self.driver.reboot_node(node)
        self.assertTrue(ret is True)

        SlicehostMockHttp.type = 'FORBIDDEN'
        try:
            ret = self.driver.reboot_node(node)
        except Exception:
            e = sys.exc_info()[1]
            self.assertEqual(e.args[0], 'Permission denied')
        else:
            self.fail('test should have thrown')
Esempio n. 11
0
def destroy_machine(request):
    """Destroys a machine on a certain backend."""
    try:
        conn = connect(request)
    except:
        return Response('Backend not found', 404)

    machine_id = request.matchdict['machine']
    machine = Node(machine_id,
                   name=machine_id,
                   state=0,
                   public_ips=[],
                   private_ips=[],
                   driver=conn)

    machine.destroy()

    return Response('Success', 200)
Esempio n. 12
0
 def _to_node(self, data):
     return Node(
         id = data['id'],
         name = data['name'],
         state = self.NODE_STATE_MAP[data['status']],
         public_ips = list(map(lambda cloud_ip: cloud_ip['public_ip'],
                                                data['cloud_ips'])),
         private_ips = list(map(lambda interface: interface['ipv4_address'],
                                                  data['interfaces'])),
         driver = self.connection.driver,
         extra = {
             'status': data['status'],
             'interfaces': data['interfaces']
         }
     )
Esempio n. 13
0
 def _to_node(self, order):
     n = Node(id=order['slug'],
              name=order['domain_name'],
              state=NodeState.RUNNING,
              public_ip=([order['allocated_ips']['primary_ip']] +
                         order['allocated_ips']['secondary_ips']),
              private_ip=[],
              driver=self.connection.driver,
              extra={
                  'order_oid':
                  order['order_oid'],
                  'monthly_recurring_fee':
                  order.get('billing_info').get('monthly_recurring_fee')
              })
     return n
Esempio n. 14
0
    def test_balancer_attach_compute_node(self):
        balancer = LoadBalancer(23530, None, None, None, None, self.driver)
        node = Node(id='1',
                    name='test',
                    state=None,
                    public_ips=['10.0.0.75'],
                    private_ips=[],
                    driver=DummyNodeDriver)
        member1 = self.driver.balancer_attach_compute_node(balancer, node)
        member2 = balancer.attach_compute_node(node)

        self.assertEqual(member1.ip, '10.0.0.75')
        self.assertEqual(member1.port, 80)
        self.assertEqual(member2.ip, '10.0.0.75')
        self.assertEqual(member2.port, 80)
Esempio n. 15
0
 def _to_node(self, data):
     """
     Convert the data from a DreamhostResponse object into a Node
     """
     return Node(
         id=data['ps'],
         name=data['ps'],
         state=NodeState.UNKNOWN,
         public_ips=[data['ip']],
         private_ips=[],
         driver=self.connection.driver,
         extra={
             'current_size': data['memory_mb'],
             'account_id': data['account_id'],
             'type': data['type']})
Esempio n. 16
0
 def ex_get_node_details(self, node_id):
     driver = DummyNodeDriver(0)
     node = Node(
         id=node_id,
         name="",
         state=NodeState.RUNNING,
         public_ips=[],
         private_ips=[],
         driver=driver,
     )
     agentnode = self._get_domain_for_node(node)
     if agentnode is None:
         return None
     node = self._from_agent_to_node(agentnode)
     return node
Esempio n. 17
0
 def _to_node(self, obj):
     extra = obj.copy()
     if "ipAddresses" in extra:
         public_ips = [ip["ip"] for ip in extra["ipAddresses"]]
     del extra["id"]
     del extra["name"]
     return Node(
         id=obj["id"],
         name=obj["name"],
         state=self.NODE_STATE_MAP[obj["status"]],
         public_ips=public_ips,
         private_ips=[],
         driver=self,
         extra=extra,
     )
Esempio n. 18
0
 def test_ex_resize(self):
     node = Node(id=444222,
                 name=None,
                 state=None,
                 public_ips=None,
                 private_ips=None,
                 driver=self.driver)
     size = NodeSize(1,
                     '256 slice',
                     None,
                     None,
                     None,
                     None,
                     driver=self.driver)
     self.assertTrue(self.driver.ex_resize(node=node, size=size))
Esempio n. 19
0
    def _to_node(self, domain):
        state, max_mem, memory, vcpu_count, used_cpu_time = domain.info()
        state = self.NODE_STATE_MAP.get(state, NodeState.UNKNOWN)

        public_ips, private_ips = [], []

        ip_addresses = self._get_ip_addresses_for_domain(domain)

        for ip_address in ip_addresses:
            if is_public_subnet(ip_address):
                public_ips.append(ip_address)
            else:
                private_ips.append(ip_address)

        extra = {'uuid': domain.UUIDString(), 'os_type': domain.OSType(),
                 'types': self.connection.getType(),
                 'used_memory': memory / 1024, 'vcpu_count': vcpu_count,
                 'used_cpu_time': used_cpu_time}

        node = Node(id=domain.ID(), name=domain.name(), state=state,
                    public_ips=public_ips, private_ips=private_ips,
                    driver=self, extra=extra)
        node._uuid = domain.UUIDString()  # we want to use a custom UUID
        return node
Esempio n. 20
0
 def _to_node(self, vm):
     state = NODE_STATE_MAP[vm.get("status", NodeState.UNKNOWN)]
     n = Node(
         id=vm["id"],
         name=vm["hostname"],
         state=state,
         public_ips=[ip["address"] for ip in vm["ips"]],
         private_ips=[],
         extra={
             "storage": vm["storage"],
             "cpu": vm["cpu"]
         },
         driver=self.connection.driver,
     )
     return n
Esempio n. 21
0
 def _get_machine_libcloud(self, machine, no_fail=False):
     cloud_service = self._cloud_service(machine.machine_id)
     for node in self.connection.list_nodes(
             ex_cloud_service_name=cloud_service):
         if node.id == machine.machine_id:
             return node
         if no_fail:
             return Node(machine.machine_id,
                         name=machine.machine_id,
                         state=0,
                         public_ips=[],
                         private_ips=[],
                         driver=self.connection)
         raise MachineNotFoundError("Machine with id '%s'." %
                                    machine.machine_id)
Esempio n. 22
0
 def test_ex_power_off_INPROGRESS(self):
     DimensionDataMockHttp.type = 'INPROGRESS'
     node = Node(id='11',
                 name=None,
                 state=None,
                 public_ips=None,
                 private_ips=None,
                 driver=self.driver)
     try:
         self.driver.ex_power_off(node)
         self.assertTrue(
             False
         )  # above command should have thrown DimensionDataAPIException
     except DimensionDataAPIException:
         pass
Esempio n. 23
0
    def test_ex_update_node(self):
        old_node = Node(
            id='12064',
            name=None,
            state=None,
            public_ips=None,
            private_ips=None,
            driver=self.driver,
        )

        new_node = self.driver.ex_update_node(old_node, name='Bob')

        self.assertTrue(new_node)
        self.assertEqual('Bob', new_node.name)
        self.assertEqual('50.57.94.30', new_node.public_ips[0])
Esempio n. 24
0
    def create_node(self, **kwargs):
        # name = kwargs['name']
        # size = kwargs['size']
        # image = kwargs['image']

        # auth = kwargs.get('auth', None)

        payload = {
            #'Hostname': None,
            #'PortSpecs': None,
            #'User': None,
            #'Tty': False,
            #'OpenStdin': False,
            #'Memory': 0,
            'AttachStdin': False,
            'AttachStdout': False,
            'AttachStderr': False,
            #'Env': None,
            'Cmd': ['ls'],
            #'Dns': None,
            'Image': 'base',
            #'Volumes': None,
            #'VolumesFrom': None,
        }

        data = json.dumps(payload)
        result = self.connection.request('/containers/create',
                                         data=data,
                                         method='POST')

        id_ = result.object['Id']

        payload = {
            'Binds': [],
        }

        data = json.dumps(payload)
        result = self.connection.request('/containers/%s/start' % id_,
                                         data=data,
                                         method='POST')

        return Node(id=id_,
                    name=id_,
                    state=NodeState.RUNNING,
                    public_ips=[],
                    private_ips=[],
                    driver=self.connection.driver,
                    extra={})
Esempio n. 25
0
    def _to_node(self, vm, driver):
        """
        Generates the :class:`Node` class.
        """
        identifier = vm.findtext("id")
        name = vm.findtext("label")
        state = AbiquoResponse.NODE_STATE_MAP[vm.findtext("state")]

        link_image = get_href(vm, "virtualmachinetemplate")
        link_hdr = {"Accept": self.VMTPL_MIME_TYPE}
        image_element = self.connection.request(link_image,
                                                headers=link_hdr).object
        repo_link = get_href(image_element, "datacenterrepository")
        image = self._to_nodeimage(image_element, self, repo_link)

        # Fill the 'ips' data
        private_ips = []
        public_ips = []
        nics_hdr = {"Accept": self.NICS_MIME_TYPE}
        nics_element = self.connection.request(get_href(vm, "nics"),
                                               headers=nics_hdr).object
        for nic in nics_element.findall("nic"):
            ip = nic.findtext("ip")
            for link in nic.findall("link"):
                rel = link.attrib["rel"]
                if rel == "privatenetwork":
                    private_ips.append(ip)
                elif rel in [
                        "publicnetwork", "externalnetwork", "unmanagednetwork"
                ]:
                    public_ips.append(ip)

        extra = {"uri_id": get_href(vm, "edit")}

        if vm.find("vdrpIp") is not None:
            extra["vdrp_ip"] = vm.findtext("vdrpIP")
            extra["vdrp_port"] = vm.findtext("vdrpPort")

        return Node(
            identifier,
            name,
            state,
            public_ips,
            private_ips,
            driver,
            image=image,
            extra=extra,
        )
Esempio n. 26
0
    def _to_node(self, data, ssh_password=None):
        try:
            state = NODE_STATE_MAP[data['status']]
        except KeyError:
            state = NodeState.UNKNOWN

        if 'nic:0:dhcp:ip' in data:
            if isinstance(data['nic:0:dhcp:ip'], list):
                public_ip = data['nic:0:dhcp:ip']
            else:
                public_ip = [data['nic:0:dhcp:ip']]
        else:
            public_ip = []

        extra = {'cpu': data['cpu'], 'mem': data['mem']}

        if 'started' in data:
            extra['started'] = data['started']

        if 'smp' in data:
            extra['smp'] = data['smp']

        if 'vnc:ip' in data:
            extra['vnc:ip'] = data['vnc:ip']

        if 'vnc:password' in data:
            extra['vnc:password'] = data['vnc:password']

        boot_device = data['boot']

        if isinstance(boot_device, list):
            for device in boot_device:
                extra[device] = data[device]
        else:
            extra[boot_device] = data[boot_device]

        if ssh_password:
            extra.update({'password': ssh_password})

        node = Node(id=data['server'],
                    name=data['name'],
                    state=state,
                    public_ips=public_ip,
                    private_ips=None,
                    driver=self.connection.driver,
                    extra=extra)

        return node
Esempio n. 27
0
    def _to_node(self, element, groups=None):
        try:
            state = self.NODE_STATE_MAP[self._findattr(element,
                                                       "instanceState/name")]
        except KeyError:
            state = NodeState.UNKNOWN

        n = Node(id=self._findtext(element, 'instanceId'),
                 name=self._findtext(element, 'instanceId'),
                 state=state,
                 public_ip=[self._findtext(element, 'ipAddress')],
                 private_ip=[self._findtext(element, 'privateIpAddress')],
                 driver=self.connection.driver,
                 extra={
                     'dns_name':
                     self._findattr(element, "dnsName"),
                     'instanceId':
                     self._findattr(element, "instanceId"),
                     'imageId':
                     self._findattr(element, "imageId"),
                     'private_dns':
                     self._findattr(element, "privateDnsName"),
                     'status':
                     self._findattr(element, "instanceState/name"),
                     'keyname':
                     self._findattr(element, "keyName"),
                     'launchindex':
                     self._findattr(element, "amiLaunchIndex"),
                     'productcode': [
                         p.text for p in self._findall(
                             element, "productCodesSet/item/productCode")
                     ],
                     'instancetype':
                     self._findattr(element, "instanceType"),
                     'launchdatetime':
                     self._findattr(element, "launchTime"),
                     'availability':
                     self._findattr(element, "placement/availabilityZone"),
                     'kernelid':
                     self._findattr(element, "kernelId"),
                     'ramdiskid':
                     self._findattr(element, "ramdiskId"),
                     'clienttoken':
                     self._findattr(element, "clientToken"),
                     'groups':
                     groups
                 })
        return n
Esempio n. 28
0
    def _to_node(self, vm):
        if vm['running']:
            state = NodeState.RUNNING
        else:
            state = NodeState.PENDING

        n = Node(
            id=vm['id'],
            name=vm['label'],
            state=state,
            public_ips=[vm.get('primary_ip_address', None)],
            private_ips=[],
            extra={'slices_count':
                   vm['slices_count']},  # Number of nodes consumed by VM
            driver=self.connection.driver)
        return n
Esempio n. 29
0
 def test_destroy_node(self):
     if UpcloudDriver.connectionCls.conn_class == UpcloudMockHttp:
         nodes = [
             Node(
                 id="00893c98_5d5a_4363_b177_88df518a2b60",
                 name="",
                 state="",
                 public_ips=[],
                 private_ips=[],
                 driver=self.driver,
             )
         ]
     else:
         nodes = self.driver.list_nodes()
     success = self.driver.destroy_node(nodes[0])
     self.assertTrue(success)
Esempio n. 30
0
    def _to_node(self, compute):
        try:
            state = self.NODE_STATE_MAP[compute.findtext("STATE")]
        except KeyError:
            state = NodeState.UNKNOWN

        networks = []
        for element in compute.findall("NIC"):
            networks.append(element.attrib["ip"])

        return Node(id=compute.findtext("ID"),
                    name=compute.findtext("NAME"),
                    state=state,
                    public_ip=networks,
                    private_ip=[],
                    driver=self.connection.driver)
Esempio n. 31
0
    def _to_node(self, vm):
        name = ""
        private_ips = []
        for tag in vm["Tags"]:
            if tag["Key"] == "Name":
                name = tag["Value"]
        if "Nics" in vm:
            private_ips = vm["Nics"]["PrivateIps"]

        return Node(id=vm["VmId"],
                    name=name,
                    state=self.NODE_STATE[vm["State"]],
                    public_ips=[],
                    private_ips=private_ips,
                    driver=self,
                    extra=vm)
Esempio n. 32
0
    def test_create_volume(self):
        node = Node("22344420",
                    None,
                    NodeState.RUNNING,
                    None,
                    None,
                    driver=self.driver)
        volume = self.driver.create_volume("Volume1",
                                           50,
                                           node=node,
                                           tags=["test123", "testing"])

        self.assertEqual(volume.extra["linode_id"], 22344420)
        self.assertEqual(volume.size, 50)
        self.assertEqual(volume.name, "Volume1")
        self.assertEqual(volume.extra["tags"], ["test123", "testing"])
Esempio n. 33
0
    def test_create_volume(self):
        node = Node('22344420',
                    None,
                    NodeState.RUNNING,
                    None,
                    None,
                    driver=self.driver)
        volume = self.driver.create_volume('Volume1',
                                           50,
                                           node=node,
                                           tags=['test123', 'testing'])

        self.assertEqual(volume.extra['linode_id'], 22344420)
        self.assertEqual(volume.size, 50)
        self.assertEqual(volume.name, 'Volume1')
        self.assertEqual(volume.extra['tags'], ['test123', 'testing'])
Esempio n. 34
0
 def _to_node(self, obj):
     extra = obj.copy()
     if 'flavorId' in extra:
         public_ips = [obj.pop('ip')]
     else:
         ip = extra.pop('ipv4')
         public_ips = [ip] if ip else []
     del extra['instanceId']
     del extra['name']
     return Node(id=obj['instanceId'],
                 name=obj['name'],
                 state=self.NODE_STATE_MAP[obj['status']],
                 public_ips=public_ips,
                 private_ips=[],
                 driver=self,
                 extra=extra)
Esempio n. 35
0
 def test_ex_get_control_access(self):
     node = Node(
         'https://vm-vcloud/api/vApp/vapp-8c57a5b6-e61b-48ca-8a78-3b70ee65ef6b',
         'testNode', NodeState.RUNNING, [], [], self.driver)
     control_access = self.driver.ex_get_control_access(node)
     self.assertEqual(control_access.everyone_access_level,
                      ControlAccess.AccessLevel.READ_ONLY)
     self.assertEqual(len(control_access.subjects), 1)
     self.assertEqual(control_access.subjects[0].type, 'group')
     self.assertEqual(control_access.subjects[0].name, 'MyGroup')
     self.assertEqual(
         control_access.subjects[0].id,
         'https://vm-vcloud/api/admin/group/b8202c48-7151-4e61-9a6c-155474c7d413'
     )
     self.assertEqual(control_access.subjects[0].access_level,
                      ControlAccess.AccessLevel.FULL_CONTROL)
Esempio n. 36
0
 def _to_node(self, server):
     public_ip = server['public_ip']
     private_ip = server['private_ip']
     location = server['location'] or {}
     return Node(id=server['id'],
                 name=server['name'],
                 state=NodeState.fromstring(server['state']),
                 public_ips=[public_ip['address']] if public_ip else [],
                 private_ips=[private_ip] if private_ip else [],
                 driver=self,
                 extra={'volumes': server['volumes'],
                        'tags': server['tags'],
                        'arch': server['arch'],
                        'organization': server['organization'],
                        'region': location.get('zone_id', 'par1')},
                 created_at=parse_date(server['creation_date']))
Esempio n. 37
0
    def _to_node(self, element):
        if findtext(element, 'isStarted', SERVER_NS) == 'true':
            state = NodeState.RUNNING
        else:
            state = NodeState.TERMINATED

        status = self._to_status(element.find(fixxpath('status', SERVER_NS)))

        extra = {
            'description':
            findtext(element, 'description', SERVER_NS),
            'sourceImageId':
            findtext(element, 'sourceImageId', SERVER_NS),
            'networkId':
            findtext(element, 'networkId', SERVER_NS),
            'machineName':
            findtext(element, 'machineName', SERVER_NS),
            'deployedTime':
            findtext(element, 'deployedTime', SERVER_NS),
            'cpuCount':
            findtext(element, 'machineSpecification/cpuCount', SERVER_NS),
            'memoryMb':
            findtext(element, 'machineSpecification/memoryMb', SERVER_NS),
            'osStorageGb':
            findtext(element, 'machineSpecification/osStorageGb', SERVER_NS),
            'additionalLocalStorageGb':
            findtext(element, 'machineSpecification/additionalLocalStorageGb',
                     SERVER_NS),
            'OS_type':
            findtext(element, 'machineSpecification/operatingSystem/type',
                     SERVER_NS),
            'OS_displayName':
            findtext(element,
                     'machineSpecification/operatingSystem/displayName',
                     SERVER_NS),
            'status':
            status,
        }

        n = Node(id=findtext(element, 'id', SERVER_NS),
                 name=findtext(element, 'name', SERVER_NS),
                 state=state,
                 public_ips=[],
                 private_ips=findtext(element, 'privateIpAddress', SERVER_NS),
                 driver=self.connection.driver,
                 extra=extra)
        return n
Esempio n. 38
0
    def _to_ssd_node(self, vm):
        if vm['running']:
            state = NodeState.RUNNING
        else:
            state = NodeState.PENDING

        n = Node(id=vm['id'],
                 name=vm['ssd_vps_label'],
                 state=state,
                 public_ips=[vm.get('primary_ip_address', None)],
                 private_ips=[],
                 extra={
                    'password': vm.get('password', None),
                    'backups_enabled': vm['backups_enabled'],
                    'cloud_id': vm['cloud_id']},
                 driver=self.connection.driver)
        return n
Esempio n. 39
0
    def _get_machine_libcloud(self, machine, no_fail=False):
        """Return an instance of a libcloud node

        This is a private method, used mainly by machine action methods.
        """
        # assert isinstance(machine.cloud, Machine)
        assert self.cloud == machine.cloud
        for node in self.connection.list_nodes():
            if node.id == machine.machine_id:
                return node
        if no_fail:
            return Node(machine.machine_id, name=machine.machine_id,
                        state=0, public_ips=[], private_ips=[],
                        driver=self.connection)
        raise MachineNotFoundError(
            "Machine with machine_id '%s'." % machine.machine_id
        )
Esempio n. 40
0
    def _to_nodes(self, objs):
        """Convert returned JSON Linodes into Node instances

        :keyword objs: ``list`` of JSON dictionaries representing the Linodes
        :type objs: ``list``
        :return: ``list`` of :class:`Node`s"""

        # Get the IP addresses for the Linodes
        nodes = {}
        batch = []
        for o in objs:
            lid = o["LINODEID"]
            nodes[lid] = n = Node(id=lid, name=o["LABEL"], public_ips=[],
                                  private_ips=[],
                                  state=self.LINODE_STATES[o["STATUS"]],
                                  driver=self.connection.driver)
            n.extra = copy(o)
            n.extra["PLANID"] = self._linode_plan_ids.get(o.get("TOTALRAM"))
            batch.append({"api_action": "linode.ip.list", "LinodeID": lid})

        # Avoid batch limitation
        ip_answers = []
        args = [iter(batch)] * 25

        if PY3:
            izip_longest = itertools.zip_longest  # pylint: disable=no-member
        else:
            izip_longest = getattr(itertools, 'izip_longest', _izip_longest)

        for twenty_five in izip_longest(*args):
            twenty_five = [q for q in twenty_five if q]
            params = {"api_action": "batch",
                      "api_requestArray": json.dumps(twenty_five)}
            req = self.connection.request(API_ROOT, params=params)
            if not req.success() or len(req.objects) == 0:
                return None
            ip_answers.extend(req.objects)

        # Add the returned IPs to the nodes and return them
        for ip_list in ip_answers:
            for ip in ip_list:
                lid = ip["LINODEID"]
                which = nodes[lid].public_ips if ip["ISPUBLIC"] == 1 else\
                    nodes[lid].private_ips
                which.append(ip["IPADDRESS"])
        return list(nodes.values())
Esempio n. 41
0
    def _to_node(self, server, state=None):
        ip_addresses = server['ip_addresses']['ip_address']
        public_ips = [ip['address'] for ip in ip_addresses
                      if ip['access'] == 'public']
        private_ips = [ip['address'] for ip in ip_addresses
                       if ip['access'] == 'private']

        extra = {'vnc_password': server['vnc_password']}
        if 'password' in server:
            extra['password'] = server['password']
        return Node(id=server['uuid'],
                    name=server['title'],
                    state=state or self.NODE_STATE_MAP[server['state']],
                    public_ips=public_ips,
                    private_ips=private_ips,
                    driver=self,
                    extra=extra)
Esempio n. 42
0
 def _to_node(self, vm):
     return Node(
         id=vm['id'],
         name=vm['hostname'],
         state=NODE_STATE_MAP.get(
             vm['state'],
             NodeState.UNKNOWN
         ),
         public_ips=vm.get('ips', []),
         private_ips=[],
         driver=self,
         extra={
             'ai_active': vm.get('ai_active'),
             'datacenter_id': vm.get('datacenter_id'),
             'description': vm.get('description')
         }
     )
 def test_reboot_node(self):
     node = Node(id=72258, name=None, state=None, public_ips=None,
                 private_ips=None, driver=self.driver)
     ret = node.reboot()
     self.assertTrue(ret is True)