Ejemplo n.º 1
0
    def start(self, node: models.Node):
        b = Benchmarks(
            ram_size=1024 * 1024 * 500,  # 500MB
            storage_size=1024 * 1024 * 1024 * 10,  # 10GB
            cpu_cores=1,
            cpu_sysbench_multi=500,
            cpu_sysbench_single=500,
            net_download=1024 * 1024 * settings.NODE_DOWNLOAD,
            net_upload=1024 * 1024 * settings.NODE_UPLOAD,
        )
        n = NetworkParams(incoming=True, outbound=True, overlay=True)
        bid = BidParams(
            duration=0,
            price='0.01 USD/h',
            counterparty=settings.COUNTERPARTY,
            identity=sonm.consts.IDENTITY_ANONYMOUS,
            tag='sonm-cdn-node',
            benchmarks=b,
            network=n,
        )

        bid_id = self.sonm.order.create(bid=bid)['id']

        node.external_id = bid_id
        node.throughput = settings.NODE_UPLOAD
        node.save()

        models.SonmBid.objects.create(node=node)
Ejemplo n.º 2
0
    def check_node(self, node: models.Node):
        node_address = node.get_address()
        try:
            response = requests.get(f'http://{node_address}/bytes_sent')
            if response.status_code < 300:
                node.prev_sent_bytes = node.last_sent_bytes
                node.prev_sent_bytes_dt = node.last_sent_bytes_dt
                node.last_sent_bytes = int(response.content)
                node.last_sent_bytes_dt = now()
                node.save()

                if self.verbosity:
                    print(f'Node {node.name}: {node.get_load()} Mb/sec')

            else:
                print(f'Node check load error! '
                      f'NAME: {node.id} '
                      f'ADDRESS: {node_address}.'
                      f'CODE: {response.status_code}'
                      f'RESPONSE: {response.content}\n')

        except Exception as e:
            print(f'Node check load error! '
                  f'NAME: {node.id} '
                  f'ADDRESS: {node_address}.'
                  f'EXCEPTION: \n{e}.\n')
Ejemplo n.º 3
0
    def destroy(self, node: Node):
        node.stopped = now()
        node.save()

        for droplet in self.get_droplets():
            if str(droplet.id) == node.external_id:
                droplet.destroy()
                return

        raise Exception('Not found node with external ID "%s"' % node.external_id)
Ejemplo n.º 4
0
Archivo: node.py Proyecto: vpramo/xos-1
    def create(self):
        xos_args = self.get_xos_args()

        if not xos_args.get("site_deployment", None):
            raise Exception("Deployment is a required field of Node")

        node = Node(**xos_args)
        node.caller = self.user
        node.save()

        self.postprocess(node)

        self.info("Created Node '%s' on Site '%s' Deployment '%s'" % (str(node), str(node.site_deployment.site), str(node.site_deployment.deployment)))
Ejemplo n.º 5
0
    def create(self):
        xos_args = self.get_xos_args()

        if not xos_args.get("site", None):
            raise Exception("Site is a required field of Node")
        if not xos_args.get("site_deployment", None):
            raise Exception("Deployment is a required field of Node")

        node = Node(**xos_args)
        node.caller = self.user
        node.save()

        self.postprocess(node)

        self.info("Created Node '%s' on Site '%s' Deployment '%s'" % (str(node), str(node.site), str(node.site_deployment.deployment)))
Ejemplo n.º 6
0
    def start(self, node: Node):
        size_slug = 's-1vcpu-1gb'
        ssh_keys = self.get_ssh_keys()
        do_region = random.choice(REGIONS_MAP[node.region])

        droplet = digitalocean.Droplet(token=settings.DO_TOKEN,
                                       name=node.name,
                                       region=do_region,
                                       image=self.get_image(),
                                       size_slug=size_slug,
                                       ssh_keys=ssh_keys,
                                       tags=[TAG_NAME],
                                       backups=False)
        droplet.create()

        node.external_id = droplet.id
        node.throughput = 100     # let's consider that maximum throughput 100 Mb/sec
        node.save()