Example #1
0
    def _to_node(self, obj):
        # Convert a returned Linode instance into a Node instance.
        lid = obj["LINODEID"]

        # Get the IP addresses for a Linode
        params = {"api_action": "linode.ip.list", "LinodeID": lid}
        req = self.connection.request(LINODE_ROOT, params=params)
        if not req.success() or len(req.object) == 0:
            return None

        public_ip = []
        private_ip = []
        for ip in req.object:
            if ip["ISPUBLIC"]:
                public_ip.append(ip["IPADDRESS"])
            else:
                private_ip.append(ip["IPADDRESS"])

        n = Node(id=lid,
                 name=obj["LABEL"],
                 state=self.LINODE_STATES[obj["STATUS"]],
                 public_ip=public_ip,
                 private_ip=private_ip,
                 driver=self.connection.driver)
        n.extra = copy(obj)
        return n
Example #2
0
 def _to_node(self, order):
     n = Node(id=order['order_oid'],
             name=order['domain_name'],
             state=NodeState.RUNNING,
             public_ip=[order['allocated_ips']['primary_ip']]+order['allocated_ips']['secondary_ips'],
             private_ip=None,
             driver=self.connection.driver)
     n.slug = order['slug']
     return n
Example #3
0
    def test_destroy_node(self):
        node = Node(id=1, name=None, state=None, public_ip=None, private_ip=None,
                    driver=self.driver)

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

        ret = self.driver.destroy_node(node)
        self.assertTrue(ret is True)
Example #4
0
 def _to_node(self, order):
     n = Node(id=order['order_oid'],
              name=order['domain_name'],
              state=NodeState.RUNNING,
              public_ip=[order['allocated_ips']['primary_ip']] +
              order['allocated_ips']['secondary_ips'],
              private_ip=None,
              driver=self.connection.driver)
     n.slug = order['slug']
     return n
Example #5
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.message, 'Permission denied')
Example #6
0
    def create_node(self, **kwargs):
        raise NotImplementedError, \
            'create_node not finished for voxel yet'
        size = kwargs["size"]
        cores = size.ram / RAM_PER_CPU
        params = {
            'method': 'voxel.voxcloud.create',
            'hostname': kwargs["name"],
            'disk_size': int(kwargs["disk"]) / 1024,
            'processing_cores': cores,
            'facility': kwargs["location"].id,
            'image_id': kwargs["image"],
            'backend_ip': kwargs.get("privateip", None),
            'frontend_ip': kwargs.get("publicip", None),
            'admin_password': kwargs.get("rootpass", None),
            'console_password': kwargs.get("consolepass", None),
            'ssh_username': kwargs.get("sshuser", None),
            'ssh_password': kwargs.get("sshpass", None),
            'voxel_access': kwargs.get("voxel_access", None)
        }

        object = self.connection.request('/', params=params).object

        if self._getstatus(object):
            return Node(
                id=object.findtext("device/id"),
                name=kwargs["name"],
                state=NODE_STATE_MAP[object.findtext("devices/status")],
                public_ip=kwargs.get("publicip", None),
                private_ip=kwargs.get("privateip", None),
                driver=self.connection.driver)
        else:
            return None
Example #7
0
    def _to_node(self, name, elm):
        state = self.NODE_STATE_MAP[elm.get('status')]
        public_ips = []
        private_ips = []

        # Following code to find private IPs works for Terremark
        connections = elm.findall(
            '{http://schemas.dmtf.org/ovf/envelope/1}NetworkConnectionSection/{http://www.vmware.com/vcloud/v0.8}NetworkConnection'
        )
        for connection in connections:
            ips = [
                ip.text
                for ip in connection.findall(fixxpath(elm, "IpAddress"))
            ]
            if connection.get('Network') == 'Internal':
                private_ips.extend(ips)
            else:
                public_ips.extend(ips)

        node = Node(id=elm.get('href'),
                    name=name,
                    state=state,
                    public_ip=public_ips,
                    private_ip=private_ips,
                    driver=self.connection.driver)

        return node
Example #8
0
    def create_node(self, **kwargs):
        """Create a new Dreamhost node

        See L{NodeDriver.create_node} for more keyword args.

        @keyword    ex_movedata: Copy all your existing users to this new PS
        @type       ex_movedata: C{str}
        """
        size = kwargs['size'].ram
        params = {
            'cmd' : 'dreamhost_ps-add_ps',
            'movedata' : kwargs.get('movedata', 'no'),
            'type' : kwargs['image'].name,
            'size' : size
        }
        data = self.connection.request('/', params).object
        return Node(
            id = data['added_web'],
            name = data['added_web'],
            state = NodeState.PENDING,
            public_ip = [],
            private_ip = [],
            driver = self.connection.driver,
            extra = {
                'type' : kwargs['image'].name
            }
        )
