~ubuntu-branches/ubuntu/saucy/juju-core/saucy-proposed

« back to all changes in this revision

Viewing changes to src/launchpad.net/goose/nova/nova.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-07-11 17:18:27 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20130711171827-vjqkg40r0dlf7ys2
Tags: 1.11.2-0ubuntu1
* New upstream release.
* Make juju-core the default juju (LP: #1190634):
  - d/control: Add virtual package juju -> juju-core.
  - d/juju-core.postinst.in: Bump priority of alternatives over that of
    python juju packages.
* Enable for all architectures (LP: #1172505):
  - d/control: Version BD on golang-go to >= 2:1.1.1 to ensure CGO
    support for non-x86 archs, make juju-core Arch: any.
  - d/README.source: Dropped - no longer required.
* d/watch: Updated for new upstream tarball naming.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
        "net/http"
12
12
        "net/url"
13
13
        "reflect"
14
 
        "strconv"
15
14
)
16
15
 
17
16
// API URL parts.
327
326
        FromPort      *int              `json:"from_port"`   // Can be nil
328
327
        IPProtocol    *string           `json:"ip_protocol"` // Can be nil
329
328
        ToPort        *int              `json:"to_port"`     // Can be nil
330
 
        ParentGroupId int               `json:"parent_group_id"`
 
329
        ParentGroupId string            `json:"-"`
331
330
        IPRange       map[string]string `json:"ip_range"` // Can be empty
332
 
        Id            int
 
331
        Id            string            `json:"-"`
333
332
        Group         SecurityGroupRef
334
333
}
335
334
 
337
336
type SecurityGroup struct {
338
337
        Rules       []SecurityGroupRule
339
338
        TenantId    string `json:"tenant_id"`
340
 
        Id          int
 
339
        Id          string `json:"-"`
341
340
        Name        string
342
341
        Description string
343
342
}
389
388
                        if err == nil {
390
389
                                result := make([]SecurityGroup, len(serverDetails.Groups))
391
390
                                for i, e := range serverDetails.Groups {
392
 
                                        id, err := strconv.Atoi(e.Id)
393
 
                                        if err != nil {
394
 
                                                return nil, errors.Newf(err, "failed to parse security group id %s", e.Id)
395
 
                                        }
396
391
                                        result[i] = SecurityGroup{
397
 
                                                Id:   id,
 
392
                                                Id:   e.Id,
398
393
                                                Name: e.Name,
399
394
                                        }
400
395
                                }
429
424
}
430
425
 
431
426
// DeleteSecurityGroup deletes the specified security group.
432
 
func (c *Client) DeleteSecurityGroup(groupId int) error {
433
 
        url := fmt.Sprintf("%s/%d", apiSecurityGroups, groupId)
 
427
func (c *Client) DeleteSecurityGroup(groupId string) error {
 
428
        url := fmt.Sprintf("%s/%s", apiSecurityGroups, groupId)
434
429
        requestData := goosehttp.RequestData{ExpectedStatus: []int{http.StatusAccepted}}
435
430
        err := c.client.SendRequest(client.DELETE, "compute", url, &requestData)
436
431
        if err != nil {
473
468
        // Cidr cannot be specified with GroupId. Ingress rules need a valid
474
469
        // subnet mast in CIDR format here, while if GroupID is specifed, it
475
470
        // means you're adding a group rule, specifying source group ID, which
476
 
        // must exists already and can be equal to ParentGroupId).
 
471
        // must exist already and can be equal to ParentGroupId).
477
472
        // need Cidr, while
478
 
        Cidr    string `json:"cidr"`
479
 
        GroupId *int   `json:"group_id"`
 
473
        Cidr    string  `json:"cidr"`
 
474
        GroupId *string `json:"-"`
480
475
 
481
476
        // ParentGroupId is always required and specifies the group to which
482
477
        // the rule is added.
483
 
        ParentGroupId int `json:"parent_group_id"`
 
478
        ParentGroupId string `json:"-"`
484
479
}
485
480
 
486
481
// CreateSecurityGroupRule creates a security group rule.
505
500
}
506
501
 
507
502
// DeleteSecurityGroupRule deletes the specified security group rule.
508
 
func (c *Client) DeleteSecurityGroupRule(ruleId int) error {
509
 
        url := fmt.Sprintf("%s/%d", apiSecurityGroupRules, ruleId)
 
503
func (c *Client) DeleteSecurityGroupRule(ruleId string) error {
 
504
        url := fmt.Sprintf("%s/%s", apiSecurityGroupRules, ruleId)
510
505
        requestData := goosehttp.RequestData{ExpectedStatus: []int{http.StatusAccepted}}
511
506
        err := c.client.SendRequest(client.DELETE, "compute", url, &requestData)
512
507
        if err != nil {
556
551
type FloatingIP struct {
557
552
        // FixedIP holds the private IP address of the machine (when assigned)
558
553
        FixedIP *string `json:"fixed_ip"`
559
 
        Id      int     `json:"id"`
 
554
        Id      string  `json:"-"`
560
555
        // InstanceId holds the instance id of the machine, if this FIP is assigned to one
561
556
        InstanceId *string `json:"-"`
562
557
        IP         string  `json:"ip"`
578
573
}
579
574
 
580
575
// GetFloatingIP lists details of the floating IP address associated with specified id.
581
 
func (c *Client) GetFloatingIP(ipId int) (*FloatingIP, error) {
 
576
func (c *Client) GetFloatingIP(ipId string) (*FloatingIP, error) {
582
577
        var resp struct {
583
578
                FloatingIP FloatingIP `json:"floating_ip"`
584
579
        }
585
580
 
586
 
        url := fmt.Sprintf("%s/%d", apiFloatingIPs, ipId)
 
581
        url := fmt.Sprintf("%s/%s", apiFloatingIPs, ipId)
587
582
        requestData := goosehttp.RequestData{RespValue: &resp}
588
583
        err := c.client.SendRequest(client.GET, "compute", url, &requestData)
589
584
        if err != nil {
590
 
                return nil, errors.Newf(err, "failed to get floating ip %d details", ipId)
 
585
                return nil, errors.Newf(err, "failed to get floating ip %s details", ipId)
591
586
        }
592
587
        return &resp.FloatingIP, nil
593
588
}
607
602
}
608
603
 
609
604
// DeleteFloatingIP deallocates the floating IP address associated with the specified id.
610
 
func (c *Client) DeleteFloatingIP(ipId int) error {
611
 
        url := fmt.Sprintf("%s/%d", apiFloatingIPs, ipId)
 
605
func (c *Client) DeleteFloatingIP(ipId string) error {
 
606
        url := fmt.Sprintf("%s/%s", apiFloatingIPs, ipId)
612
607
        requestData := goosehttp.RequestData{ExpectedStatus: []int{http.StatusAccepted}}
613
608
        err := c.client.SendRequest(client.DELETE, "compute", url, &requestData)
614
609
        if err != nil {
615
 
                err = errors.Newf(err, "failed to delete floating ip %d details", ipId)
 
610
                err = errors.Newf(err, "failed to delete floating ip %s details", ipId)
616
611
        }
617
612
        return err
618
613
}