コード例 #1
0
    def create_tag(self, name, description=None, servers=[]):
        """
        Create a new Tag. Only name is mandatory.

        Returns the created Tag object.
        """
        servers = [str(server) for server in servers]
        body = {'tag': Tag(name, description, servers).to_dict()}
        res = self.request('POST', '/tag', body)

        return Tag(cloud_manager=self, **res['tag'])
コード例 #2
0
 def create_tag(self, name, description=None, servers=[]):
     tag = {"name": name}
     if description:
         tag["description"] = description
     if servers:
         tag["servers"] = servers
     return Tag(cloud_manager=self, **tag)
コード例 #3
0
    def _modify_tag(self, name, description, servers, new_name):
        """
        PUT /tag/name. Returns a dict that can be used to create a Tag object.

        Private method used by the Tag class and TagManager.modify_tag.
        """
        body = Tag._prepare_tag_body(new_name, description, servers)
        res = self.request('PUT', '/tag/' + name, body)
        return res['tag']
コード例 #4
0
    def _modify_tag(self, name, description, servers, new_name):
        """
        PUT /tag/name. Returns a dict that can be used to create a Tag object.

        Private method used by the Tag class and TagManager.modify_tag.
        """
        body = {'tag': Tag(new_name, description, servers).to_dict()}
        res = self.request('PUT', '/tag/' + name, body)
        return res['tag']
コード例 #5
0
    def create_tag(self, name, description=None, servers=[]):
        """
        Create a new Tag. Only name is mandatory.

        Returns the created Tag object.
        """
        servers = [str(server) for server in servers]
        body = Tag._prepare_tag_body(name, description, servers)
        res = self.request('POST', '/tag', body)

        return Tag(cloud_manager=self, **res['tag'])
コード例 #6
0
    def test_assign_tags_to_server(self, manager):
        data = Mock.mock_get('server/00798b85-efdc-41ca-8021-f6ef457b8531')
        server = manager.get_server('00798b85-efdc-41ca-8021-f6ef457b8531')

        responses.add(
            responses.POST,
            Mock.base_url +
            '/server/00798b85-efdc-41ca-8021-f6ef457b8531/tag/tag1,tag2',
            body=json.dumps({'foo': 'bar'}),
            content_type='application/json',
            status=200)
        server.add_tags(['tag1', Tag('tag2')])

        for tag in ['web1', 'tag1', 'tag2']:
            assert tag in server.tags
コード例 #7
0
 def modify_tag(self, name, description=None, servers=None, new_name=None):
     """
     PUT /tag/name. Returns a new Tag object based on the API response.
     """
     res = self._modify_tag(name, description, servers, new_name)
     return Tag(cloud_manager=self, **res['tag'])
コード例 #8
0
 def get_tag(self, name):
     """Return the tag as Tag object."""
     res = self.get_request('/tag/' + name)
     return Tag(cloud_manager=self, **res['tag'])
コード例 #9
0
 def get_tags(self):
     """List all tags as Tag objects."""
     res = self.get_request('/tag')
     return [Tag(cloud_manager=self, **tag) for tag in res['tags']['tag']]
コード例 #10
0
    FirewallRule(
        position='1',
        direction='in',
        family='IPv4',
        protocol='tcp',
        source_address_start='192.168.1.1',
        source_address_end='192.168.1.255',
        destination_port_start='22',
        destination_port_end='22',
        action='accept'
    ),
    FirewallRule(
        position='2',
        direction='in',
        family='IPv4',
        protocol='tcp',
        source_address_start='192.168.1.1',
        source_address_end='192.168.1.255',
        destination_port_start='21',
        destination_port_end='21',
        action='accept'
    )
]


TAGS = [
    Tag('testlb'),
    Tag('testdb'),
    Tag('testweb')
]
コード例 #11
0
        password_delivery='none',
        storage_devices=[Storage(os='Debian 10.0', size=30)],
        login_user=login_user_block(
            'testuser',
            ['ssh-rsa AAAAB3NzaC1yc2EAA[...]ptshi44x [email protected]'], True),
    )
}

FIREWALL_RULES = [
    FirewallRule(position='1',
                 direction='in',
                 family='IPv4',
                 protocol='tcp',
                 source_address_start='192.168.1.1',
                 source_address_end='192.168.1.255',
                 destination_port_start='22',
                 destination_port_end='22',
                 action='accept'),
    FirewallRule(position='2',
                 direction='in',
                 family='IPv4',
                 protocol='tcp',
                 source_address_start='192.168.1.1',
                 source_address_end='192.168.1.255',
                 destination_port_start='21',
                 destination_port_end='21',
                 action='accept')
]

TAGS = [Tag('testlb'), Tag('testdb'), Tag('testweb')]
コード例 #12
0
 def get_tags(self):
     data = self.read_json_data("tag")
     return [Tag(cloud_manager=self, **tag) for tag in data["tags"]["tag"]]