Example #9
0
    def _to_node(self, el):
        def get_ips(el):
            return [ip.get('addr') for ip in el]

        def get_meta_dict(el):
            d = {}
            for meta in el:
                d[meta.get('key')] = meta.text
            return d

        public_ip = get_ips(self._findall(el, 'addresses/public/ip'))
        private_ip = get_ips(self._findall(el, 'addresses/private/ip'))
        metadata = get_meta_dict(self._findall(el, 'metadata/meta'))

        n = Node(id=el.get('id'),
                 name=el.get('name'),
                 state=self.NODE_STATE_MAP.get(el.get('status'),
                                               NodeState.UNKNOWN),
                 public_ip=public_ip,
                 private_ip=private_ip,
                 driver=self.connection.driver,
                 extra={
                     'password': el.get('adminPass'),
                     'hostId': el.get('hostId'),
                     'imageId': el.get('imageId'),
                     'flavorId': el.get('flavorId'),
                     'metadata': metadata,
                 })
        return n
Example #10
0
    def _to_nodes(self, object):
        nodes = []
        for element in object.findall('devices/device'):
            if element.findtext("type") == "Virtual Server":
                try:
                    state = self.NODE_STATE_MAP[element.attrib['status']]
                except KeyError:
                    state = NodeState.UNKNOWN

                public_ip = private_ip = None
                ipassignments = element.findall("ipassignments/ipassignment")
                for ip in ipassignments:
                    if ip.attrib["type"] == "frontend":
                        public_ip = ip.text
                    elif ip.attrib["type"] == "backend":
                        private_ip = ip.text

                nodes.append(
                    Node(id=element.attrib['id'],
                         name=element.attrib['label'],
                         state=state,
                         public_ip=public_ip,
                         private_ip=private_ip,
                         driver=self.connection.driver))
        return nodes
Example #11
0
    def _to_node(self, obj):
        # Convert a returned Linode instance into a Node instance.
        lid = obj["LINODEID"]
        
        # Get the IP addresses for a Linode
        params = { "api_action": "linode.ip.list", "LinodeID": lid }        
        req = self.connection.request(LINODE_ROOT, params=params)
        if not req.success() or len(req.object) == 0:
            return None
        
        # TODO: Multiple IP support.  How do we handle that case?
        public_ip = private_ip = None
        for ip in req.object:
            if ip["ISPUBLIC"]: public_ip = ip["IPADDRESS"]
            else: private_ip = ip["IPADDRESS"]

        n = Node(id=lid, name=obj["LABEL"],
            state=self.LINODE_STATES[obj["STATUS"]], public_ip=public_ip,
            private_ip=private_ip, driver=self.connection.driver)
        n.extra = copy(obj)
        return n
Example #12
0
    def _to_node(self, el):
        def get_ips(el):
            return [ip.get('addr') for ip in el]

        public_ip = get_ips(self._findall(el, 'addresses/public/ip'))
        private_ip = get_ips(self._findall(el, 'addresses/private/ip'))
        n = Node(id=el.get('id'),
                 name=el.get('name'),
                 state=el.get('status'),
                 public_ip=public_ip,
                 private_ip=private_ip,
                 driver=self.connection.driver)
        return n
Example #13
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_ip=[vm.get('primary_ip_address', None)],
                 private_ip=[],
                 driver=self.connection.driver)
        return n
Example #14
0
    def _to_node(self, element):
        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, 'dnsName'),
                 private_ip=self._findtext(element, 'privateDnsName'),
                 driver=self.connection.driver)
        return n
Example #15
0
    def _to_node(self, host):
        try:
            password = host['softwareComponents'][0]['passwords'][0][
                'password']
        except (IndexError, KeyError):
            password = None

        return Node(id=host['id'],
                    name=host['hostname'],
                    state=NODE_STATE_MAP.get(host['powerState']['keyName'],
                                             NodeState.UNKNOWN),
                    public_ip=[host['primaryIpAddress']],
                    private_ip=[host['primaryBackendIpAddress']],
                    driver=self,
                    extra={'password': password})
Example #16
0
    def _to_node(self, name, elm):
        state = self.NODE_STATE_MAP[elm.get('status')]
        public_ips = [
            ip.text for ip in elm.findall(
                fixxpath(
                    elm,
                    'NetworkConnectionSection/NetworkConnection/IPAddress'))
        ]

        node = Node(id=name,
                    name=name,
                    state=state,
                    public_ip=public_ips,
                    private_ip=None,
                    driver=self.connection.driver)

        return node
Example #17
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_ip = [data['ip']],
         private_ip = [],
         driver = self.connection.driver,
         extra = {
             'current_size' : data['memory_mb'],
             'account_id' : data['account_id'],
             'type' : data['type']
         }
     )
