Jump to content
  • Announcements

    • admin

      PBS Forum Has Closed   06/12/17

      The PBS Works Support Forum is no longer active.  For PBS community-oriented questions and support, please join the discussion at http://community.pbspro.org.  Any new security advisories related to commercially-licensed products will be posted in the PBS User Area (https://secure.altair.com/UserArea/). 
Sign in to follow this  
vuhiep

how to attach instance to different networks

Recommended Posts

Hi, I have many network are created and when I launch a instance how can I attach that instance to exactly network what I want. please teach me how to do that using libcloud api, thanks. This is my code:

        N = len(names)
        for i in xrange(N):
            #Find exists SSH Key
            key_pair = None
            for keypair in self.conn.list_key_pairs():
                if keypair.name == 'PubKey':
                    key_pair = keypair
                    break
            '''
            if key_pair == None:
                key_pair = self.conn.create_key_pair(name = 'Key-' + names[i])
            '''
            #Optimize : Multi-thread ?
            node = self.conn.create_node(name = utils.VM_NAME % (course_id, names[i], idx), 
                                         image = images[i], 
                                         size = sizes[i], 
                                         ex_keyname = key_pair.name)
            self.nodes.append(node)  
        #Wait until all nodes are considered running
        w_nodes = self.conn.wait_until_running(nodes = self.nodes, wait_period = 10, timeout = 600)
        self.nodes = w_nodes

Blockquote

        ram, disk = info_json_clients[idx]['ram'], info_json_clients[idx]['disk']
        #********** list network name *******#
        netnamelist = [i['netname'] for i in info_json_clients[idx]['networks']]
        #***************** END **************#
        s_flavor = None
        s_image = None
        for flavor in list_flavors:
            if (flavor.ram >= ram and flavor.disk >= disk and flavor.disk >= 10 and (s_flavor == None or s_flavor.disk > flavor.disk or (s_flavor.disk == flavor.disk and s_flavor.ram < flavor.ram))):
                s_flavor = flavor
        sizes = [s_flavor for _ in xrange(num)] 
        for img in list_images:
            if img.name == 'ubuntu_agent':
                s_image = img
                break
        images = [s_image for _ in xrange(num)]
        print s_flavor, s_image
        nodes = cloud.CreateNodes(course_id = course.id, names = students, images = images, sizes = sizes, idx = idx)
        deploy_nodes.append(nodes)

when i run it return error:

server_params['flavorRef'] = kwargs.get('size').id
AttributeError: 'NoneType' object has no attribute 'id'

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×