Example #18
0
    def _to_node(self, element):

        attrs = [
            'name', 'image-id', 'progress', 'id', 'bw-out', 'bw-in',
            'flavor-id', 'status', 'ip-address', 'root-password'
        ]

        node_attrs = {}
        for attr in attrs:
            node_attrs[attr] = element.findtext(attr)

        # slicehost does not determine between public and private, so we
        # have to figure it out
        public_ip = element.findtext('ip-address')
        private_ip = None
        for addr in element.findall('addresses/address'):
            ip = addr.text
            try:
                socket.inet_aton(ip)
            except socket.error:
                # not a valid ip
                continue
            if is_private_subnet(ip):
                private_ip = ip
            else:
                public_ip = ip

        try:
            state = self.NODE_STATE_MAP[element.findtext('status')]
        except:
            state = NodeState.UNKNOWN

        # for consistency with other drivers, we put this in two places.
        node_attrs['password'] = node_attrs['root-password']
        extra = {}
        for k in node_attrs.keys():
            ek = k.replace("-", "_")
            extra[ek] = node_attrs[k]
        n = Node(id=element.findtext('id'),
                 name=element.findtext('name'),
                 state=state,
                 public_ip=[public_ip],
                 private_ip=[private_ip],
                 driver=self.connection.driver,
                 extra=extra)
        return n
Example #19
0
File: ec2.py Project: eskp/dewpoint
    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, 'dnsName')],
                 private_ip=[self._findtext(element, 'privateDnsName')],
                 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"),
                     'groups':
                     groups
                 })
        return n
Example #20
0
File: ecp.py Project: eskp/dewpoint
    def create_node(self, **kwargs):
        """
        Creates a virtual machine.

        Parameters: name (string), image (NodeImage), size (NodeSize)
        """

        #Find out what network to put the VM on.
        res = self.connection.request(
            '/rest/hosting/network/list').parse_body()

        #Use the first / default network because there is no way to specific
        #which one
        network = res['networks'][0]['uuid']

        #Prepare to make the VM
        data = {
            'name': str(kwargs['name']),
            'package': str(kwargs['image'].id),
            'hardware': str(kwargs['size'].id),
            'network_uuid': str(network),
            'disk': ''
        }

        #Black magic to make the POST requests work
        d = self.connection._encode_multipart_formdata(data)
        response = self.connection.request('/rest/hosting/vm/',
                                           method='PUT',
                                           headers=d[0],
                                           data=d[1]).parse_body()

        #Create a node object and return it.
        n = Node(
            id=response['machine_id'],
            name=data['name'],
            state=NodeState.PENDING,
            public_ip=[],
            private_ip=[],
            driver=self,
        )

        return n
Example #21
0
File: ecp.py Project: eskp/dewpoint
    def _to_node(self, vm):
        """
        Turns a (json) dictionary into a Node object.
        This returns only running VMs.
        """

        #Check state
        if not vm['state'] == "running":
            return None

        #IPs
        iplist = [
            interface['ip'] for interface in vm['interfaces']
            if interface['ip'] != '127.0.0.1'
        ]

        public_ips = []
        private_ips = []
        for ip in iplist:
            try:
                socket.inet_aton(ip)
            except socket.error:
                # not a valid ip
                continue
            if is_private_subnet(ip):
                private_ips.append(ip)
            else:
                public_ips.append(ip)

        #Create the node object
        n = Node(
            id=vm['uuid'],
            name=vm['name'],
            state=NodeState.RUNNING,
            public_ip=public_ips,
            private_ip=private_ips,
            driver=self,
        )

        return n
Example #22
0
    def _to_node(self, element):

        attrs = [ 'name', 'image-id', 'progress', 'id', 'bw-out', 'bw-in', 
                  'flavor-id', 'status', 'ip-address' ]

        node_attrs = {}
        for attr in attrs:
            node_attrs[attr] = element.findtext(attr)

        # slicehost does not determine between public and private, so we 
        # have to figure it out
        public_ip = element.findtext('ip-address')
        private_ip = None
        for addr in element.findall('addresses/address'):
            ip = addr.text
            try:
                socket.inet_aton(ip)
            except socket.error:
                # not a valid ip
                continue
            if self._is_private_subnet(ip):
                private_ip = ip
            else:
                public_ip = ip
                
        try:
            state = self.NODE_STATE_MAP[element.findtext('status')]
        except:
            state = NodeState.UNKNOWN

        n = Node(id=element.findtext('id'),
                 name=element.findtext('name'),
                 state=state,
                 public_ip=public_ip,
                 private_ip=private_ip,
                 driver=self.connection.driver)
        return n
Example #23
0
 def test_reboot_node(self):
     node = Node(id=72258, name=None, state=None, public_ip=None, private_ip=None,
                 driver=self.driver)
     ret = node.reboot()
     self.assertTrue(ret is True)